Skip to content

Commit

Permalink
split out frontend library targets into individual components
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffamstutz committed Nov 25, 2024
1 parent 72f5edd commit c227710
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 78 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set(ANARI_SDK_VERSION
${ANARI_SDK_VERSION_MAJOR}.${ANARI_SDK_VERSION_MINOR}.${ANARI_SDK_VERSION_PATCH}
)

project(anari VERSION ${ANARI_SDK_VERSION} LANGUAGES C CXX)
project(anari-sdk VERSION ${ANARI_SDK_VERSION} LANGUAGES C CXX)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
Expand Down Expand Up @@ -141,7 +141,7 @@ include(cmake/mark_cache_variables_as_advanced.cmake)
## Configure CMake find_package() config files ##

set(ANARI_CMAKE_INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
${CMAKE_INSTALL_LIBDIR}/cmake/anari-${PROJECT_VERSION}
)

install(EXPORT anari_Exports
Expand All @@ -152,21 +152,21 @@ install(EXPORT anari_Exports
include(CMakePackageConfigHelpers)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_SOURCE_DIR}/cmake/anariConfig.cmake.in"
"${PROJECT_BINARY_DIR}/anariConfig.cmake"
INSTALL_DESTINATION
${ANARI_CMAKE_INSTALL_DESTINATION}
)

write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
"anariConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/anariConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/anariConfigVersion.cmake
DESTINATION
${ANARI_CMAKE_INSTALL_DESTINATION}
)
Expand Down
35 changes: 14 additions & 21 deletions cmake/Findanari.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,19 @@ if (TARGET anari::anari)
return()
endif()

add_library(anari::anari INTERFACE IMPORTED)
set_target_properties(anari::anari PROPERTIES
INTERFACE_LINK_LIBRARIES
"anari"
set(ANARI_LOCAL_TARGETS
anari_headers
anari_backend
anari
anari_static
anari_test_scenes
helium
)

add_library(anari::anari_static INTERFACE IMPORTED)
set_target_properties(anari::anari_static PROPERTIES
INTERFACE_LINK_LIBRARIES
"anari_static"
)

add_library(anari::anari_test_scenes INTERFACE IMPORTED)
set_target_properties(anari::anari_test_scenes PROPERTIES
INTERFACE_LINK_LIBRARIES
"anari_test_scenes"
)

add_library(anari::helium INTERFACE IMPORTED)
set_target_properties(anari::helium PROPERTIES
INTERFACE_LINK_LIBRARIES
"helium"
)
foreach(TARGET ${ANARI_LOCAL_TARGETS})
add_library(anari::${TARGET} INTERFACE IMPORTED)
set_target_properties(anari::${TARGET} PROPERTIES
INTERFACE_LINK_LIBRARIES
"${TARGET}"
)
endforeach()
2 changes: 1 addition & 1 deletion cmake/anariConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (@VIEWER_ENABLE_KTX@)
find_dependency(Ktx)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@_Exports.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/anari_Exports.cmake)

