summaryrefslogtreecommitdiff
path: root/Modules/CMakePackageConfigHelpers.cmake
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-08-30 12:59:42 +0200
committerStephen Kelly <steveire@gmail.com>2013-08-30 13:03:10 +0200
commitbb501a2a648f4c2e2dd008b925b87b575b4e2cf1 (patch)
tree5e804d52d827cf072d282b39ad38407b04242687 /Modules/CMakePackageConfigHelpers.cmake
parent549b95f115d1f98a68ed390816d5ac9e1eb38806 (diff)
downloadcmake-bb501a2a648f4c2e2dd008b925b87b575b4e2cf1.tar.gz
CMakePackageConfigHelpers: Add a find_dependency macro
This macro handles the EXACT, REQUIRED and QUIET options and sets an appropriate NOT_FOUND_MESSAGE for the package if a dependency is not found.
Diffstat (limited to 'Modules/CMakePackageConfigHelpers.cmake')
-rw-r--r--Modules/CMakePackageConfigHelpers.cmake39
1 files changed, 37 insertions, 2 deletions
diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake
index d042d5e0f0..3c56b7fcc6 100644
--- a/Modules/CMakePackageConfigHelpers.cmake
+++ b/Modules/CMakePackageConfigHelpers.cmake
@@ -3,7 +3,8 @@
# CONFIGURE_PACKAGE_CONFIG_FILE(<input> <output> INSTALL_DESTINATION <path>
# [PATH_VARS <var1> <var2> ... <varN>]
# [NO_SET_AND_CHECK_MACRO]
-# [NO_CHECK_REQUIRED_COMPONENTS_MACRO])
+# [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
+# [NO_FIND_DEPENDENCY_MACRO])
#
# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain
# configure_file() command when creating the <Name>Config.cmake or <Name>-config.cmake
@@ -154,7 +155,7 @@ endmacro()
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 NO_FIND_DEPENDENCY_MACRO)
set(oneValueArgs INSTALL_DESTINATION )
set(multiValueArgs PATH_VARS )
@@ -240,6 +241,40 @@ 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()
+")
+ endif()
+
set(PACKAGE_INIT "${PACKAGE_INIT}
####################################################################################")