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.
This commit is contained in:
FeRD (Frank Dana)
2023-01-23 16:09:54 -05:00
parent f9f34eb111
commit bfa61ccf64

View File

@@ -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``: