Skip to content

Commit a820d38

Browse files
committed
Write CMake config-file package using helper
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.
1 parent 95faf1f commit a820d38

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,19 @@ install(FILES ${docopt_HEADERS} DESTINATION include/docopt)
101101

102102
# CMake Package
103103
include(CMakePackageConfigHelpers)
104-
write_basic_package_version_file("${PROJECT_BINARY_DIR}/docopt-config-version.cmake" COMPATIBILITY SameMajorVersion)
105-
install(FILES docopt-config.cmake ${PROJECT_BINARY_DIR}/docopt-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
106-
install(EXPORT ${export_name} DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
104+
set(ConfigPackageLocation "cmake/docopt")
105+
# Unix layout, ref https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
106+
configure_package_config_file(docopt-config.cmake.in
107+
"${CMAKE_CURRENT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config.cmake"
108+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}")
109+
write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config-version.cmake"
110+
COMPATIBILITY SameMajorVersion)
111+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config.cmake"
112+
${PROJECT_BINARY_DIR}/${ConfigPackageLocation}/docopt-config-version.cmake
113+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}")
114+
install(EXPORT ${export_name}
115+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}"
116+
NAMESPACE Docopt::)
107117

108118
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc @ONLY)
109119
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
@PACKAGE_INIT@
2+
13
include("${CMAKE_CURRENT_LIST_DIR}/docopt-targets.cmake")
4+
5+
check_required_components(docopt)

0 commit comments

Comments
 (0)