-
Notifications
You must be signed in to change notification settings - Fork 18
Fix CMake export and include interfaces #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 15 commits
d5a94db
74fecb7
640644a
62455c3
7a68f0e
f1e880a
e5db953
9cffc2b
960796b
8751dae
2d6daa1
f898abd
66a54c1
9d8ef4d
b813de2
0c8fb71
e0d9ca0
e028d87
94e39b0
4a98590
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| cmake_minimum_required(VERSION 3.12.0) # older would work, but could give warnings on policy CMP0074 | ||
| project(petsird VERSION 0.7.2) | ||
| project(petsird VERSION 0.7.2 LANGUAGES CXX) | ||
| include(GNUInstallDirs) | ||
| set(PETSIRD_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/PETSIRD") | ||
|
|
||
| include(CMakePackageConfigHelpers) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| if(WIN32) | ||
| add_compile_options(/W3 /WX) | ||
|
|
@@ -15,14 +20,71 @@ if(CCACHE_PROGRAM) | |
| message(STATUS "ccache found, so we will use it.") | ||
| endif() | ||
|
|
||
| find_package(date REQUIRED) | ||
|
|
||
| # assume that yardl was run with the following in the _package.yml | ||
| # sourcesOutputDir: ../cpp/generated/petsird | ||
|
|
||
| add_subdirectory(generated/petsird) | ||
| add_subdirectory(helpers) | ||
| # create a petsird library target | ||
| # Currently it is just empty, but allows creating target properties which are transitive | ||
| add_library(petsird) | ||
| target_link_libraries(petsird PUBLIC petsird_generated) | ||
| target_include_directories(petsird PUBLIC "${PROJECT_SOURCE_DIR}/generated") | ||
| add_library(PETSIRD::petsird ALIAS petsird) | ||
|
|
||
| add_subdirectory(helpers) | ||
| target_link_libraries(petsird | ||
| PUBLIC | ||
| petsird_generated | ||
| petsird_helpers | ||
| date::date | ||
NikEfth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| target_compile_features(petsird PUBLIC cxx_std_17) | ||
|
||
|
|
||
| target_include_directories(petsird | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/generated> | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/helpers/include> | ||
NikEfth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
|
|
||
| install(TARGETS petsird petsird_generated petsird_helpers | ||
| EXPORT petsirdTargets | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| ) | ||
|
|
||
| install( | ||
| DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/generated/petsird/ | ||
| DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/petsird | ||
| ) | ||
|
|
||
| install( | ||
| DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/helpers/include/ | ||
| DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| ) | ||
|
|
||
| install(EXPORT petsirdTargets | ||
| NAMESPACE PETSIRD:: | ||
| DESTINATION ${PETSIRD_CMAKE_DIR} | ||
| ) | ||
|
|
||
|
|
||
| configure_package_config_file( | ||
| cmake/PETSIRDConfig.cmake.in | ||
| ${CMAKE_CURRENT_BINARY_DIR}/PETSIRDConfig.cmake | ||
| INSTALL_DESTINATION ${PETSIRD_CMAKE_DIR} | ||
| ) | ||
|
|
||
| write_basic_package_version_file( | ||
| ${CMAKE_CURRENT_BINARY_DIR}/PETSIRDConfigVersion.cmake | ||
| VERSION ${PROJECT_VERSION} | ||
| COMPATIBILITY SameMajorVersion | ||
| ) | ||
|
|
||
| install(FILES | ||
| ${CMAKE_CURRENT_BINARY_DIR}/PETSIRDConfig.cmake | ||
| ${CMAKE_CURRENT_BINARY_DIR}/PETSIRDConfigVersion.cmake | ||
| DESTINATION ${PETSIRD_CMAKE_DIR} | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @PACKAGE_INIT@ | ||
| include(CMakeFindDependencyMacro) | ||
| find_dependency(date) | ||
| find_dependency(BLAS) | ||
NikEfth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if(@PETSIRD_GENERATED_USE_NDJSON@) | ||
| find_dependency(nlohmann_json) | ||
| endif() | ||
| if(@PETSIRD_GENERATED_USE_HDF5@) | ||
| find_dependency(HDF5 COMPONENTS CXX) | ||
| endif() | ||
| include("${CMAKE_CURRENT_LIST_DIR}/petsirdTargets.cmake") | ||
| check_required_components(PETSIRD) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,33 @@ | ||
| find_package(xtensor-blas REQUIRED) | ||
| find_package(xtensor REQUIRED) | ||
| # find_package(xtensor-blas REQUIRED) | ||
| find_package(BLAS REQUIRED) | ||
|
||
|
|
||
| # create a petsird_helpers library target | ||
| # Currently it is just empty, but allows creating target properties which are transitive | ||
| add_library(petsird_helpers INTERFACE) | ||
| target_link_libraries(petsird_helpers INTERFACE petsird xtensor-blas) | ||
| target_include_directories(petsird_helpers INTERFACE "${PROJECT_SOURCE_DIR}/helpers/include") | ||
|
|
||
| target_include_directories(petsird_helpers | ||
| INTERFACE | ||
| ${xtensor_INCLUDE_DIRS} | ||
|
||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
|
|
||
| target_link_libraries(petsird_helpers INTERFACE petsird BLAS::BLAS) | ||
NikEfth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| add_executable(petsird_generator petsird_generator.cpp) | ||
| target_link_libraries(petsird_generator petsird_helpers) | ||
| target_link_libraries(petsird_generator PRIVATE petsird_helpers) | ||
|
|
||
| add_executable(petsird_analysis petsird_analysis.cpp) | ||
| target_link_libraries(petsird_analysis petsird_helpers) | ||
| target_link_libraries(petsird_analysis PRIVATE petsird_helpers) | ||
|
|
||
| foreach(t petsird petsird_generated petsird_helpers) | ||
| if(TARGET ${t}) | ||
| get_target_property(_libs ${t} INTERFACE_LINK_LIBRARIES) | ||
| if(_libs) | ||
| list(FILTER _libs EXCLUDE REGEX "xtensor") | ||
| set_target_properties(${t} | ||
| PROPERTIES INTERFACE_LINK_LIBRARIES "${_libs}") | ||
| endif() | ||
| endif() | ||
| endforeach() | ||
|
Comment on lines
+25
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you need this? (probably because you removed
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To undo an overly-aggressive dependency propagation introduced by generated / helper targets.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as xtensor is header-only, we could use the same trick as https://github.com/UCL/STIR/blob/ec3a5670f9b63cb10f4bebce6edf22d6f028a6fb/src/buildblock/CMakeLists.txt#L125-L137, i.e. only add the include path. However, this is all quite ugly. I'd rather avoid it as much as possible. As long as we have |
||
Uh oh!
There was an error while loading. Please reload this page.