Skip to content

Commit

Permalink
Merge pull request #51 from stephenswat/build/install_only_top_level
Browse files Browse the repository at this point in the history
Enable installation only if top-level
  • Loading branch information
stephenswat authored Jan 21, 2025
2 parents 5699bb6 + aef0d2e commit 092c9c3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
58 changes: 30 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,33 @@ if(COVFIE_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Installation logic.
# CMake is hell.
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

install(
FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)
if(PROJECT_IS_TOP_LEVEL)
# Installation logic.
# CMake is hell.
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

install(
FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)
endif()
14 changes: 8 additions & 6 deletions lib/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ set_target_properties(
core
)

install(TARGETS covfie_core EXPORT ${PROJECT_NAME}Targets)
if(PROJECT_IS_TOP_LEVEL)
install(TARGETS covfie_core EXPORT ${PROJECT_NAME}Targets)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/covfie
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/covfie
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

# Hack for people using the disgusting mal-practice of pullling in external
# projects via "add_subdirectory"...
Expand Down
14 changes: 8 additions & 6 deletions lib/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ set_target_properties(
cpu
)

install(TARGETS covfie_cpu EXPORT ${PROJECT_NAME}Targets)
if(PROJECT_IS_TOP_LEVEL)
install(TARGETS covfie_cpu EXPORT ${PROJECT_NAME}Targets)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/covfie
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/covfie
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

target_link_libraries(covfie_cpu INTERFACE covfie_core)

Expand Down
14 changes: 8 additions & 6 deletions lib/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ set_target_properties(
cuda
)

install(TARGETS covfie_cuda EXPORT ${PROJECT_NAME}Targets)
if(PROJECT_IS_TOP_LEVEL)
install(TARGETS covfie_cuda EXPORT ${PROJECT_NAME}Targets)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/covfie
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/covfie
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

# Hack for compatibility
if(NOT PROJECT_IS_TOP_LEVEL)
Expand Down

0 comments on commit 092c9c3

Please sign in to comment.