Help: Update cmake-packages.7 examples to import targets only once

Package configuration files should load their targets files at most once
in a given scope.  Update our ClimbingStats example to show how to do
this.
This commit is contained in:
Brad King 2014-07-09 12:54:22 -04:00
parent 55d3e88fb7
commit cfab942e5f
1 changed files with 11 additions and 4 deletions

View File

@ -385,9 +385,12 @@ In this case, the ``ClimbingStatsConfig.cmake`` file could be as simple as:
.. code-block:: cmake .. code-block:: cmake
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake") if(NOT TARGET Upstream::ClimbingStats)
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
endif()
As this allows downstreams to use the ``IMPORTED`` targets. If any macros This allows downstreams to use the ``IMPORTED`` targets, and guards
against importing the targets more than once. If any macros
should be provided by the ``ClimbingStats`` package, they should should be provided by the ``ClimbingStats`` package, they should
be in a separate file which is installed to the same location as the be in a separate file which is installed to the same location as the
``ClimbingStatsConfig.cmake`` file, and included from there. ``ClimbingStatsConfig.cmake`` file, and included from there.
@ -454,7 +457,9 @@ dependencies of a package should be found in the ``Config.cmake`` file:
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
find_dependency(Stats 2.6.4) find_dependency(Stats 2.6.4)
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake") if(NOT TARGET Upstream::ClimbingStats)
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake") include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake")
The ``find_dependency`` macro also sets ``ClimbingStats_FOUND`` to ``False`` if The ``find_dependency`` macro also sets ``ClimbingStats_FOUND`` to ``False`` if
@ -471,7 +476,9 @@ be true. This can be tested with logic in the package configuration file:
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
find_dependency(Stats 2.6.4) find_dependency(Stats 2.6.4)
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake") if(NOT TARGET Upstream::ClimbingStats)
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake") include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake")
set(_supported_components Plot Table) set(_supported_components Plot Table)