Commit d057bf85 authored by Daniele E. Domenichelli's avatar Daniele E. Domenichelli Committed by Brad King
Browse files

CMakePackageConfigHelpers: Add INSTALL_PREFIX option

This option instructs configure_package_config_file to consider paths
that are not absolute as relative to the INSTALL_PREFIX directory
instead of relative to the CMAKE_INSTALL_PREFIX directory.

If this argument is not passed, the default behaviour is to use
the CMAKE_INSTALL_PREFIX variable.

The new signature is therefore:

  configure_package_config_file(<input> <output> INSTALL_DESTINATION <path>
                                                 [PATH_VARS <var1> <var2> ... <varN>]
                                                 [NO_SET_AND_CHECK_MACRO]
                                                 [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
                                                 [INSTALL_PREFIX <path>])
parent f3dd116c
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
# configure_package_config_file(<input> <output> INSTALL_DESTINATION <path> # configure_package_config_file(<input> <output> INSTALL_DESTINATION <path>
# [PATH_VARS <var1> <var2> ... <varN>] # [PATH_VARS <var1> <var2> ... <varN>]
# [NO_SET_AND_CHECK_MACRO] # [NO_SET_AND_CHECK_MACRO]
# [NO_CHECK_REQUIRED_COMPONENTS_MACRO]) # [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
# [INSTALL_PREFIX <path>])
# #
# #
# ``configure_package_config_file()`` should be used instead of the plain # ``configure_package_config_file()`` should be used instead of the plain
...@@ -64,8 +65,8 @@ ...@@ -64,8 +65,8 @@
# same way as in :command:`configure_file()`. # same way as in :command:`configure_file()`.
# #
# The ``<path>`` given to ``INSTALL_DESTINATION`` must be the destination where # The ``<path>`` given to ``INSTALL_DESTINATION`` must be the destination where
# the ``FooConfig.cmake`` file will be installed to. This can either be a # the ``FooConfig.cmake`` file will be installed to. This path can either be
# relative or absolute path, both work. # absolute, or relative to the ``INSTALL_PREFIX`` path.
# #
# The variables ``<var1>`` to ``<varN>`` given as ``PATH_VARS`` are the # The variables ``<var1>`` to ``<varN>`` given as ``PATH_VARS`` are the
# variables which contain install destinations. For each of them the macro will # variables which contain install destinations. For each of them the macro will
...@@ -74,8 +75,15 @@ ...@@ -74,8 +75,15 @@
# They are calculated by ``configure_package_config_file`` so that they are # They are calculated by ``configure_package_config_file`` so that they are
# always relative to the installed location of the package. This works both for # always relative to the installed location of the package. This works both for
# relative and also for absolute locations. For absolute locations it works # relative and also for absolute locations. For absolute locations it works
# only if the absolute location is a subdirectory of # only if the absolute location is a subdirectory of ``INSTALL_PREFIX``.
# :variable:`CMAKE_INSTALL_PREFIX`. #
# If the ``INSTALL_PREFIX`` argument is passed, this is used as base path to
# calculate all the relative paths. The ``<path>`` argument must be an absolute
# path. If this argument is not passed, the :variable:`CMAKE_INSTALL_PREFIX`
# variable will be used instead. The default value is good when generating a
# FooConfig.cmake file to use your package from the install tree. When
# generating a FooConfig.cmake file to use your package from the build tree this
# option should be used.
# #
# By default ``configure_package_config_file`` also generates two helper macros, # By default ``configure_package_config_file`` also generates two helper macros,
# ``set_and_check()`` and ``check_required_components()`` into the # ``set_and_check()`` and ``check_required_components()`` into the
...@@ -210,7 +218,7 @@ endmacro() ...@@ -210,7 +218,7 @@ endmacro()
function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile) function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
set(oneValueArgs INSTALL_DESTINATION ) set(oneValueArgs INSTALL_DESTINATION INSTALL_PREFIX)
set(multiValueArgs PATH_VARS ) set(multiValueArgs PATH_VARS )
cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
...@@ -223,20 +231,30 @@ function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile) ...@@ -223,20 +231,30 @@ function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()") message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()")
endif() endif()
if(DEFINED CCF_INSTALL_PREFIX)
if(IS_ABSOLUTE "${CCF_INSTALL_PREFIX}")
set(installPrefix "${CCF_INSTALL_PREFIX}")
else()
message(FATAL_ERROR "INSTALL_PREFIX must be an absolute path")
endif()
else()
set(installPrefix "${CMAKE_INSTALL_PREFIX}")
endif()
if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}") if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}")
set(absInstallDir "${CCF_INSTALL_DESTINATION}") set(absInstallDir "${CCF_INSTALL_DESTINATION}")
else() else()
set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}") set(absInstallDir "${installPrefix}/${CCF_INSTALL_DESTINATION}")
endif() endif()
file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" ) file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${installPrefix}" )
foreach(var ${CCF_PATH_VARS}) foreach(var ${CCF_PATH_VARS})
if(NOT DEFINED ${var}) if(NOT DEFINED ${var})
message(FATAL_ERROR "Variable ${var} does not exist") message(FATAL_ERROR "Variable ${var} does not exist")
else() else()
if(IS_ABSOLUTE "${${var}}") if(IS_ABSOLUTE "${${var}}")
string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}" string(REPLACE "${installPrefix}" "\${PACKAGE_PREFIX_DIR}"
PACKAGE_${var} "${${var}}") PACKAGE_${var} "${${var}}")
else() else()
set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}") set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
...@@ -262,7 +280,7 @@ get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE ...@@ -262,7 +280,7 @@ get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE
get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH) get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH)
get_filename_component(_realOrig \"${absInstallDir}\" REALPATH) get_filename_component(_realOrig \"${absInstallDir}\" REALPATH)
if(_realCurr STREQUAL _realOrig) if(_realCurr STREQUAL _realOrig)
set(PACKAGE_PREFIX_DIR \"${CMAKE_INSTALL_PREFIX}\") set(PACKAGE_PREFIX_DIR \"${installPrefix}\")
endif() endif()
unset(_realOrig) unset(_realOrig)
unset(_realCurr) unset(_realCurr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment