Skip to content

Commit

Permalink
Write CMake config-file package using helper
Browse files Browse the repository at this point in the history
Write our CMake config-file package using the
`configure_package_config_file` function defined in
CMakePackageConfigHelpers.cmake
and export our library in a namespace so that it can be used as an
imported target.
  • Loading branch information
eaaltonen committed Oct 14, 2022
1 parent 95faf1f commit d97004e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,19 @@ install(FILES ${docopt_HEADERS} DESTINATION include/docopt)

# CMake Package
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/docopt-config-version.cmake" COMPATIBILITY SameMajorVersion)
install(FILES docopt-config.cmake ${PROJECT_BINARY_DIR}/docopt-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
install(EXPORT ${export_name} DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
set(ConfigPackageLocation "cmake/docopt")
# Unix layout, ref https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
configure_package_config_file(docopt-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}")
write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config-version.cmake"
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config.cmake"
${PROJECT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config-version.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}")
install(EXPORT ${export_name}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}"
NAMESPACE Docopt::)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Expand Down
4 changes: 4 additions & 0 deletions docopt-config.cmake → docopt-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/docopt-targets.cmake")

check_required_components(docopt)

0 comments on commit d97004e

Please sign in to comment.