if (NOT TARGET anari::anari)
message(FATAL_ERROR "CMAKE_PREFIX_PATH or anari_DIR are pointing to an \
Expand Down
12 changes: 8 additions & 4 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ if (IN_SDK_SOURCE_TREE)
install(TARGETS anariInfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

if (TARGET anari_library_helide)
# This app links to the include 'helide' device library directly to use its
# direct device creation function. Vendors can choose to ship a header with
# such a direct function in it.
add_executable(anariTutorialDirectLink anariTutorialDirectLink.c)
target_link_libraries(anariTutorialDirectLink PRIVATE anari_library_helide)
target_link_libraries(anariTutorialDirectLink
PRIVATE
anari_static
# This app links to the include 'helide' device library directly to use
# its direct device creation function. Vendors can choose to ship a header
# with such a direct function in it.
anari_library_helide
)
endif()

if (BUILD_TESTING)
Expand Down
88 changes: 51 additions & 37 deletions src/anari/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,81 @@ macro(add_anari_frontend_library_target LIB_TYPE)
anari_cpp_linalg_defs.cpp
anari_cpp_std_defs.cpp
API.cpp
DeviceImpl.cpp
LibraryImpl.cpp
test_c_header_compilation.c
)

if (WIN32)
project_compile_definitions(PUBLIC -D_USE_MATH_DEFINES)
endif()

if (ANARI_FRONTEND_CATCH_EXCEPTIONS)
project_compile_definitions(PRIVATE -DANARI_FRONTEND_CATCH_EXCEPTIONS)
endif()

project_include_directories(
PUBLIC
$<BUILD_INTERFACE:${GENERATED_HEADER_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/anari>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

project_link_libraries(PUBLIC Threads::Threads ${CMAKE_DL_LIBS})

project_link_libraries(PUBLIC ${CMAKE_DL_LIBS} anari_headers anari_backend)
set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${ANARI_SDK_VERSION}
SOVERSION ${ANARI_SDK_VERSION_MAJOR}
)
endmacro()

install(TARGETS ${PROJECT_NAME}
EXPORT anari_Exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_SKIP
# on Windows put the dlls into bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# ... and the import lib into the devel package
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
## Create auxiliary targets ##

project(anari_headers)
project_add_library(INTERFACE)
project_include_directories(
INTERFACE
$<BUILD_INTERFACE:${GENERATED_HEADER_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/anari>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if (WIN32)
project_compile_definitions(INTERFACE -D_USE_MATH_DEFINES)
endif()

install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endmacro()
project(anari_backend)
project_add_library(STATIC DeviceImpl.cpp LibraryImpl.cpp)
project_link_libraries(PUBLIC Threads::Threads anari_headers)
project_compile_definitions(PRIVATE -Danari_EXPORTS)

## Create shared + static frontend library targets ##
## Create main shared + static library targets ##

project(anari)
add_anari_frontend_library_target(SHARED)

project(anari_static VERSION ${ANARI_SDK_VERSION} LANGUAGES C CXX)
project(anari_static)
add_anari_frontend_library_target(STATIC)
project_compile_definitions(PUBLIC -DANARI_STATIC_DEFINE)

## Create version header ##

configure_file(anari_sdk_version.h.in include/anari/frontend/anari_sdk_version.h)

## Install headers ##
## Install ##

set(ANARI_TARGETS
anari
anari_static
anari_backend
anari_headers
)

install(
TARGETS ${ANARI_TARGETS}
EXPORT anari_Exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_SKIP
# on Windows put the dlls into bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# ... and the import lib into the devel package
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(
TARGETS ${ANARI_TARGETS}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/anari
Expand Down
6 changes: 3 additions & 3 deletions src/anari/anari_sdk_version.h.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2022-2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0

#define ANARI_SDK_VERSION_MAJOR @anari_VERSION_MAJOR@
#define ANARI_SDK_VERSION_MINOR @anari_VERSION_MINOR@
#define ANARI_SDK_VERSION_PATCH @anari_VERSION_PATCH@
#define ANARI_SDK_VERSION_MAJOR @ANARI_SDK_VERSION_MAJOR@
#define ANARI_SDK_VERSION_MINOR @ANARI_SDK_VERSION_MINOR@
#define ANARI_SDK_VERSION_PATCH @ANARI_SDK_VERSION_PATCH@
2 changes: 1 addition & 1 deletion src/anari/include/anari/backend/DeviceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace anari {

struct ANARI_INTERFACE DeviceImpl
struct DeviceImpl
{
/////////////////////////////////////////////////////////////////////////////
// Main virtual interface to accepting API calls
Expand Down
2 changes: 1 addition & 1 deletion src/anari/include/anari/backend/LibraryImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void *loadANARILibrary(const std::string &libName);
void freeLibrary(void *lib);
void *getSymbolAddress(void *lib, const std::string &symbol);

struct ANARI_INTERFACE LibraryImpl
struct LibraryImpl
{
LibraryImpl(
void *lib, ANARIStatusCallback defaultStatusCB, const void *statusCBPtr);
Expand Down
4 changes: 2 additions & 2 deletions src/anari_test_scenes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/anari/anari_test_scenes>
)
project_link_libraries(PUBLIC helium PUBLIC $<BUILD_INTERFACE:stb_image>)
project_link_libraries(PUBLIC helium PUBLIC $<BUILD_INTERFACE:mikktspace>)
project_link_libraries(PUBLIC helium anari_static PUBLIC $<BUILD_INTERFACE:stb_image>)
project_link_libraries(PUBLIC helium anari_static PUBLIC $<BUILD_INTERFACE:mikktspace>)

if (VIEWER_ENABLE_GLTF)
project_sources(PRIVATE scenes/file/glTF.cpp)
Expand Down
2 changes: 1 addition & 1 deletion src/helium/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/anari/backend>
)

project_link_libraries(PUBLIC anari)
project_link_libraries(PUBLIC anari_headers anari_backend)

## Install library + targets ##

Expand Down

0 comments on commit c227710

Please sign in to comment.