Blame cmake/compat_2.8.11/CMakePackageConfigHelpers.cmake

Packit Service fa4841
# - CONFIGURE_PACKAGE_CONFIG_FILE(), WRITE_BASIC_PACKAGE_VERSION_FILE()
Packit Service fa4841
#
Packit Service fa4841
#    CONFIGURE_PACKAGE_CONFIG_FILE(<input> <output> INSTALL_DESTINATION <path>
Packit Service fa4841
#                                                   [PATH_VARS <var1> <var2> ... <varN>]
Packit Service fa4841
#                                                   [NO_SET_AND_CHECK_MACRO]
Packit Service fa4841
#                                                   [NO_CHECK_REQUIRED_COMPONENTS_MACRO])
Packit Service fa4841
#
Packit Service fa4841
# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain
Packit Service fa4841
# configure_file() command when creating the <Name>Config.cmake or <Name>-config.cmake
Packit Service fa4841
# file for installing a project or library. It helps making the resulting package
Packit Service fa4841
# relocatable by avoiding hardcoded paths in the installed Config.cmake file.
Packit Service fa4841
#
Packit Service fa4841
# In a FooConfig.cmake file there may be code like this to make the
Packit Service fa4841
# install destinations know to the using project:
Packit Service fa4841
#   set(FOO_INCLUDE_DIR   "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
Packit Service fa4841
#   set(FOO_DATA_DIR   "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
Packit Service fa4841
#   set(FOO_ICONS_DIR   "@CMAKE_INSTALL_PREFIX@/share/icons" )
Packit Service fa4841
#   ...logic to determine installedPrefix from the own location...
Packit Service fa4841
#   set(FOO_CONFIG_DIR  "${installedPrefix}/@CONFIG_INSTALL_DIR@" )
Packit Service fa4841
# All 4 options shown above are not sufficient, since the first 3 hardcode
Packit Service fa4841
# the absolute directory locations, and the 4th case works only if the logic
Packit Service fa4841
# to determine the installedPrefix is correct, and if CONFIG_INSTALL_DIR contains
Packit Service fa4841
# a relative path, which in general cannot be guaranteed.
Packit Service fa4841
# This has the effect that the resulting FooConfig.cmake file would work poorly
Packit Service fa4841
# under Windows and OSX, where users are used to choose the install location
Packit Service fa4841
# of a binary package at install time, independent from how CMAKE_INSTALL_PREFIX
Packit Service fa4841
# was set at build/cmake time.
Packit Service fa4841
#
Packit Service fa4841
# Using CONFIGURE_PACKAGE_CONFIG_FILE() helps. If used correctly, it makes the
Packit Service fa4841
# resulting FooConfig.cmake file relocatable.
Packit Service fa4841
# Usage:
Packit Service fa4841
#   1. write a FooConfig.cmake.in file as you are used to
Packit Service fa4841
#   2. insert a line containing only the string "@PACKAGE_INIT@"
Packit Service fa4841
#   3. instead of set(FOO_DIR "@SOME_INSTALL_DIR@"), use set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@")
Packit Service fa4841
#      (this must be after the @PACKAGE_INIT@ line)
Packit Service fa4841
#   4. instead of using the normal configure_file(), use CONFIGURE_PACKAGE_CONFIG_FILE()
Packit Service fa4841
#
Packit Service fa4841
# The <input> and <output> arguments are the input and output file, the same way
Packit Service fa4841
# as in configure_file().
Packit Service fa4841
#
Packit Service fa4841
# The <path> given to INSTALL_DESTINATION must be the destination where the FooConfig.cmake
Packit Service fa4841
# file will be installed to. This can either be a relative or absolute path, both work.
Packit Service fa4841
#
Packit Service fa4841
# The variables <var1> to <varN> given as PATH_VARS are the variables which contain
Packit Service fa4841
# install destinations. For each of them the macro will create a helper variable
Packit Service fa4841
# PACKAGE_<var...>. These helper variables must be used
Packit Service fa4841
# in the FooConfig.cmake.in file for setting the installed location. They are calculated
Packit Service fa4841
# by CONFIGURE_PACKAGE_CONFIG_FILE() so that they are always relative to the
Packit Service fa4841
# installed location of the package. This works both for relative and also for absolute locations.
Packit Service fa4841
# For absolute locations it works only if the absolute location is a subdirectory
Packit Service fa4841
# of CMAKE_INSTALL_PREFIX.
Packit Service fa4841
#
Packit Service fa4841
# By default configure_package_config_file() also generates two helper macros,
Packit Service fa4841
# set_and_check() and check_required_components() into the FooConfig.cmake file.
Packit Service fa4841
#
Packit Service fa4841
# set_and_check() should be used instead of the normal set()
Packit Service fa4841
# command for setting directories and file locations. Additionally to setting the
Packit Service fa4841
# variable it also checks that the referenced file or directory actually exists
Packit Service fa4841
# and fails with a FATAL_ERROR otherwise. This makes sure that the created
Packit Service fa4841
# FooConfig.cmake file does not contain wrong references.
Packit Service fa4841
# When using the NO_SET_AND_CHECK_MACRO, this macro is not generated into the
Packit Service fa4841
# FooConfig.cmake file.
Packit Service fa4841
#
Packit Service fa4841
# check_required_components(<package_name>) should be called at the end of the
Packit Service fa4841
# FooConfig.cmake file if the package supports components.
Packit Service fa4841
# This macro checks whether all requested, non-optional components have been found,
Packit Service fa4841
# and if this is not the case, sets the Foo_FOUND variable to FALSE, so that the package
Packit Service fa4841
# is considered to be not found.
Packit Service fa4841
# It does that by testing the Foo_<Component>_FOUND variables for all requested
Packit Service fa4841
# required components.
Packit Service fa4841
# When using the NO_CHECK_REQUIRED_COMPONENTS option, this macro is not generated
Packit Service fa4841
# into the FooConfig.cmake file.
Packit Service fa4841
#
Packit Service fa4841
# For an example see below the documentation for WRITE_BASIC_PACKAGE_VERSION_FILE().
Packit Service fa4841
#
Packit Service fa4841
#
Packit Service fa4841
#  WRITE_BASIC_PACKAGE_VERSION_FILE( filename VERSION major.minor.patch COMPATIBILITY (AnyNewerVersion|SameMajorVersion|ExactVersion) )
Packit Service fa4841
#
Packit Service fa4841
# Writes a file for use as <package>ConfigVersion.cmake file to <filename>.
Packit Service fa4841
# See the documentation of find_package() for details on this.
Packit Service fa4841
#    filename is the output filename, it should be in the build tree.
Packit Service fa4841
#    major.minor.patch is the version number of the project to be installed
Packit Service fa4841
# The COMPATIBILITY mode AnyNewerVersion means that the installed package version
Packit Service fa4841
# will be considered compatible if it is newer or exactly the same as the requested version.
Packit Service fa4841
# This mode should be used for packages which are fully backward compatible,
Packit Service fa4841
# also across major versions.
Packit Service fa4841
# If SameMajorVersion is used instead, then the behaviour differs from AnyNewerVersion
Packit Service fa4841
# in that the major version number must be the same as requested, e.g. version 2.0 will
Packit Service fa4841
# not be considered compatible if 1.0 is requested.
Packit Service fa4841
# This mode should be used for packages which guarantee backward compatibility within the
Packit Service fa4841
# same major version.
Packit Service fa4841
# If ExactVersion is used, then the package is only considered compatible if the requested
Packit Service fa4841
# version matches exactly its own version number (not considering the tweak version).
Packit Service fa4841
# For example, version 1.2.3 of a package is only considered compatible to requested version 1.2.3.
Packit Service fa4841
# This mode is for packages without compatibility guarantees.
Packit Service fa4841
# If your project has more elaborated version matching rules, you will need to write your
Packit Service fa4841
# own custom ConfigVersion.cmake file instead of using this macro.
Packit Service fa4841
#
Packit Service fa4841
# Internally, this macro executes configure_file() to create the resulting
Packit Service fa4841
# version file. Depending on the COMPATIBLITY, either the file
Packit Service fa4841
# BasicConfigVersion-SameMajorVersion.cmake.in or BasicConfigVersion-AnyNewerVersion.cmake.in
Packit Service fa4841
# is used. Please note that these two files are internal to CMake and you should
Packit Service fa4841
# not call configure_file() on them yourself, but they can be used as starting
Packit Service fa4841
# point to create more sophisticted custom ConfigVersion.cmake files.
Packit Service fa4841
#
Packit Service fa4841
#
Packit Service fa4841
# Example using both configure_package_config_file() and write_basic_package_version_file():
Packit Service fa4841
# CMakeLists.txt:
Packit Service fa4841
#   set(INCLUDE_INSTALL_DIR include/ ... CACHE )
Packit Service fa4841
#   set(LIB_INSTALL_DIR lib/ ... CACHE )
Packit Service fa4841
#   set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE )
Packit Service fa4841
#   ...
Packit Service fa4841
#   include(CMakePackageConfigHelpers)
Packit Service fa4841
#   configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake
Packit Service fa4841
#                                 INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake
Packit Service fa4841
#                                 PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
Packit Service fa4841
#   write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
Packit Service fa4841
#                                    VERSION 1.2.3
Packit Service fa4841
#                                    COMPATIBILITY SameMajorVersion )
Packit Service fa4841
#   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
Packit Service fa4841
#           DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake )
Packit Service fa4841
#
Packit Service fa4841
# With a FooConfig.cmake.in:
Packit Service fa4841
#   set(FOO_VERSION x.y.z)
Packit Service fa4841
#   ...
Packit Service fa4841
#   @PACKAGE_INIT@
Packit Service fa4841
#   ...
Packit Service fa4841
#   set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
Packit Service fa4841
#   set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@")
Packit Service fa4841
#
Packit Service fa4841
#   check_required_components(Foo)
Packit Service fa4841
Packit Service fa4841
Packit Service fa4841
#=============================================================================
Packit Service fa4841
# Copyright 2012 Alexander Neundorf <neundorf@kde.org>
Packit Service fa4841
#
Packit Service fa4841
# Distributed under the OSI-approved BSD License (the "License");
Packit Service fa4841
# see accompanying file Copyright.txt for details.
Packit Service fa4841
#
Packit Service fa4841
# This software is distributed WITHOUT ANY WARRANTY; without even the
Packit Service fa4841
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit Service fa4841
# See the License for more information.
Packit Service fa4841
#=============================================================================
Packit Service fa4841
# (To distribute this file outside of CMake, substitute the full
Packit Service fa4841
#  License text for the above reference.)
Packit Service fa4841
Packit Service fa4841
include(CMakeParseArguments)
Packit Service fa4841
Packit Service fa4841
include(WriteBasicConfigVersionFile)
Packit Service fa4841
Packit Service fa4841
macro(WRITE_BASIC_PACKAGE_VERSION_FILE)
Packit Service fa4841
  write_basic_config_version_file(${ARGN})
