Skip to content

Commit

Permalink
build frontend library as both shared and static always
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffamstutz committed Oct 18, 2024
1 parent 7d291cc commit e1c2e54
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 61 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

## Establish project

project(anari VERSION 0.10.1 LANGUAGES C CXX)
set(ANARI_SDK_VERSION_MAJOR 0)
set(ANARI_SDK_VERSION_MINOR 10)
set(ANARI_SDK_VERSION_PATCH 1)
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)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
Expand Down
6 changes: 6 additions & 0 deletions cmake/Findanari.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ set_target_properties(anari::anari PROPERTIES
"anari"
)

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
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ add_executable(anariTutorialInitFromEnv anariTutorialInitFromEnv.c)
target_link_libraries(anariTutorialInitFromEnv PRIVATE anari::anari)

add_executable(anariInfo anariInfo.cpp)
target_link_libraries(anariInfo PRIVATE anari::anari)
target_link_libraries(anariInfo PRIVATE anari::anari_static)

if (IN_SDK_SOURCE_TREE)
install(TARGETS anariInfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
125 changes: 66 additions & 59 deletions src/anari/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,75 @@
option(ANARI_FRONTEND_CATCH_EXCEPTIONS "Have libanari catch all exceptions" ON)
mark_as_advanced(ANARI_FRONTEND_CATCH_EXCEPTIONS)

project_add_library(
anari_cpp_linalg_defs.cpp
anari_cpp_std_defs.cpp
API.cpp
DeviceImpl.cpp
LibraryImpl.cpp
test_c_header_compilation.c
)

if (NOT BUILD_SHARED_LIBS)
project_compile_definitions(PUBLIC -DANARI_STATIC_DEFINE)
endif()

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 ${CMAKE_DL_LIBS})

## Create version header
macro(add_anari_frontend_library_target LIB_TYPE)
project_add_library(${LIB_TYPE}
anari_cpp_linalg_defs.cpp
anari_cpp_std_defs.cpp
API.cpp
DeviceImpl.cpp
LibraryImpl.cpp
test_c_header_compilation.c
)

if (NOT BUILD_SHARED_LIBS)
project_compile_definitions(PUBLIC -DANARI_STATIC_DEFINE)
endif()

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 ${CMAKE_DL_LIBS})

set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${ANARI_SDK_VERSION}
SOVERSION ${ANARI_SDK_VERSION_MAJOR}
)

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}
)
endmacro()

## Create shared + static frontend library targets ##

add_anari_frontend_library_target(SHARED)

project(anari_static VERSION ${ANARI_SDK_VERSION} LANGUAGES C CXX)
add_anari_frontend_library_target(STATIC)

## Create version header ##

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

## Install library + targets

set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

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 anari
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

## Install headers
## Install headers ##

install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/anari
Expand Down

0 comments on commit e1c2e54

Please sign in to comment.