1 # ============================================================================ 2 # Copyright (c) 2011-2012 University of Pennsylvania 3 # Copyright (c) 2013-2016 Andreas Schuh 6 # See COPYING file for license information or visit 7 # https://cmake-basis.github.io/download.html#license 8 # ============================================================================ 10 ############################################################################## 11 # @file GenerateConfig.cmake 12 # @brief Generates package configuration files. 14 # This CMake script configures the \<package\>Config.cmake et al. files, 15 # once for the build tree and once for the install tree. Variables with a 16 # _CONFIG suffix are replaced in the default template file by either the 17 # value for the build or the install tree, respectively. 19 # If present, this script includes the @c PROJECT_CONFIG_DIR/ConfigBuild.cmake 20 # and/or @c PROJECT_CONFIG_DIR/ConfigInstall.cmake file before configuring the 21 # Config.cmake.in template. If a file @c PROJECT_CONFIG_DIR/Config.cmake.in 22 # exists, it is used as template. Otherwise, the default template file is used. 24 # Similarly, if the file @c PROJECT_CONFIG_DIR/ConfigVersion.cmake.in exists, 25 # it is used as template for the \<package\>ConfigVersion.cmake file. The same 26 # applies to ConfigUse.cmake.in. 29 ############################################################################## 33 # ============================================================================ 34 # names of output files 35 # ============================================================================ 37 # Attention: This has to be done before configuring any files such that these 38 # variables can be used by the template files. 40 ## @addtogroup CMakeUtilities 44 ## @brief Package name. 46 ## @brief Name of the CMake package configuration file.
48 ## @brief Name of the CMake package version file. 50 ## @brief Name of the CMake package use file.
52 ## @brief Name of the CMake target exports file. 54 ## @brief Name of the CMake target exports file
for custom targets.
59 # end of Doxygen group 61 # ============================================================================ 62 # export build targets 63 # ============================================================================ 67 FILE "${EXPORTS_FILE}" 68 CUSTOM_FILE
"${CUSTOM_EXPORTS_FILE}" 72 # ============================================================================ 74 # ============================================================================ 76 # code used at top of package configuration and use files to set package 77 # namespace prefix used for configuration variables 79 "# prefix used for variable names 80 set (NS \"${PROJECT_CONFIG_PREFIX}_\") 82 # allow caller to change namespace - used by projects with modules 83 if (\${NS}CONFIG_PREFIX) 84 set (NS \"\${\${NS}CONFIG_PREFIX}_\") 88 # ============================================================================
89 # project configuration file
90 # ============================================================================
92 # ----------------------------------------------------------------------------
95 if (EXISTS
"${PROJECT_CONFIG_DIR}/Config.cmake.in")
96 set (
TEMPLATE "${PROJECT_CONFIG_DIR}/Config.cmake.in")
97 elseif (PROJECT_IS_MODULE OR PROJECT_IS_SUBMODULE OR PROJECT_IS_SUBPROJECT)
98 set (
TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/ModuleConfig.cmake.in")
100 set (
TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in")
103 # ---------------------------------------------------------------------------- 104 # provide code of BASIS config file as variable 106 if (NOT
TEMPLATE MATCHES
"^${CMAKE_CURRENT_LIST_DIR_RE}/")
107 if (PROJECT_IS_MODULE OR PROJECT_IS_SUBMODULE OR PROJECT_IS_SUBPROJECT)
108 file (READ
"${CMAKE_CURRENT_LIST_DIR}/ModuleConfig.cmake.in" BASIS_TEMPLATE)
110 file (READ
"${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in" BASIS_TEMPLATE)
113 string (REGEX REPLACE
"^########.*########" "" BASIS_TEMPLATE "${BASIS_TEMPLATE}")
119 # ---------------------------------------------------------------------------- 120 # build tree related configuration 123 include (
"${CMAKE_CURRENT_LIST_DIR}/BasisConfigSettings.cmake")
124 include (
"${PROJECT_CONFIG_DIR}/ConfigSettings.cmake" OPTIONAL)
126 # ---------------------------------------------------------------------------- 127 # configure project configuration file for build tree 129 string (CONFIGURE
"${BASIS_TEMPLATE}" BASIS_CONFIG @ONLY)
130 configure_file (
"${TEMPLATE}" "${BINARY_LIBCONF_DIR}/${CONFIG_FILE}" @ONLY)
134 # -------------------------------------------------------------------------- 135 # install tree related configuration 138 include (
"${CMAKE_CURRENT_LIST_DIR}/BasisConfigSettings.cmake")
139 include (
"${PROJECT_CONFIG_DIR}/ConfigSettings.cmake" OPTIONAL)
141 # -------------------------------------------------------------------------- 142 # configure project configuration file for install tree 144 string (CONFIGURE
"${BASIS_TEMPLATE}" BASIS_CONFIG @ONLY)
145 configure_file (
"${TEMPLATE}" "${BINARY_CONFIG_DIR}/${CONFIG_FILE}" @ONLY)
147 # -------------------------------------------------------------------------- 148 # install project configuration file 151 FILES
"${BINARY_CONFIG_DIR}/${CONFIG_FILE}" 152 DESTINATION
"${INSTALL_CONFIG_DIR}" 157 # ============================================================================ 158 # project version file 159 # ============================================================================ 160 if (NOT PROJECT_IS_SUBMODULE)
162 # -------------------------------------------------------------------------- 165 if (EXISTS
"${PROJECT_CONFIG_DIR}/ConfigVersion.cmake.in")
166 set (
TEMPLATE "${PROJECT_CONFIG_DIR}/ConfigVersion.cmake.in")
168 set (
TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/ConfigVersion.cmake.in")
171 # -------------------------------------------------------------------------- 172 # configure project configuration version file 174 configure_file (
"${TEMPLATE}" "${BINARY_LIBCONF_DIR}/${VERSION_FILE}" @ONLY)
176 # -------------------------------------------------------------------------- 177 # install project configuration version file 181 FILES
"${BINARY_LIBCONF_DIR}/${VERSION_FILE}" 182 DESTINATION
"${INSTALL_CONFIG_DIR}" 187 # ============================================================================ 189 # ============================================================================ 191 # ---------------------------------------------------------------------------- 194 if (EXISTS
"${PROJECT_CONFIG_DIR}/ConfigUse.cmake.in")
195 set (
TEMPLATE "${PROJECT_CONFIG_DIR}/ConfigUse.cmake.in")
196 elseif (EXISTS
"${PROJECT_CONFIG_DIR}/Use.cmake.in")
197 # backwards compatibility to version <= 0.1.8 of BASIS 198 set (
TEMPLATE "${PROJECT_CONFIG_DIR}/Use.cmake.in")
199 elseif (PROJECT_IS_MODULE OR PROJECT_IS_SUBMODULE OR PROJECT_IS_SUBPROJECT)
200 set (
TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/ModuleConfigUse.cmake.in")
202 set (
TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/ConfigUse.cmake.in")
205 # ---------------------------------------------------------------------------- 206 # provide code of BASIS use file as variable 207 if (NOT
TEMPLATE MATCHES
"^${CMAKE_CURRENT_LIST_DIR_RE}/")
208 if (PROJECT_IS_MODULE OR PROJECT_IS_SUBMODULE OR PROJECT_IS_SUBPROJECT)
209 file (READ
"${CMAKE_CURRENT_LIST_DIR}/ModuleConfigUse.cmake.in" BASIS_USE)
211 file (READ
"${CMAKE_CURRENT_LIST_DIR}/ConfigUse.cmake.in" BASIS_USE)
214 string (REGEX REPLACE
"^########.*########" "" BASIS_USE "${BASIS_USE}")
220 # ---------------------------------------------------------------------------- 221 # configure project use file 223 string (CONFIGURE
"${BASIS_USE}" BASIS_USE @ONLY)
224 configure_file (
"${TEMPLATE}" "${BINARY_LIBCONF_DIR}/${USE_FILE}" @ONLY)
226 # ---------------------------------------------------------------------------- 227 # install project use file 229 if (NOT BASIS_BUILD_ONLY)
231 FILES
"${BINARY_LIBCONF_DIR}/${USE_FILE}" 232 DESTINATION
"${INSTALL_CONFIG_DIR}" 240 unset (CMAKE_CURRENT_LIST_DIR_RE)
cmake EXPORTS_FILE
Name of the CMake target exports file.
cmake USE_FILE
Name of the CMake package use file.
macro basis_sanitize_for_regex(out OUT, in STR)
Sanitize string variable for use in regular expression.
function basis_export_targets()
Export all targets added by basis_add_* commands.
cmake BUILD_CONFIG_SETTINGS
cmake CONFIG_FILE
Name of the CMake package configuration file.
cmake BASIS_EXPORT_ENABLED
Whether to create "<Package><ExportSuffix>.cmake" file so other projects can import the exported targ...
cmake CONFIG_PREFIX
Package name.
cmake VERSION_FILE
Name of the CMake package version file.
option BASIS_BUILD_ONLY
Request configuration of software build only, skipping steps related to packaging and installation...
cmake CUSTOM_EXPORTS_FILE
Name of the CMake target exports file for custom targets.