diff options
author | Brad King <brad.king@kitware.com> | 2013-12-20 20:01:26 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2013-12-20 20:01:26 (GMT) |
commit | 437236517784b7ca948f671a929304070d68b759 (patch) | |
tree | 0560064fbdc947edc77a5f80fbe656e31cc5f090 /Modules | |
parent | 6820882be57942403fa7eaf706a0169fd2816fc2 (diff) | |
parent | 3fe4ac828d91db6ebffce6a2e47b8f4cb069a49a (diff) | |
download | CMake-437236517784b7ca948f671a929304070d68b759.zip CMake-437236517784b7ca948f671a929304070d68b759.tar.gz CMake-437236517784b7ca948f671a929304070d68b759.tar.bz2 |
Merge topic 'cmake-packages-manual'
3fe4ac8 Help: Add a CMake manual for Packages related docs.
20cafa2 Split the find_dependency macro into a separate file.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakeFindDependencyMacro.cmake | 58 | ||||
-rw-r--r-- | Modules/CMakePackageConfigHelpers.cmake | 35 |
2 files changed, 62 insertions, 31 deletions
diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake new file mode 100644 index 0000000..596c6fc --- /dev/null +++ b/Modules/CMakeFindDependencyMacro.cmake @@ -0,0 +1,58 @@ +#.rst: +# CMakeFindDependencyMacro +# ------------------------- +# +# :: +# +# find_dependency(<dep> [<version>]) +# +# +# ``find_dependency()`` wraps a :command:`find_package` call for a package +# dependency. It is designed to be used in a <package>Config.cmake file, and it +# forwards the correct parameters for EXACT, QUIET and REQUIRED which were +# passed to the original :command:`find_package` call. It also sets an +# informative diagnostic message if the dependency could not be found. +# + +#============================================================================= +# Copyright 2013 Stephen Kelly <steveire@gmail.com> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +macro(find_dependency dep) + if (NOT ${dep}_FOUND) + if (${ARGV1}) + set(version ${ARGV1}) + endif() + set(exact_arg) + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT) + set(exact_arg EXACT) + endif() + set(quiet_arg) + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + set(quiet_arg QUIET) + endif() + set(required_arg) + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) + set(required_arg REQUIRED) + endif() + + find_package(${dep} ${version} ${exact_arg} ${quiet_arg} ${required_arg}) + if (NOT ${dep}_FOUND) + set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.") + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False) + return() + endif() + set(required_arg) + set(quiet_arg) + set(exact_arg) + endif() +endmacro() diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake index 855af9c..2c1c613 100644 --- a/Modules/CMakePackageConfigHelpers.cmake +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -196,11 +196,13 @@ include(CMakeParseArguments) include(WriteBasicConfigVersionFile) +include(CMakeFindDependencyMacro) macro(WRITE_BASIC_PACKAGE_VERSION_FILE) write_basic_config_version_file(${ARGN}) endmacro() +set(cfpch_dir ${CMAKE_CURRENT_LIST_DIR}) function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile) set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO NO_FIND_DEPENDENCY_MACRO) @@ -290,37 +292,8 @@ endmacro() endif() if(NOT CCF_NO_FIND_DEPENDENCY_MACRO) - set(PACKAGE_INIT "${PACKAGE_INIT} -macro(find_dependency dep) - if (NOT \${dep}_FOUND) - if (\${ARGV1}) - set(version \${ARGV1}) - endif() - set(exact_arg) - if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT) - set(exact_arg EXACT) - endif() - set(quiet_arg) - if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) - set(quiet_arg QUIET) - endif() - set(required_arg) - if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - set(required_arg REQUIRED) - endif() - - find_package(\${dep} \${version} \${exact_arg} \${quiet_arg} \${required_arg}) - if (NOT \${dep}_FOUND) - set(\${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE \"\${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency \${dep} could not be found.\") - set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND False) - return() - endif() - set(required_arg) - set(quiet_arg) - set(exact_arg) - endif() -endmacro() -") + file(READ "${cfpch_dir}/CMakeFindDependencyMacro.cmake" find_dependency_macro) + set(PACKAGE_INIT "${PACKAGE_INIT} ${find_dependency_macro}") endif() set(PACKAGE_INIT "${PACKAGE_INIT} |