1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5CMakeFindDependencyMacro 6------------------------- 7 8.. command:: find_dependency 9 10 The ``find_dependency()`` macro wraps a :command:`find_package` call for 11 a package dependency:: 12 13 find_dependency(<dep> [...]) 14 15 It is designed to be used in a 16 :ref:`Package Configuration File <Config File Packages>` 17 (``<PackageName>Config.cmake``). ``find_dependency`` forwards the correct 18 parameters for ``QUIET`` and ``REQUIRED`` which were passed to 19 the original :command:`find_package` call. Any additional arguments 20 specified are forwarded to :command:`find_package`. 21 22 If the dependency could not be found it sets an informative diagnostic 23 message and calls :command:`return` to end processing of the calling 24 package configuration file and return to the :command:`find_package` 25 command that loaded it. 26 27 .. note:: 28 29 The call to :command:`return` makes this macro unsuitable to call 30 from :ref:`Find Modules`. 31#]=======================================================================] 32 33macro(find_dependency dep) 34 set(cmake_fd_quiet_arg) 35 if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) 36 set(cmake_fd_quiet_arg QUIET) 37 endif() 38 set(cmake_fd_required_arg) 39 if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) 40 set(cmake_fd_required_arg REQUIRED) 41 endif() 42 43 get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY 44 _CMAKE_${dep}_TRANSITIVE_DEPENDENCY 45 ) 46 47 find_package(${dep} ${ARGN} 48 ${cmake_fd_quiet_arg} 49 ${cmake_fd_required_arg} 50 ) 51 52 if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive) 53 set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE) 54 endif() 55 56 if (NOT ${dep}_FOUND) 57 set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.") 58 set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False) 59 return() 60 endif() 61 set(cmake_fd_required_arg) 62 set(cmake_fd_quiet_arg) 63endmacro() 64