From bb8bde35b8eb75d0edb8bc2812ddc22bdc61fd58 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 7 Jan 2014 18:15:27 +0100 Subject: [PATCH] Help: Add notes about relocatability of config-file packages. --- Help/manual/cmake-packages.7.rst | 38 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst index b572bf7e6..e87eb8358 100644 --- a/Help/manual/cmake-packages.7.rst +++ b/Help/manual/cmake-packages.7.rst @@ -392,11 +392,41 @@ should be provided by the ``ClimbingStats`` package, they should be in a separate file which is installed to the same location as the ``ClimbingStatsConfig.cmake`` file, and included from there. +Packages created by :command:`install(EXPORT)` are designed to be relocatable, +using paths relative to the location of the package itself. When defining +the interface of a target for ``EXPORT``, keep in mind that the include +directories should be specified as relative paths which are relative to the +:variable:`CMAKE_INSTALL_PREFIX`: + +.. code-block:: cmake + + target_include_directories(tgt INTERFACE + # Wrong, not relocatable: + $ + ) + + target_include_directories(tgt INTERFACE + # Ok, relocatable: + $ + ) + +The ``$`` +:manual:`generator expression ` may be used as +a placeholder for the install prefix without resulting in a non-relocatable +package. This is necessary if complex generator expressions are used: + +.. code-block:: cmake + + target_include_directories(tgt INTERFACE + # Ok, relocatable: + $:$/include/TgtName>> + ) + The :command:`export(EXPORT)` command creates an :prop_tgt:`IMPORTED` targets -definition file which is specific to the build-tree. This can similiarly be -used with a suitable package configuration file and package version file to -define a package for the build tree which may be used without installation. -Consumers of the build tree can simply ensure that the +definition file which is specific to the build-tree, and is not relocatable. +This can similiarly be used with a suitable package configuration file and +package version file to define a package for the build tree which may be used +without installation. Consumers of the build tree can simply ensure that the :variable:`CMAKE_PREFIX_PATH` contains the build directory, or set the ``ClimbingStats_DIR`` to ``/ClimbingStats`` in the cache.