Packit Service fa4841
endmacro()
Packit Service fa4841
Packit Service fa4841
Packit Service fa4841
function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
Packit Service fa4841
  set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
Packit Service fa4841
  set(oneValueArgs INSTALL_DESTINATION )
Packit Service fa4841
  set(multiValueArgs PATH_VARS )
Packit Service fa4841
Packit Service fa4841
  cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}"  ${ARGN})
Packit Service fa4841
Packit Service fa4841
  if(CCF_UNPARSED_ARGUMENTS)
Packit Service fa4841
    message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"")
Packit Service fa4841
  endif()
Packit Service fa4841
Packit Service fa4841
  if(NOT CCF_INSTALL_DESTINATION)
Packit Service fa4841
    message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()")
Packit Service fa4841
  endif()
Packit Service fa4841
Packit Service fa4841
  if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}")
Packit Service fa4841
    set(absInstallDir "${CCF_INSTALL_DESTINATION}")
Packit Service fa4841
  else()
Packit Service fa4841
    set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}")
Packit Service fa4841
  endif()
Packit Service fa4841
Packit Service fa4841
  file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" )
Packit Service fa4841
Packit Service fa4841
  foreach(var ${CCF_PATH_VARS})
Packit Service fa4841
    if(NOT DEFINED ${var})
