From bfa61ccf64db099f182da72854835a3a6263b981 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 23 Jan 2023 16:09:54 -0500 Subject: Help: Modernize PackageConfigHelpers example The example shown in the module documentation for CMakePackageConfigHelpers was showing its age, by: 1. Hardcoding directory prefixes (`etc/`, `lib/`, etc.) instead of using GNUInstallDirs 2. Handwaving `set()` commands (incorrectly!) as: `set(VAR dir/ ... CACHE )` which should, at the very least, be: `set(VAR dir/ CACHE ... )` 3. Installing CMake configuration files to `lib/Foo/cmake/`, when current practice favors `${CMAKE_INSTALL_LIBDIR}/cmake/Foo/` This updated example addresses all of those issues. --- Modules/CMakePackageConfigHelpers.cmake | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake index 6f5702a..1dc850a 100644 --- a/Modules/CMakePackageConfigHelpers.cmake +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -200,14 +200,16 @@ Example using both :command:`configure_package_config_file` and .. code-block:: cmake - set(INCLUDE_INSTALL_DIR include/ ... CACHE ) - set(LIB_INSTALL_DIR lib/ ... CACHE ) - set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE ) + include(GNUInstallDirs) + set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/Foo + CACHE PATH "Location of header files" ) + set(SYSCONFIG_INSTALL_DIR ${CMAKE_INSTALL_SYSCONFDIR}/foo + CACHE PATH "Location of configuration files" ) #... include(CMakePackageConfigHelpers) configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake - INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Foo PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake @@ -215,7 +217,7 @@ Example using both :command:`configure_package_config_file` and COMPATIBILITY SameMajorVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake - DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake ) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Foo ) ``FooConfig.cmake.in``: -- cgit v0.12