|
| 1 | +# CREATE_CONFIG_FILES(<packagename>) |
| 2 | +# Call this macro to generate CMake and pkg-config configuration |
| 3 | +# files from templates found in the top-level source directory. |
| 4 | +# |
| 5 | +# Most ARPA2-related components write configuration-information |
| 6 | +# files and install them. There are two flavors: |
| 7 | +# |
| 8 | +# - CMake config-info files (<foo>Config.cmake and <foo>ConfigVersion.cmake) |
| 9 | +# - pkg-config files (<foo>.pc) |
| 10 | +# |
| 11 | +# The macro create_config_files() simplifies this process |
| 12 | +# by using named template files for all three output files. |
| 13 | +# Pass a package name (e.g. "Quick-DER") to the macro, and |
| 14 | +# the source files (e.g. <file>.in for the files named above |
| 15 | +# will be taken from the top-level source directory. |
| 16 | +# |
| 17 | +# As an (un)special case, the ConfigVersion file may be taken from |
| 18 | +# the cmake/ directory, since there is nothing particularly special |
| 19 | +# for that file (as opposed to the other files, which need to |
| 20 | +# specify paths, dependencies, and other things). |
| 21 | + |
| 22 | +# Copyright 2017, Adriaan de Groot <groot@kde.org> |
| 23 | +# |
| 24 | +# Redistribution and use is allowed according to the terms of the two-clause BSD license. |
| 25 | +# https://opensource.org/licenses/BSD-2-Clause |
| 26 | +# SPDX short identifier: BSD-2-Clause |
| 27 | + |
| 28 | +macro (create_config_files _packagename) |
| 29 | + export (PACKAGE ${_packagename}) |
| 30 | + # The CMake configuration files are written to different locations |
| 31 | + # depending on the host platform, since different conventions apply. |
| 32 | + if (WIN32 AND NOT CYGWIN) |
| 33 | + set (DEF_INSTALL_CMAKE_DIR CMake) |
| 34 | + else () |
| 35 | + set (DEF_INSTALL_CMAKE_DIR lib/cmake/${_packagename}) |
| 36 | + endif () |
| 37 | + set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH |
| 38 | + "Installation directory for CMake files") |
| 39 | + |
| 40 | + # Calculate include/ relative to the installed place of the config file. |
| 41 | + file (RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" |
| 42 | + "${CMAKE_INSTALL_PREFIX}/include") |
| 43 | + set (CONF_INCLUDE_DIRS "\${${_packagename}_CMAKE_DIR}/${REL_INCLUDE_DIR}") |
| 44 | + # Substitute in real values for the placeholders in the .in files, |
| 45 | + # create the files in the build tree, and install them. |
| 46 | + configure_file (${PROJECT_SOURCE_DIR}/${_packagename}Config.cmake.in |
| 47 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}Config.cmake" @ONLY) |
| 48 | + set (_conf_version_filename ${PROJECT_SOURCE_DIR}/${_packagename}ConfigVersion.cmake.in) |
| 49 | + if (NOT EXISTS ${_conf_version_filename}) |
| 50 | + # (un)special-case: use the generic version-checking file, |
| 51 | + # assume ${_packagename}_VERSION exists and copy that to |
| 52 | + # the generic version-variable for this file. |
| 53 | + set (_conf_version_filename ${PROJECT_SOURCE_DIR}/cmake/ConfigVersion.cmake.in) |
| 54 | + set (_conf_version ${${_packagename}_VERSION}) |
| 55 | + endif () |
| 56 | + configure_file (${_conf_version_filename} |
| 57 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}ConfigVersion.cmake" @ONLY) |
| 58 | + configure_file (${PROJECT_SOURCE_DIR}/${_packagename}.pc.in |
| 59 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}.pc" @ONLY) |
| 60 | + |
| 61 | + install (FILES |
| 62 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}Config.cmake" |
| 63 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}ConfigVersion.cmake" |
| 64 | + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) |
| 65 | + install (FILES |
| 66 | + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}.pc" |
| 67 | + DESTINATION "lib/pkgconfig/") |
| 68 | +endmacro () |
0 commit comments