Packit Service fa4841
      message(FATAL_ERROR "Variable ${var} does not exist")
Packit Service fa4841
    else()
Packit Service fa4841
      if(IS_ABSOLUTE "${${var}}")
Packit Service fa4841
        string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}"
Packit Service fa4841
                        PACKAGE_${var} "${${var}}")
Packit Service fa4841
      else()
Packit Service fa4841
        set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
Packit Service fa4841
      endif()
Packit Service fa4841
    endif()
Packit Service fa4841
  endforeach()
Packit Service fa4841
Packit Service fa4841
  get_filename_component(inputFileName "${_inputFile}" NAME)
Packit Service fa4841
Packit Service fa4841
  set(PACKAGE_INIT "
Packit Service fa4841
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
Packit Service fa4841
####### Any changes to this file will be overwritten by the next CMake run ####
Packit Service fa4841
####### The input file was ${inputFileName}                            ########
Packit Service fa4841
Packit Service fa4841
get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
Packit Service fa4841
")
Packit Service fa4841
Packit Service fa4841
  if("${absInstallDir}" MATCHES "^(/usr)?/lib(64)?/.+")
Packit Service fa4841
    # Handle "/usr move" symlinks created by some Linux distros.
Packit Service fa4841
    set(PACKAGE_INIT "${PACKAGE_INIT}
Packit Service fa4841
# Use original install prefix when loaded through a \"/usr move\"
Packit Service fa4841
# cross-prefix symbolic link such as /lib -> /usr/lib.
Packit Service fa4841
get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH)
Packit Service fa4841
get_filename_component(_realOrig \"${absInstallDir}\" REALPATH)
Packit Service fa4841
if(_realCurr STREQUAL _realOrig)
Packit Service fa4841
  set(PACKAGE_PREFIX_DIR \"${CMAKE_INSTALL_PREFIX}\")
Packit Service fa4841
endif()
Packit Service fa4841
unset(_realOrig)
Packit Service fa4841
unset(_realCurr)
Packit Service fa4841
")
Packit Service fa4841
  endif()
Packit Service fa4841
Packit Service fa4841
  if(NOT CCF_NO_SET_AND_CHECK_MACRO)
Packit Service fa4841
    set(PACKAGE_INIT "${PACKAGE_INIT}
Packit Service fa4841
macro(set_and_check _var _file)
Packit Service fa4841
  set(\${_var} \"\${_file}\")
Packit Service fa4841
  if(NOT EXISTS \"\${_file}\")
Packit Service fa4841
    message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\")
Packit Service fa4841
  endif()
Packit Service fa4841
endmacro()
Packit Service fa4841
")
Packit Service fa4841
  endif()
Packit Service fa4841
Packit Service fa4841
Packit Service fa4841
  if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO)
Packit Service fa4841
    set(PACKAGE_INIT "${PACKAGE_INIT}
Packit Service fa4841
macro(check_required_components _NAME)
Packit Service fa4841
  foreach(comp \${\${_NAME}_FIND_COMPONENTS})
Packit Service fa4841
    if(NOT \${_NAME}_\${comp}_FOUND)
Packit Service fa4841
      if(\${_NAME}_FIND_REQUIRED_\${comp})
Packit Service fa4841
        set(\${_NAME}_FOUND FALSE)
Packit Service fa4841
      endif()
Packit Service fa4841
    endif()
Packit Service fa4841
  endforeach()
Packit Service fa4841
endmacro()
Packit Service fa4841
")
Packit Service fa4841
  endif()
Packit Service fa4841
Packit Service fa4841
  set(PACKAGE_INIT "${PACKAGE_INIT}
Packit Service fa4841
####################################################################################")
Packit Service fa4841
Packit Service fa4841
  configure_file("${_inputFile}" "${_outputFile}" @ONLY)
Packit Service fa4841
Packit Service fa4841
endfunction()