Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
Eero Aaltonen committed Oct 17, 2022
commit a820d385662d5725a13e3acfe35d00344be53532
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's at least two valid choices here, so I'd like to check the project author's preference here:

  • unix layout (current)
  • picking a layout according the current / specified OS.

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::)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the name:

  • is current Docopt::docopt good
  • should it be Docopt.cpp::docopt
  • something else ?


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)