| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
|
| 11 |
################################################################################ |
| 12 |
# |
| 13 |
# Module TribitsInternalPackageWriteConfigFile.cmake |
| 14 |
# |
| 15 |
# This module contains code for generating <Package>Config.cmake files for |
| 16 |
# internal TriBITS packages. |
| 17 |
# |
| 18 |
################################################################################ |
| 19 |
|
| 20 |
|
| 21 |
include(TribitsGeneralMacros) |
| 22 |
include(TribitsPkgExportCacheVars) |
| 23 |
include(TribitsWritePackageConfigFileHelpers) |
| 24 |
|
| 25 |
|
| 26 |
# Generate the ${PACKAGE_NAME}Config.cmake file for package PACKAGE_NAME. |
| 27 |
# |
| 28 |
# ToDo: Finish documentation! |
| 29 |
# |
| 30 |
function(tribits_write_package_client_export_files PACKAGE_NAME) |
| 31 |
|
| 32 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 33 |
message("\nTRIBITS_WRITE_PACKAGE_CLIENT_EXPORT_FILES: ${PACKAGE_NAME}") |
| 34 |
endif() |
| 35 |
|
| 36 |
set(buildDirCMakePkgsDir |
| 37 |
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR}") |
| 38 |
|
| 39 |
set(EXPORT_FILES_ARGS PACKAGE_NAME ${PACKAGE_NAME}) |
| 40 |
|
| 41 |
if (${PROJECT_NAME}_ENABLE_INSTALL_CMAKE_CONFIG_FILES) |
| 42 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 43 |
message("For package ${PACKAGE_NAME} creating ${PACKAGE_NAME}Config.cmake") |
| 44 |
endif() |
| 45 |
set(PACKAGE_CONFIG_FOR_BUILD_BASE_DIR |
| 46 |
"${buildDirCMakePkgsDir}/${PACKAGE_NAME}" ) |
| 47 |
set(PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR |
| 48 |
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles" ) |
| 49 |
append_set(EXPORT_FILES_ARGS |
| 50 |
PACKAGE_CONFIG_FOR_BUILD_BASE_DIR "${PACKAGE_CONFIG_FOR_BUILD_BASE_DIR}" |
| 51 |
PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR "${PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR}" |
| 52 |
) |
| 53 |
endif() |
| 54 |
|
| 55 |
tribits_write_flexible_package_client_export_files(${EXPORT_FILES_ARGS}) |
| 56 |
|
| 57 |
tribits_write_package_client_export_files_export_and_install_targets(${EXPORT_FILES_ARGS}) |
| 58 |
|
| 59 |
endfunction() |
| 60 |
|
| 61 |
|
| 62 |
# @FUNCTION: tribits_write_package_client_export_files_export_and_install_targets() |
| 63 |
# |
| 64 |
# Create the ``<Package>ConfigTargets.cmake`` file and install rules and the |
| 65 |
# install() target for the previously generated |
| 66 |
# ``<Package>Config_install.cmake`` files generated by the |
| 67 |
# `tribits_write_flexible_package_client_export_files()`_ function. |
| 68 |
# |
| 69 |
# Usage:: |
| 70 |
# |
| 71 |
# tribits_write_package_client_export_files_export_and_install_targets( |
| 72 |
# PACKAGE_NAME <packageName> |
| 73 |
# PACKAGE_CONFIG_FOR_BUILD_BASE_DIR <packageConfigForBuildBaseDir> |
| 74 |
# PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR <packageConfigForInstallBaseDir> |
| 75 |
# ) |
| 76 |
# |
| 77 |
# The install() commands must be in a different subroutine or CMake will not |
| 78 |
# allow you to call the routine, even if you if() it out! |
| 79 |
# |
| 80 |
function(tribits_write_package_client_export_files_export_and_install_targets) |
| 81 |
|
| 82 |
cmake_parse_arguments( |
| 83 |
#prefix |
| 84 |
PARSE |
| 85 |
#options |
| 86 |
"" |
| 87 |
#one_value_keywords |
| 88 |
"PACKAGE_NAME;PACKAGE_CONFIG_FOR_BUILD_BASE_DIR;PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR" |
| 89 |
#multi_value_keywords |
| 90 |
"" |
| 91 |
${ARGN} |
| 92 |
) |
| 93 |
|
| 94 |
set(PACKAGE_NAME ${PARSE_PACKAGE_NAME}) |
| 95 |
|
| 96 |
if (PARSE_PACKAGE_CONFIG_FOR_BUILD_BASE_DIR) |
| 97 |
tribits_get_package_config_build_dir_targets_file(${PACKAGE_NAME} |
| 98 |
"${PARSE_PACKAGE_CONFIG_FOR_BUILD_BASE_DIR}" packageConfigBuildDirTargetsFile ) |
| 99 |
export( |
| 100 |
EXPORT ${PACKAGE_NAME} |
| 101 |
NAMESPACE ${PACKAGE_NAME}:: |
| 102 |
FILE "${packageConfigBuildDirTargetsFile}" ) |
| 103 |
endif() |
| 104 |
|
| 105 |
if (PARSE_PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR) |
| 106 |
install( |
| 107 |
FILES |
| 108 |
"${PARSE_PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR}/${PACKAGE_NAME}Config_install.cmake" |
| 109 |
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${PACKAGE_NAME}" |
| 110 |
RENAME ${PACKAGE_NAME}Config.cmake |
| 111 |
) |
| 112 |
install( |
| 113 |
EXPORT ${PACKAGE_NAME} |
| 114 |
NAMESPACE ${PACKAGE_NAME}:: |
| 115 |
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${PACKAGE_NAME}" |
| 116 |
FILE "${PACKAGE_NAME}Targets.cmake" ) |
| 117 |
endif() |
| 118 |
|
| 119 |
endfunction() |
| 120 |
|
| 121 |
|
| 122 |
# @FUNCTION: tribits_generate_package_config_file_for_build_tree() |
| 123 |
# |
| 124 |
# Called from tribits_write_flexible_package_client_export_files() to finish |
| 125 |
# up generating text for and writing the file `<Package>Config.cmake` for the |
| 126 |
# build tree. |
| 127 |
# |
| 128 |
# Usage:: |
| 129 |
# |
| 130 |
# tribits_generate_package_config_file_for_build_tree( <packageName> |
| 131 |
# [EXPORT_FILE_VAR_PREFIX <exportFileVarPrefix>] |
| 132 |
# ) |
| 133 |
# |
| 134 |
# These files get placed under <buildDir>/cmake_packages/<packageName>/ |
| 135 |
# |
| 136 |
# That makes them easy to find by find_package() by adding |
| 137 |
# <buildDir>/cmake_packages/ to CMAKE_PREFIX_PATH. |
| 138 |
# |
| 139 |
function(tribits_generate_package_config_file_for_build_tree packageName) |
| 140 |
|
| 141 |
if (TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES_DEBUG_DUMP) |
| 142 |
message("tribits_generate_package_config_file_for_build_tree(${ARGV})") |
| 143 |
endif() |
| 144 |
|
| 145 |
cmake_parse_arguments( |
| 146 |
PARSE #prefix |
| 147 |
"" #options |
| 148 |
"EXPORT_FILE_VAR_PREFIX" #one_value_keywords |
| 149 |
"" #multi_value_keywords |
| 150 |
${ARGN} |
| 151 |
) |
| 152 |
|
| 153 |
if (PARSE_EXPORT_FILE_VAR_PREFIX) |
| 154 |
set(EXPORT_FILE_VAR_PREFIX ${PARSE_EXPORT_FILE_VAR_PREFIX}) |
| 155 |
else() |
| 156 |
set(EXPORT_FILE_VAR_PREFIX ${packageName}) |
| 157 |
endif() |
| 158 |
|
| 159 |
set(buildDirExtPkgsDir |
| 160 |
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}") |
| 161 |
set(buildDirCMakePkgsDir |
| 162 |
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR}") |
| 163 |
|
| 164 |
if (PARSE_PACKAGE_CONFIG_FOR_BUILD_BASE_DIR |
| 165 |
OR PARSE_PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR |
| 166 |
) |
| 167 |
# Custom code in configuration file (gets pulled from by configure_file() |
| 168 |
# below) |
| 169 |
set(PACKAGE_CONFIG_CODE "") |
| 170 |
|
| 171 |
tribits_append_dependent_package_config_file_includes_and_enables_str(${packageName} |
| 172 |
EXPORT_FILE_VAR_PREFIX ${EXPORT_FILE_VAR_PREFIX} |
| 173 |
EXT_PKG_CONFIG_FILE_BASE_DIR "${buildDirExtPkgsDir}" |
| 174 |
PKG_CONFIG_FILE_BASE_DIR "${buildDirCMakePkgsDir}" |
| 175 |
CONFIG_FILE_STR_INOUT PACKAGE_CONFIG_CODE ) |
| 176 |
|
| 177 |
# Import build tree targets into applications. |
| 178 |
# |
| 179 |
# BMA: Export only the immediate libraries of this project to the |
| 180 |
# build tree. Should manage more carefully, checking that they are |
| 181 |
# targets of this project and not other libs. Also, should |
| 182 |
# consider more careful recursive management of targets when there |
| 183 |
# are sub-packages. We'd like to export per-package, but deps |
| 184 |
# won't be satisfied, so we export one file for the project for |
| 185 |
# now... |
| 186 |
if (PARSE_PACKAGE_CONFIG_FOR_BUILD_BASE_DIR) |
| 187 |
tribits_get_package_config_build_dir_targets_file(${packageName} |
| 188 |
"${PACKAGE_CONFIG_FOR_BUILD_BASE_DIR}" packageConfigBuildDirTargetsFile ) |
| 189 |
string(APPEND PACKAGE_CONFIG_CODE |
| 190 |
"\n# Import ${packageName} targets\n" |
| 191 |
"include(\"${packageConfigBuildDirTargetsFile}\")\n") |
| 192 |
endif() |
| 193 |
|
| 194 |
tribits_extpkg_append_tribits_compliant_package_config_vars_str(${packageName} |
| 195 |
PACKAGE_CONFIG_CODE) |
| 196 |
|
| 197 |
tribits_set_compiler_vars_for_config_file(BUILD_DIR) |
| 198 |
|
| 199 |
if ("${CMAKE_CXX_FLAGS}" STREQUAL "") |
| 200 |
set(CMAKE_CXX_FLAGS_ESCAPED "") |
| 201 |
else() |
| 202 |
# Replace " by \". |
| 203 |
string(REGEX REPLACE "\"" "\\\\\"" CMAKE_CXX_FLAGS_ESCAPED ${CMAKE_CXX_FLAGS}) |
| 204 |
endif() |
| 205 |
|
| 206 |
# Used in configured file below |
| 207 |
set(EXPORTED_PACKAGE_LIBS_NAMES ${${packageName}_EXPORTED_PACKAGE_LIBS_NAMES}) |
| 208 |
set(PDOLLAR "$") |
| 209 |
|
| 210 |
set(tribitsConfigFilesDir |
| 211 |
"${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CMAKE_INSTALLATION_FILES_DIR}") |
| 212 |
configure_file( |
| 213 |
"${tribitsConfigFilesDir}/TribitsPackageConfigTemplate.cmake.in" |
| 214 |
"${PARSE_PACKAGE_CONFIG_FOR_BUILD_BASE_DIR}/${packageName}Config.cmake" |
| 215 |
) |
| 216 |
|
| 217 |
endif() |
| 218 |
|
| 219 |
endfunction() |
| 220 |
|
| 221 |
|
| 222 |
# @FUNCTION: tribits_generate_package_config_file_for_install_tree() |
| 223 |
# |
| 224 |
# Called from tribits_write_flexible_package_client_export_files() to finish |
| 225 |
# up generating text for and writing the file `<Package>Config_install.cmake` |
| 226 |
# that will get installed. |
| 227 |
# |
| 228 |
# Usage:: |
| 229 |
# |
| 230 |
# tribits_generate_package_config_file_for_install_tree( <packageName> |
| 231 |
# [EXPORT_FILE_VAR_PREFIX <exportFileVarPrefix>] |
| 232 |
# ) |
| 233 |
# |
| 234 |
# The export files are typically installed in |
| 235 |
# <install-dir>/<lib-path>/cmake/<package-name>/. |
| 236 |
# |
| 237 |
# This file isn't generally useful inside the build tree so it is being |
| 238 |
# "hidden" in the CMakeFiles directory. It gets installed in a separate |
| 239 |
# function. (NOTE: The install target is added in a different function to |
| 240 |
# allow this function to be unit tested in a cmake -P script.) |
| 241 |
# |
| 242 |
function(tribits_generate_package_config_file_for_install_tree packageName) |
| 243 |
|
| 244 |
if (TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES_DEBUG_DUMP) |
| 245 |
message("tribits_generate_package_config_file_for_install_tree(${ARGV})") |
| 246 |
endif() |
| 247 |
|
| 248 |
cmake_parse_arguments( |
| 249 |
PARSE #prefix |
| 250 |
"" #options |
| 251 |
"EXPORT_FILE_VAR_PREFIX" #one_value_keywords |
| 252 |
"" #multi_value_keywords |
| 253 |
${ARGN} |
| 254 |
) |
| 255 |
|
| 256 |
if (PARSE_EXPORT_FILE_VAR_PREFIX) |
| 257 |
set(EXPORT_FILE_VAR_PREFIX ${PARSE_EXPORT_FILE_VAR_PREFIX}) |
| 258 |
else() |
| 259 |
set(EXPORT_FILE_VAR_PREFIX ${packageName}) |
| 260 |
endif() |
| 261 |
|
| 262 |
# Custom code in configuration file. |
| 263 |
set(PACKAGE_CONFIG_CODE "") |
| 264 |
|
| 265 |
tribits_append_dependent_package_config_file_includes_and_enables_str(${packageName} |
| 266 |
EXPORT_FILE_VAR_PREFIX ${EXPORT_FILE_VAR_PREFIX} |
| 267 |
EXT_PKG_CONFIG_FILE_BASE_DIR |
| 268 |
"\${CMAKE_CURRENT_LIST_DIR}/../../${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}" |
| 269 |
PKG_CONFIG_FILE_BASE_DIR "\${CMAKE_CURRENT_LIST_DIR}/.." |
| 270 |
CONFIG_FILE_STR_INOUT PACKAGE_CONFIG_CODE ) |
| 271 |
|
| 272 |
# Import install targets |
| 273 |
string(APPEND PACKAGE_CONFIG_CODE |
| 274 |
"\n# Import ${packageName} targets\n" |
| 275 |
"include(\"\${CMAKE_CURRENT_LIST_DIR}/${packageName}Targets.cmake\")\n") |
| 276 |
|
| 277 |
tribits_extpkg_append_tribits_compliant_package_config_vars_str(${packageName} |
| 278 |
PACKAGE_CONFIG_CODE) |
| 279 |
|
| 280 |
# Write the specification of the rpath if necessary. This is only needed if |
| 281 |
# we're building shared libraries. |
| 282 |
if (BUILD_SHARED_LIBS) |
| 283 |
set(SHARED_LIB_RPATH_COMMAND |
| 284 |
${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}${CMAKE_INSTALL_PREFIX}/${${PROJECT_NAME}_INSTALL_LIB_DIR} |
| 285 |
) |
| 286 |
endif() |
| 287 |
|
| 288 |
tribits_set_compiler_vars_for_config_file(INSTALL_DIR) |
| 289 |
|
| 290 |
# Used in configure file below |
| 291 |
set(EXPORTED_PACKAGE_LIBS_NAMES ${${packageName}_EXPORTED_PACKAGE_LIBS_NAMES}) |
| 292 |
set(PDOLLAR "$") |
| 293 |
|
| 294 |
if (PARSE_PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR) |
| 295 |
configure_file( |
| 296 |
"${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CMAKE_INSTALLATION_FILES_DIR}/TribitsPackageConfigTemplate.cmake.in" |
| 297 |
"${PARSE_PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR}/${packageName}Config_install.cmake" |
| 298 |
) |
| 299 |
endif() |
| 300 |
|
| 301 |
endfunction() |
| 302 |
|
| 303 |
|
| 304 |
# @FUNCTION: tribits_write_flexible_package_client_export_files() |
| 305 |
# |
| 306 |
# Utility function for writing the ``${PACKAGE_NAME}Config.cmake`` files for |
| 307 |
# the build dir and/or for the install dir for the package ``<packageName>`` |
| 308 |
# with some flexibility . (See NOTE below for what is actually generated and |
| 309 |
# what is *NOT* generated.) |
| 310 |
# |
| 311 |
# Usage:: |
| 312 |
# |
| 313 |
# tribits_write_flexible_package_client_export_files( |
| 314 |
# PACKAGE_NAME <packageName> |
| 315 |
# [EXPORT_FILE_VAR_PREFIX <exportFileVarPrefix>] |
| 316 |
# [PACKAGE_CONFIG_FOR_BUILD_BASE_DIR <packageConfigForBuildBaseDir>] |
| 317 |
# [PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR <packageConfigForInstallBaseDir>] |
| 318 |
# ) |
| 319 |
# |
| 320 |
# The arguments are: |
| 321 |
# |
| 322 |
# ``PACKAGE_NAME <packageName>`` |
| 323 |
# |
| 324 |
# Gives the name of the TriBITS package for which the export files should |
| 325 |
# be created. (This must match the export set for the libraries for the |
| 326 |
# generated/exported ``<packageName>ConfigTargets.cmake`` file.) |
| 327 |
# |
| 328 |
# ``EXPORT_FILE_VAR_PREFIX <exportFileVarPrefix>`` |
| 329 |
# |
| 330 |
# If specified, then all of the variables in the generated export files |
| 331 |
# will be prefixed with ``<exportFileVarPrefix>_`` instead of |
| 332 |
# ``<packageName>_``. |
| 333 |
# |
| 334 |
# ``PACKAGE_CONFIG_FOR_BUILD_BASE_DIR <packageConfigForBuildBaseDir>`` |
| 335 |
# |
| 336 |
# If specified, then the package's ``<packageName>Config.cmake`` file will |
| 337 |
# be written under the directory ``<packageConfigForBuildBaseDir>/`` (and |
| 338 |
# any subdirs that do not exist will be created). The generated file |
| 339 |
# ``<packageName>Config.cmake`` is for usage of the package in the build |
| 340 |
# tree (not the install tree) and points to include directories and |
| 341 |
# libraries in the build tree. (NOTE: The included |
| 342 |
# ``<packageName>Targets.cmake`` file is *NOT* generated in this |
| 343 |
# function.) |
| 344 |
# |
| 345 |
# ``PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR <packageConfigForInstallBaseDir>`` |
| 346 |
# |
| 347 |
# If specified, then the package's ``<packageName>Config_install.cmake`` |
| 348 |
# file will be written under the directory |
| 349 |
# ``<packageConfigForInstallBaseDir>/`` (and any subdirs that do not exist |
| 350 |
# will be created). The file ``${PACKAGE_NAME}Config_install.cmake`` is |
| 351 |
# meant to be installed renamed as ``<packageName>Config.cmake`` in the |
| 352 |
# install tree and it points to installed include directories and |
| 353 |
# libraries. (NOTE: The included ``<packageName>Targets.cmake`` |
| 354 |
# file is *NOT* generated in this function.) |
| 355 |
# |
| 356 |
# NOTE: This function does *not* generate the ``<packageName>Config.cmake`` |
| 357 |
# files (which will be created later using ``export()`` or ``include()`) which |
| 358 |
# are included in these generated package config files and this function. |
| 359 |
# Also, this function does *not* invoke the ``install()`` command to install |
| 360 |
# the package config file for the install directory. The ``export()`` and |
| 361 |
# ``install()`` project commands are bot allowed in `cmake -P` scripting mode |
| 362 |
# that is used for unit testing this function. Instead, the commands to |
| 363 |
# generate the ``<packageName>Targets.cmake`` files and install the package |
| 364 |
# config file for the install tree are produced by the function |
| 365 |
# ``tribits_write_package_client_export_files_export_and_install_targets()`` |
| 366 |
# which is called after this function. This allows this function |
| 367 |
# ``tribits_write_package_client_export_files()`` to be run in unit testing |
| 368 |
# with a `cmake -P` script. |
| 369 |
# |
| 370 |
function(tribits_write_flexible_package_client_export_files) |
| 371 |
|
| 372 |
if (TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES_DEBUG_DUMP) |
| 373 |
message("\ntribits_write_flexible_package_client_export_files(${ARGN})") |
| 374 |
endif() |
| 375 |
|
| 376 |
# |
| 377 |
# A) Process the command-line arguments |
| 378 |
# |
| 379 |
|
| 380 |
cmake_parse_arguments( |
| 381 |
#prefix |
| 382 |
PARSE |
| 383 |
#options |
| 384 |
"WRITE_INSTALL_CMAKE_CONFIG_FILE" |
| 385 |
#one_value_keywords |
| 386 |
"PACKAGE_NAME;EXPORT_FILE_VAR_PREFIX;PACKAGE_CONFIG_FOR_BUILD_BASE_DIR;PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR" |
| 387 |
#multi_value_keywords |
| 388 |
"" |
| 389 |
${ARGN} |
| 390 |
) |
| 391 |
|
| 392 |
tribits_check_for_unparsed_arguments() |
| 393 |
|
| 394 |
if (NOT ${PROJECT_NAME}_GENERATE_EXPORT_FILE_DEPENDENCIES) |
| 395 |
message(SEND_ERROR "Error: Can't generate export dependency files because" |
| 396 |
" ${PROJECT_NAME}_GENERATE_EXPORT_FILE_DEPENDENCIES is not ON!") |
| 397 |
return() |
| 398 |
endif() |
| 399 |
|
| 400 |
set(PACKAGE_NAME ${PARSE_PACKAGE_NAME}) |
| 401 |
if (TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES_DEBUG_DUMP) |
| 402 |
print_var(PACKAGE_NAME) |
| 403 |
endif() |
| 404 |
|
| 405 |
set(EXPORT_FILE_VAR_PREFIX ${PACKAGE_NAME}) |
| 406 |
if (PARSE_EXPORT_FILE_VAR_PREFIX) |
| 407 |
set(EXPORT_FILE_VAR_PREFIX ${PARSE_EXPORT_FILE_VAR_PREFIX}) |
| 408 |
endif() |
| 409 |
if (TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES_DEBUG_DUMP) |
| 410 |
print_var(EXPORT_FILE_VAR_PREFIX) |
| 411 |
endif() |
| 412 |
|
| 413 |
# Generate a note discouraging editing of the <package>Config.cmake file |
| 414 |
set(DISCOURAGE_EDITING "Do not edit: This file was generated automatically by CMake.") |
| 415 |
|
| 416 |
# |
| 417 |
# B) Deal with the library rpath issues with shared libs |
| 418 |
# |
| 419 |
|
| 420 |
# Write the specification of the rpath if necessary. This is only needed if |
| 421 |
# we're building shared libraries. |
| 422 |
|
| 423 |
if(BUILD_SHARED_LIBS) |
| 424 |
string(REPLACE ";" ":" SHARED_LIB_RPATH_COMMAND "${FULL_LIBRARY_DIRS_SET}") |
| 425 |
set(SHARED_LIB_RPATH_COMMAND |
| 426 |
${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}${SHARED_LIB_RPATH_COMMAND}) |
| 427 |
endif() |
| 428 |
|
| 429 |
# |
| 430 |
# C) Create the contents of the <Package>Config.cmake file for the build tree |
| 431 |
# |
| 432 |
|
| 433 |
tribits_generate_package_config_file_for_build_tree(${PACKAGE_NAME} |
| 434 |
EXPORT_FILE_VAR_PREFIX ${EXPORT_FILE_VAR_PREFIX}) |
| 435 |
|
| 436 |
# |
| 437 |
# D) Create <Package>Config_install.cmake file for the install tree |
| 438 |
# |
| 439 |
|
| 440 |
tribits_generate_package_config_file_for_install_tree(${PACKAGE_NAME} |
| 441 |
EXPORT_FILE_VAR_PREFIX ${EXPORT_FILE_VAR_PREFIX}) |
| 442 |
|
| 443 |
endfunction() |
| 444 |
|
| 445 |
|
| 446 |
# @FUNCTION: tribits_append_dependent_package_config_file_includes_and_enables_str() |
| 447 |
# |
| 448 |
# Append the includes for upstream external packages (TPLs) and internal |
| 449 |
# packages as well as the enables/disables for upstream dependencies to an |
| 450 |
# output `<Package>Config.cmake` file string. |
| 451 |
# |
| 452 |
# Usage:: |
| 453 |
# |
| 454 |
# tribits_append_dependent_package_config_file_includes_and_enables_str( |
| 455 |
# <packageName> |
| 456 |
# EXPORT_FILE_VAR_PREFIX <exportFileVarPrefix> |
| 457 |
# EXT_PKG_CONFIG_FILE_BASE_DIR <extPkgconfigFileBaseDir> |
| 458 |
# PKG_CONFIG_FILE_BASE_DIR <pkgConfigFileBaseDir> |
| 459 |
# CONFIG_FILE_STR_INOUT <configFileStrInOut> |
| 460 |
# ) |
| 461 |
# |
| 462 |
function(tribits_append_dependent_package_config_file_includes_and_enables_str packageName) |
| 463 |
|
| 464 |
if (TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES_DEBUG_DUMP) |
| 465 |
message("tribits_append_dependent_package_config_file_includes_and_enables_str(${ARGV})") |
| 466 |
endif() |
| 467 |
|
| 468 |
# Parse input |
| 469 |
|
| 470 |
cmake_parse_arguments( |
| 471 |
PARSE "" # prefix, options |
| 472 |
#one_value_keywords |
| 473 |
"EXPORT_FILE_VAR_PREFIX;EXT_PKG_CONFIG_FILE_BASE_DIR;PKG_CONFIG_FILE_BASE_DIR;CONFIG_FILE_STR_INOUT" |
| 474 |
"" #multi_value_keywords |
| 475 |
${ARGN} |
| 476 |
) |
| 477 |
tribits_check_for_unparsed_arguments() |
| 478 |
|
| 479 |
if (PARSE_EXPORT_FILE_VAR_PREFIX) |
| 480 |
set(EXPORT_FILE_VAR_PREFIX ${PARSE_EXPORT_FILE_VAR_PREFIX}) |
| 481 |
else() |
| 482 |
set(EXPORT_FILE_VAR_PREFIX ${packageName}) |
| 483 |
endif() |
| 484 |
|
| 485 |
set(extPkgConfigFileBaseDir "${PARSE_EXT_PKG_CONFIG_FILE_BASE_DIR}") |
| 486 |
set(pkgConfigFileBaseDir "${PARSE_PKG_CONFIG_FILE_BASE_DIR}") |
| 487 |
set(configFileStr "${${PARSE_CONFIG_FILE_STR_INOUT}}") |
| 488 |
|
| 489 |
# Add set of enables/disables for all upstream dependencies |
| 490 |
string(APPEND configFileStr |
| 491 |
"# Enables/Disables for upstream package dependencies\n") |
| 492 |
foreach(depPkg IN LISTS ${packageName}_LIB_DEFINED_DEPENDENCIES) |
| 493 |
if (${packageName}_ENABLE_${depPkg}) |
| 494 |
set(enableVal ON) |
| 495 |
else() |
| 496 |
set(enableVal OFF) |
| 497 |
endif() |
| 498 |
string(APPEND configFileStr |
| 499 |
"set(${EXPORT_FILE_VAR_PREFIX}_ENABLE_${depPkg} ${enableVal})\n") |
| 500 |
endforeach() |
| 501 |
|
| 502 |
# Put in set() statements for exported cache vars |
| 503 |
string(APPEND configFileStr |
| 504 |
"\n# Exported cache variables\n") |
| 505 |
tribits_pkg_append_set_commands_for_exported_vars(${packageName} configFileStr) |
| 506 |
|
| 507 |
# Include configurations of dependent packages |
| 508 |
string(APPEND configFileStr |
| 509 |
"\n# Include configuration of dependent packages\n") |
| 510 |
set(DOLLAR "$") |
| 511 |
set(externalPkgsDir |
| 512 |
"${DOLLAR}{CMAKE_CURRENT_LIST_DIR}/../../${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}") |
| 513 |
foreach(depPkg IN LISTS ${packageName}_LIB_ENABLED_DEPENDENCIES) |
| 514 |
set(findDepPkgCode "") # Start out not including anything |
| 515 |
if (${depPkg}_PACKAGE_BUILD_STATUS STREQUAL "INTERNAL") |
| 516 |
set(findDepPkgCode |
| 517 |
" include(\"${DOLLAR}{CMAKE_CURRENT_LIST_DIR}/../${depPkg}/${depPkg}Config.cmake\")\n") |
| 518 |
elseif (${depPkg}_PACKAGE_BUILD_STATUS STREQUAL "EXTERNAL") |
| 519 |
if (NOT "${${depPkg}_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR}" STREQUAL "") |
| 520 |
set(findDepPkgCode |
| 521 |
" include(\"${${depPkg}_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR}/${depPkg}Config.cmake\")\n") |
| 522 |
elseif (${depPkg}_FINDMOD STREQUAL "TRIBITS_PKG") |
| 523 |
assert_defined(${depPkg}_CONFIG) |
| 524 |
string(APPEND findDepPkgCode |
| 525 |
" include(\"${${depPkg}_CONFIG}\")\n" |
| 526 |
" set(${depPkg}_CONFIG \"${${depPkg}_CONFIG}\")\n") |
| 527 |
else() |
| 528 |
set(findDepPkgCode |
| 529 |
" include(\"${externalPkgsDir}/${depPkg}/${depPkg}Config.cmake\")\n") |
| 530 |
endif() |
| 531 |
else() |
| 532 |
message(FATAL_ERROR "ERROR:" |
| 533 |
" ${depPkg}_PACKAGE_BUILD_STATUS='${${depPkg}_PACKAGE_BUILD_STATUS}' invalid!") |
| 534 |
endif() |
| 535 |
if (findDepPkgCode) |
| 536 |
string(APPEND configFileStr |
| 537 |
"if (NOT TARGET ${depPkg}::all_libs)\n" |
| 538 |
"${findDepPkgCode}" |
| 539 |
"endif()\n" |
| 540 |
) |
| 541 |
endif() |
| 542 |
endforeach() |
| 543 |
|
| 544 |
# Set the output |
| 545 |
set(${PARSE_CONFIG_FILE_STR_INOUT} "${configFileStr}" PARENT_SCOPE) |
| 546 |
|
| 547 |
endfunction() |
| 548 |
|
| 549 |
|
| 550 |
# Function to return the full path the targets file for the |
| 551 |
# <Package>Config.cmake file in the build tree. |
| 552 |
# |
| 553 |
function(tribits_get_package_config_build_dir_targets_file PACKAGE_NAME |
| 554 |
packageConfigForBuildBaseDir packageConfigBuildDirTargetsFileOut |
| 555 |
) |
| 556 |
set(${packageConfigBuildDirTargetsFileOut} |
| 557 |
"${PACKAGE_CONFIG_FOR_BUILD_BASE_DIR}/${PACKAGE_NAME}Targets.cmake" |
| 558 |
PARENT_SCOPE ) |
| 559 |
endfunction() |
| 560 |
|
| 561 |
|
| 562 |
macro(tribits_set_compiler_var_for_config_file LANG FOR_DIR) |
| 563 |
if (NOT "${CMAKE_${LANG}_COMPILER_FOR_CONFIG_FILE_${FOR_DIR}}" STREQUAL "") |
| 564 |
set(CMAKE_${LANG}_COMPILER_FOR_CONFIG_FILE |
| 565 |
"${CMAKE_${LANG}_COMPILER_FOR_CONFIG_FILE_${FOR_DIR}}") |
| 566 |
else() |
| 567 |
set(CMAKE_${LANG}_COMPILER_FOR_CONFIG_FILE |
| 568 |
"${CMAKE_${LANG}_COMPILER}") |
| 569 |
endif() |
| 570 |
#message("${FOR_DIR}: CMAKE_${LANG}_COMPILER_FOR_CONFIG_FILE='${CMAKE_${LANG}_COMPILER_FOR_CONFIG_FILE}'") |
| 571 |
endmacro() |
| 572 |
|
| 573 |
|
| 574 |
macro(tribits_set_compiler_vars_for_config_file FOR_DIR) |
| 575 |
tribits_set_compiler_var_for_config_file(CXX ${FOR_DIR}) |
| 576 |
tribits_set_compiler_var_for_config_file(C ${FOR_DIR}) |
| 577 |
tribits_set_compiler_var_for_config_file(Fortran ${FOR_DIR}) |
| 578 |
endmacro() |