Warning, /frameworks/extra-cmake-modules/modules/ECMPackageConfigHelpers.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kdemail.net>
0002 # SPDX-FileCopyrightText: 2013 Stephen Kelly <steveire@gmail.com>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 
0006 #[=======================================================================[.rst:
0007 ECMPackageConfigHelpers
0008 -----------------------
0009 
0010 Helper macros for generating CMake package config files.
0011 
0012 ``write_basic_package_version_file()`` is the same as the one provided by the
0013 `CMakePackageConfigHelpers
0014 <https://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:CMakePackageConfigHelpers>`_
0015 module in CMake; see that module's documentation for
0016 more information.
0017 
0018 ::
0019 
0020   ecm_configure_package_config_file(<input> <output>
0021       INSTALL_DESTINATION <path>
0022       [PATH_VARS <var1> [<var2> [...]]
0023       [NO_SET_AND_CHECK_MACRO]
0024       [NO_CHECK_REQUIRED_COMPONENTS_MACRO])
0025 
0026 
0027 This behaves in the same way as ``configure_package_config_file()`` from CMake
0028 2.8.12, except that it adds an extra helper macro: ``find_dependency()``. It is
0029 highly recommended that you read the `documentation for
0030 CMakePackageConfigHelpers
0031 <https://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:CMakePackageConfigHelpers>`_
0032 for more information, particularly with regard to the ``PATH_VARS`` argument.
0033 
0034 Note that there is no argument that will disable the ``find_dependency()`` macro;
0035 if you do not require this macro, you should use
0036 ``configure_package_config_file`` from the CMakePackageConfigHelpers module.
0037 
0038 CMake 3.0 includes a CMakeFindDependencyMacro module that provides the
0039 ``find_dependency()`` macro (which you can ``include()`` in your package config
0040 file), so this file is only useful for projects wishing to provide config
0041 files that will work with CMake 2.8.12.
0042 
0043 Additional Config File Macros
0044 =============================
0045 
0046 ::
0047 
0048   find_dependency(<dep> [<version> [EXACT]])
0049 
0050 ``find_dependency()`` should be used instead of ``find_package()`` to find package
0051 dependencies.  It forwards the correct parameters for ``EXACT``, ``QUIET`` and
0052 ``REQUIRED`` which were passed to the original ``find_package()`` call.  It also sets
0053 an informative diagnostic message if the dependency could not be found.
0054 
0055 Since pre-1.0.0.
0056 #]=======================================================================]
0057 
0058 include(${CMAKE_ROOT}/Modules/CMakePackageConfigHelpers.cmake)
0059 
0060 set(_ecm_package_config_helpers_included TRUE)
0061 
0062 message(AUTHOR_WARNING "Your project already requires a version of CMake that includes the find_dependency macro via the CMakeFindDependencyMacro module. You should use CMakePackageConfigHelpers instead of ECMPackageConfigHelpers.")
0063 
0064 function(ECM_CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
0065   set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
0066   set(oneValueArgs INSTALL_DESTINATION )
0067   set(multiValueArgs PATH_VARS )
0068 
0069   cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}"  ${ARGN})
0070 
0071   if(CCF_UNPARSED_ARGUMENTS)
0072     message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"")
0073   endif()
0074 
0075   if(NOT CCF_INSTALL_DESTINATION)
0076     message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()")
0077   endif()
0078 
0079   if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}")
0080     set(absInstallDir "${CCF_INSTALL_DESTINATION}")
0081   else()
0082     set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}")
0083   endif()
0084 
0085   file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" )
0086 
0087   foreach(var ${CCF_PATH_VARS})
0088     if(NOT DEFINED ${var})
0089       message(FATAL_ERROR "Variable ${var} does not exist")
0090     else()
0091       if(IS_ABSOLUTE "${${var}}")
0092         string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}"
0093                         PACKAGE_${var} "${${var}}")
0094       else()
0095         set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
0096       endif()
0097     endif()
0098   endforeach()
0099 
0100   get_filename_component(inputFileName "${_inputFile}" NAME)
0101 
0102   set(PACKAGE_INIT "
0103 ####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() (ECM variant) #######
0104 ####### Any changes to this file will be overwritten by the next CMake run            #######
0105 ####### The input file was ${inputFileName}                                           #######
0106 
0107 get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
0108 ")
0109 
0110   if("${absInstallDir}" MATCHES "^(/usr)?/lib(64)?/.+")
0111     # Handle "/usr move" symlinks created by some Linux distros.
0112     set(PACKAGE_INIT "${PACKAGE_INIT}
0113 # Use original install prefix when loaded through a \"/usr move\"
0114 # cross-prefix symbolic link such as /lib -> /usr/lib.
0115 get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH)
0116 get_filename_component(_realOrig \"${absInstallDir}\" REALPATH)
0117 if(_realCurr STREQUAL _realOrig)
0118   set(PACKAGE_PREFIX_DIR \"${CMAKE_INSTALL_PREFIX}\")
0119 endif()
0120 unset(_realOrig)
0121 unset(_realCurr)
0122 ")
0123   endif()
0124 
0125   if(NOT CCF_NO_SET_AND_CHECK_MACRO)
0126     set(PACKAGE_INIT "${PACKAGE_INIT}
0127 macro(set_and_check _var _file)
0128   set(\${_var} \"\${_file}\")
0129   if(NOT EXISTS \"\${_file}\")
0130     message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\")
0131   endif()
0132 endmacro()
0133 
0134 include(CMakeFindDependencyMacro OPTIONAL RESULT_VARIABLE _CMakeFindDependencyMacro_FOUND)
0135 
0136 if (NOT _CMakeFindDependencyMacro_FOUND)
0137   macro(find_dependency dep)
0138     if (NOT \${dep}_FOUND)
0139 
0140       set(ecm_fd_version)
0141       if (\${ARGC} GREATER 1)
0142         set(ecm_fd_version \${ARGV1})
0143       endif()
0144       set(ecm_fd_exact_arg)
0145       if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT)
0146         set(ecm_fd_exact_arg EXACT)
0147       endif()
0148       set(ecm_fd_quiet_arg)
0149       if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
0150         set(ecm_fd_quiet_arg QUIET)
0151       endif()
0152       set(ecm_fd_required_arg)
0153       if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
0154         set(ecm_fd_required_arg REQUIRED)
0155       endif()
0156 
0157       find_package(\${dep} \${ecm_fd_version}
0158           \${ecm_fd_exact_arg}
0159           \${ecm_fd_quiet_arg}
0160           \${ecm_fd_required_arg}
0161       )
0162 
0163       if (NOT \${dep}_FOUND)
0164         set(\${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE \"\${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency \${dep} could not be found.\")
0165         set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
0166         return()
0167       endif()
0168 
0169       set(ecm_fd_version)
0170       set(ecm_fd_required_arg)
0171       set(ecm_fd_quiet_arg)
0172       set(ecm_fd_exact_arg)
0173     endif()
0174   endmacro()
0175 endif()
0176 
0177 ")
0178   endif()
0179 
0180 
0181   if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO)
0182     set(PACKAGE_INIT "${PACKAGE_INIT}
0183 macro(check_required_components _NAME)
0184   foreach(comp \${\${_NAME}_FIND_COMPONENTS})
0185     if(NOT \${_NAME}_\${comp}_FOUND)
0186       if(\${_NAME}_FIND_REQUIRED_\${comp})
0187         set(\${_NAME}_FOUND FALSE)
0188       endif()
0189     endif()
0190   endforeach()
0191 endmacro()
0192 ")
0193   endif()
0194 
0195   set(PACKAGE_INIT "${PACKAGE_INIT}
0196 ####################################################################################")
0197 
0198   configure_file("${_inputFile}" "${_outputFile}" @ONLY)
0199 
0200 endfunction()