diff options
author | FeRD (Frank Dana) <ferdnyc@gmail.com> | 2023-01-23 21:09:54 (GMT) |
---|---|---|
committer | FeRD (Frank Dana) <ferdnyc@gmail.com> | 2023-01-23 23:02:31 (GMT) |
commit | bfa61ccf64db099f182da72854835a3a6263b981 (patch) | |
tree | 196f020e33ce78b480cc91c5cf1b4dc37b5701da /Modules | |
parent | f9f34eb11143e5c5c1daee4aa2867139cf930aa4 (diff) | |
download | CMake-bfa61ccf64db099f182da72854835a3a6263b981.zip CMake-bfa61ccf64db099f182da72854835a3a6263b981.tar.gz CMake-bfa61ccf64db099f182da72854835a3a6263b981.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakePackageConfigHelpers.cmake | 12 |
1 files 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``: |