CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Loading...
Searching...
No Matches
CMakeFindDependencyMacro.cmake
Go to the documentation of this file.
1#.rst:
2# CMakeFindDependencyMacro
3# -------------------------
4#
5# ::
6#
7# find_dependency(<dep> [<version> [EXACT]])
8#
9#
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.
15#
16
17#=============================================================================
18# Copyright 2013 Stephen Kelly <steveire@gmail.com>
19#
20# CMake - Cross Platform Makefile Generator
21# Copyright 2000-2014 Kitware, Inc.
22# Copyright 2000-2011 Insight Software Consortium
23# All rights reserved.
24#
25# Redistribution and use in source and binary forms, with or without
26# modification, are permitted provided that the following conditions
27# are met:
28#
29# * Redistributions of source code must retain the above copyright
30# notice, this list of conditions and the following disclaimer.
31#
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.
35#
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
39# permission.
40#
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.
52#
53#=============================================================================
54
55macro(find_dependency dep)
56 if (NOT ${dep}_FOUND)
57 set(cmake_fd_version)
58 if (${ARGC} GREATER 1)
59 if ("${ARGV1}" STREQUAL "")
60 message(FATAL_ERROR "Invalid arguments to find_dependency. VERSION is empty")
61 endif()
62 if ("${ARGV1}" STREQUAL EXACT)
63 message(FATAL_ERROR "Invalid arguments to find_dependency. EXACT may only be specified if a VERSION is specified")
64 endif()
65 set(cmake_fd_version ${ARGV1})
66 endif()
67 set(cmake_fd_exact_arg)
68 if(${ARGC} GREATER 2)
69 if (NOT "${ARGV2}" STREQUAL EXACT)
70 message(FATAL_ERROR "Invalid arguments to find_dependency")
71 endif()
72 set(cmake_fd_exact_arg EXACT)
73 endif()
74 if(${ARGC} GREATER 3)
75 message(FATAL_ERROR "Invalid arguments to find_dependency")
76 endif()
77 set(cmake_fd_quiet_arg)
78 if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
79 set(cmake_fd_quiet_arg QUIET)
80 endif()
81 set(cmake_fd_required_arg)
82 if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
83 set(cmake_fd_required_arg REQUIRED)
84 endif()
85
86 get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY
87 _CMAKE_${dep}_TRANSITIVE_DEPENDENCY
88 )
89
90 find_package(${dep} ${cmake_fd_version}
91 ${cmake_fd_exact_arg}
92 ${cmake_fd_quiet_arg}
93 ${cmake_fd_required_arg}
94 )
95
96 if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
97 set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE)
98 endif()
99
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)
103 return()
104 endif()
105 set(cmake_fd_version)
106 set(cmake_fd_required_arg)
107 set(cmake_fd_quiet_arg)
108 set(cmake_fd_exact_arg)
109 endif()
110endmacro()