Skip to content

Commit

Permalink
WIP: 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 322a530
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 71 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
40 changes: 19 additions & 21 deletions cmake/Findanari.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ 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
helium
anari_test_scenes
anari_headers
# dynamic #
anari
anari_frontend
anari_backend
# static #
anari_static
anari_frontend_static
anari_backend_static
)

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()
6 changes: 5 additions & 1 deletion examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ if (IN_SDK_SOURCE_TREE)
# 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_frontend
anari_library_helide
)
endif()

if (BUILD_TESTING)
Expand Down
116 changes: 81 additions & 35 deletions src/anari/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,113 @@ 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)
project_compile_definitions(PRIVATE -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)
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}
)

install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
macro(add_anari_backend_library_target LIB_TYPE)
project_add_library(${LIB_TYPE} DeviceImpl.cpp LibraryImpl.cpp)
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_link_libraries(PUBLIC Threads::Threads anari_headers)
set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${ANARI_SDK_VERSION}
SOVERSION ${ANARI_SDK_VERSION_MAJOR}
)
endmacro()

## Create shared + static frontend library targets ##
## 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}>
)
project_compile_definitions(INTERFACE $<BUILD_INTERFACE:-Danari_EXPORTS>)

add_anari_frontend_library_target(SHARED)
## Create main shared + static library targets ##

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

project(anari_backend)
add_anari_backend_library_target(SHARED)
project(anari_backend_static)
add_anari_backend_library_target(STATIC)
project_compile_definitions(PUBLIC -DANARI_STATIC_DEFINE)

## Create aggregate targets for backwards compatibility

project(anari)
project_add_library(INTERFACE)
project_link_libraries(INTERFACE anari_frontend anari_backend)

project(anari_static)
project_add_library(INTERFACE)
project_link_libraries(INTERFACE anari_frontend_static anari_backend_static)

## Create version header ##

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

## Install headers ##
## Install ##

set(ANARI_TARGETS
anari_headers
# dynamic #
anari
anari_frontend
anari_backend
# static #
anari_static
anari_frontend_static
anari_backend_static
)

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@
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
8 changes: 7 additions & 1 deletion src/helide/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)

project_link_libraries(PUBLIC anari::helium PRIVATE local_embree)
project_link_libraries(
PUBLIC
anari::helium
anari::anari_backend
PRIVATE
local_embree
)

if(WIN32)
project_compile_definitions(PRIVATE _USE_MATH_DEFINES)
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)

## Install library + targets ##

Expand Down

0 comments on commit 322a530

Please sign in to comment.