2# CMakeFindDependencyMacro
3# -------------------------
7# find_dependency(<dep> [<version> [EXACT]])
10# ``find_dependency()`` wraps a :command:`find_package` call for a package
11# dependency. It is designed to be used in a <package>Config.cmake file, and it
12# forwards the correct parameters for EXACT, QUIET and REQUIRED which were
13# passed to the original :command:`find_package` call. It also sets an
14# informative diagnostic message if the dependency could not be found.
17#=============================================================================
18# Copyright 2013 Stephen Kelly <steveire@gmail.com>
20# CMake - Cross Platform Makefile Generator
21# Copyright 2000-2014 Kitware, Inc.
22# Copyright 2000-2011 Insight Software Consortium
25# Redistribution and use in source and binary forms, with or without
26# modification, are permitted provided that the following conditions
29# * Redistributions of source code must retain the above copyright
30# notice, this list of conditions and the following disclaimer.
32# * Redistributions in binary form must reproduce the above copyright
33# notice, this list of conditions and the following disclaimer in the
34# documentation and/or other materials provided with the distribution.
36# * Neither the names of Kitware, Inc., the Insight Software Consortium,
37# nor the names of their contributors may be used to endorse or promote
38# products derived from this software without specific prior written
41# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
42# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
43# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
44# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
45# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#=============================================================================
55macro(find_dependency dep)
58 if (${ARGC} GREATER 1)
59 if ("${ARGV1}" STREQUAL "")
60 message(FATAL_ERROR "Invalid arguments to find_dependency. VERSION is empty")
62 if ("${ARGV1}" STREQUAL EXACT)
63 message(FATAL_ERROR "Invalid arguments to find_dependency. EXACT may only be specified if a VERSION is specified")
65 set(cmake_fd_version ${ARGV1})
67 set(cmake_fd_exact_arg)
69 if (NOT "${ARGV2}" STREQUAL EXACT)
70 message(FATAL_ERROR "Invalid arguments to find_dependency")
72 set(cmake_fd_exact_arg EXACT)
75 message(FATAL_ERROR "Invalid arguments to find_dependency")
77 set(cmake_fd_quiet_arg)
78 if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
79 set(cmake_fd_quiet_arg QUIET)
81 set(cmake_fd_required_arg)
82 if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
83 set(cmake_fd_required_arg REQUIRED)
86 get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY
87 _CMAKE_${dep}_TRANSITIVE_DEPENDENCY
90 find_package(${dep} ${cmake_fd_version}
93 ${cmake_fd_required_arg}
96 if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
97 set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE)
100 if (NOT ${dep}_FOUND)
101 set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
102 set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
105 set(cmake_fd_version)
106 set(cmake_fd_required_arg)
107 set(cmake_fd_quiet_arg)
108 set(cmake_fd_exact_arg)