Skip to content

Commit

Permalink
Merge pull request #121 from chayden83/config-file-package
Browse files Browse the repository at this point in the history
Add Basic CMake Config File Package Creation and Installation
  • Loading branch information
JeffGarland authored Feb 28, 2025
2 parents f144574 + 3606545 commit 94f65c0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ jobs:
arg: "-DBEMAN_EXEMPLAR_BUILD_TESTS=OFF"
- name: "Disable example building"
arg: "-DBEMAN_EXEMPLAR_BUILD_EXAMPLES=OFF"
- name: "Disable config-file package creation"
arg: "-DBEMAN_EXEMPLAR_INSTALL_CONFIG_FILE_PACKAGE=OFF"
name: "CMake: ${{ matrix.args.name }}"
steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(
# targets (e.g., library, executable, etc.).
DESCRIPTION "A Beman library exemplar"
LANGUAGES CXX
VERSION 0.1.0
)

enable_testing()
Expand All @@ -25,6 +26,12 @@ option(
${PROJECT_IS_TOP_LEVEL}
)

option(
BEMAN_EXEMPLAR_INSTALL_CONFIG_FILE_PACKAGE
"Enable creating and installing a CMake config-file package. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }."
${PROJECT_IS_TOP_LEVEL}
)

include(FetchContent)
include(GNUInstallDirs)

Expand Down
7 changes: 7 additions & 0 deletions cmake/beman.exemplar-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(BEMAN_EXEMPLAR_VERSION @PROJECT_VERSION@)

@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)

check_required_components(@PROJECT_NAME@)
42 changes: 39 additions & 3 deletions src/beman/exemplar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,49 @@ target_sources(
FILES ${PROJECT_SOURCE_DIR}/include/beman/exemplar/identity.hpp
)

set_target_properties(beman.exemplar PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)
set_target_properties(
beman.exemplar
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON EXPORT_NAME exemplar
)

install(
TARGETS beman.exemplar
EXPORT beman.exemplar
DESTINATION
$<$<CONFIG:Debug>:debug/>${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION $<$<CONFIG:Debug>:debug/>${CMAKE_INSTALL_BINDIR}
${CMAKE_INSTALL_LIBDIR}$<$<CONFIG:Debug>:/debug>
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}$<$<CONFIG:Debug>:/debug>
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

if(BEMAN_EXEMPLAR_INSTALL_CONFIG_FILE_PACKAGE)
include(CMakePackageConfigHelpers)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
PATH_VARS PROJECT_NAME PROJECT_VERSION
)

write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(
FILES
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT development
)

install(
EXPORT beman.exemplar
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
NAMESPACE beman::
FILE ${PROJECT_NAME}-targets.cmake
COMPONENT development
)
endif()

0 comments on commit 94f65c0

Please sign in to comment.