summaryrefslogtreecommitdiff
path: root/Modules/CMakeFindDependencyMacro.cmake
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-11-27 13:43:52 +0100
committerStephen Kelly <steveire@gmail.com>2013-12-13 16:14:02 +0100
commit20cafa2e1faff577143eb56d14e5c3998cb7d6a9 (patch)
treeee6f37c3dbebde1bdad318ee503ed5214fb9a561 /Modules/CMakeFindDependencyMacro.cmake
parentd05e0aa845a99d2a04f61578ba9882ba9a2949c4 (diff)
downloadcmake-20cafa2e1faff577143eb56d14e5c3998cb7d6a9.tar.gz
Split the find_dependency macro into a separate file.
This allows Config file authors to use it without having to use CONFIGURE_PACKAGE_CONFIG_FILE.
Diffstat (limited to 'Modules/CMakeFindDependencyMacro.cmake')
-rw-r--r--Modules/CMakeFindDependencyMacro.cmake58
1 files changed, 58 insertions, 0 deletions
diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake
new file mode 100644
index 0000000000..596c6fc937
--- /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()