| 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 |
# @MACRO: tribits_pkg_export_cache_var() |
| 12 |
# |
| 13 |
# Macro that registers a package-level cache var to be exported in the |
| 14 |
# ``<Package>Config.cmake`` file |
| 15 |
# |
| 16 |
# Usage:: |
| 17 |
# |
| 18 |
# tribits_pkg_export_cache_var(<cacheVarName>) |
| 19 |
# |
| 20 |
# where ``<cacheVarName>`` must be the name of a cache variable (or an error |
| 21 |
# will occur). |
| 22 |
# |
| 23 |
# NOTE: This will also export this variable to the |
| 24 |
# ``<Package><Spkg>Config.cmake`` file for every enabled subpackage (if this |
| 25 |
# is called from a ``CMakeLists.txt`` file of a top-level package that has |
| 26 |
# subpackages). That way, any top-level package cache vars are provided by |
| 27 |
# any of the subpackages' ``<Package><Spkg>Config.cmake`` files. |
| 28 |
# |
| 29 |
macro(tribits_pkg_export_cache_var cacheVarName) |
| 30 |
if (DEFINED ${PACKAGE_NAME}_PKG_VARS_TO_EXPORT) |
| 31 |
# Assert this is a cache var |
| 32 |
get_property(cacheVarIsCacheVar CACHE ${cacheVarName} PROPERTY VALUE SET) |
| 33 |
if (NOT cacheVarIsCacheVar) |
| 34 |
message(SEND_ERROR |
| 35 |
"ERROR: The variable ${cacheVarName} is NOT a cache var and cannot" |
| 36 |
" be exported!") |
| 37 |
endif() |
| 38 |
# Add to the list of package cache vars to export |
| 39 |
append_global_set(${PACKAGE_NAME}_PKG_VARS_TO_EXPORT |
| 40 |
${cacheVarName}) |
| 41 |
endif() |
| 42 |
endmacro() |
| 43 |
|
| 44 |
|
| 45 |
# @MACRO: tribits_assert_cache_and_local_vars_same_value() |
| 46 |
# |
| 47 |
# Asset that a cache variable and a possible local variable (if it exists) |
| 48 |
# have the same value. |
| 49 |
# |
| 50 |
# Usage:: |
| 51 |
# |
| 52 |
# tribits_assert_cache_and_local_vars_same_value(<cacheVarName>) |
| 53 |
# |
| 54 |
# If the local var ``<cacheVarName>`` and the cache var ``<cacheVarName>`` |
| 55 |
# both exist but have different values, then ``message(SEND_ERROR ...)`` is |
| 56 |
# called with an informative error message. |
| 57 |
# |
| 58 |
macro(tribits_assert_cache_and_local_vars_same_value cacheVarName) |
| 59 |
set(cacheVarValue "$CACHE{${cacheVarName}}") |
| 60 |
set(localValue "${${cacheVarName}}") |
| 61 |
if (NOT localValue STREQUAL cacheVarValue) |
| 62 |
message_wrapper(SEND_ERROR "ERROR: The cache variable ${cacheVarName} with the" |
| 63 |
" cache var value '${cacheVarValue}' is not the same value as the local" |
| 64 |
" variable ${cacheVarName} with value '${localValue}'!") |
| 65 |
endif() |
| 66 |
endmacro() |
| 67 |
|
| 68 |
|
| 69 |
# Function that sets up data-structures for package-level cache var to be |
| 70 |
# exported |
| 71 |
# |
| 72 |
function(tribits_pkg_init_exported_vars PACKAGE_NAME_IN) |
| 73 |
global_set(${PACKAGE_NAME_IN}_PKG_VARS_TO_EXPORT "") |
| 74 |
endfunction() |
| 75 |
|
| 76 |
|
| 77 |
# Function that injects set() statements for a package's exported cache vars into |
| 78 |
# a string. |
| 79 |
# |
| 80 |
# This is used to create set() statements to be injected into a package's |
| 81 |
# ``<Package>Config.cmake`` file. |
| 82 |
# |
| 83 |
function(tribits_pkg_append_set_commands_for_exported_vars packageName |
| 84 |
configFileStrInOut |
| 85 |
) |
| 86 |
set(configFileStr "${${configFileStrInOut}}") |
| 87 |
if (NOT "${${packageName}_PARENT_PACKAGE}" STREQUAL "") |
| 88 |
foreach(exportedCacheVar IN LISTS ${${packageName}_PARENT_PACKAGE}_PKG_VARS_TO_EXPORT) |
| 89 |
tribits_assert_cache_and_local_vars_same_value(${exportedCacheVar}) |
| 90 |
string(APPEND configFileStr |
| 91 |
"set(${exportedCacheVar} \"${${exportedCacheVar}}\")\n") |
| 92 |
endforeach() |
| 93 |
endif() |
| 94 |
foreach(exportedCacheVar IN LISTS ${packageName}_PKG_VARS_TO_EXPORT) |
| 95 |
#tribits_assert_cache_and_local_vars_same_value(${exportedCacheVar}) |
| 96 |
string(APPEND configFileStr |
| 97 |
"set(${exportedCacheVar} \"${${exportedCacheVar}}\")\n") |
| 98 |
endforeach() |
| 99 |
set(${configFileStrInOut} "${configFileStr}" PARENT_SCOPE) |
| 100 |
endfunction() |