11configure_file (version .h.in version .h )
22
33# Configure main target
4- target_sources ( Spglib_symspg PRIVATE
4+ add_library ( Spglib_src_obj OBJECT
55 arithmetic.c
66 cell.c
77 debug.c
@@ -28,15 +28,39 @@ target_sources(Spglib_symspg PRIVATE
2828 )
2929set_target_properties (Spglib_symspg PROPERTIES
3030 PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR} /spglib.h )
31- target_include_directories (Spglib_symspg PUBLIC
31+ # TODO: Should move spglib.h to a separate folder so other headers are not included in ExternalProject setups
32+ target_include_directories (Spglib_symspg INTERFACE
3233 "$<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} >"
33- "$<BUILD_INTERFACE :${CMAKE_CURRENT_BINARY_DIR} >"
3434 "$<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >" )
35+ target_sources (Spglib_symspg PRIVATE $<TARGET_OBJECTS :Spglib_src_obj >)
36+ # Note: Not using the following to avoid exporting Spglib_src_obj
37+ #target_link_libraries(Spglib_symspg PRIVATE Spglib_src_obj)
38+ target_include_directories (Spglib_src_obj PRIVATE
39+ "$<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} >"
40+ "$<BUILD_INTERFACE :${CMAKE_CURRENT_BINARY_DIR} >" )
3541
3642# Link to third-party libraries
3743if (OpenMP_FOUND)
38- target_link_libraries (Spglib_symspg PRIVATE OpenMP::OpenMP_C )
39- endif ()
44+ target_link_libraries (Spglib_symspg INTERFACE OpenMP::OpenMP_C )
45+ target_link_libraries (Spglib_src_obj PUBLIC OpenMP::OpenMP_C )
46+ endif ()
47+ if (SPGLIB_USE_OMP)
48+ # Add additional library that is guaranteed to have omp
49+ # TODO: might be better to keep them separate them, but how do we link to either version on fortran/python?
50+ add_library (Spglib_omp )
51+ target_sources (Spglib_omp PRIVATE $<TARGET_OBJECTS :Spglib_src_obj >)
52+ add_library (Spglib::omp ALIAS Spglib_omp )
53+ set_target_properties (Spglib_omp PROPERTIES
54+ VERSION ${PROJECT_VERSION}
55+ SOVERSION ${PROJECT_VERSION_MAJOR}
56+ EXPORT_NAME omp
57+ OUTPUT_NAME symspg-omp
58+ PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR} /spglib.h )
59+ target_include_directories (Spglib_omp INTERFACE
60+ "$<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} >"
61+ "$<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >" )
62+ target_link_libraries (Spglib_omp INTERFACE OpenMP::OpenMP_C )
63+ endif ()
4064# Should not be needed anymore
4165#if(NOT MSVC)
4266# # Link to mathlibrary
@@ -49,7 +73,7 @@ if (SPGLIB_USE_SANITIZER)
4973 string (TOLOWER ${SPGLIB_USE_SANITIZER} SPGLIB_USE_SANITIZER)
5074 target_compile_options (Spglib_symspg PUBLIC -fsanitize=${SPGLIB_USE_SANITIZER} )
5175 target_link_options (Spglib_symspg PUBLIC -fsanitize=${SPGLIB_USE_SANITIZER} )
52- endif ()
76+ endif ()
5377if ("${CMAKE_BUILD_TYPE} " STREQUAL "Debug" )
5478 target_compile_definitions (Spglib_symspg
5579 PUBLIC SPGDEBUG SPGWARNING )
0 commit comments