| 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 |
# @FUNCTION: tribits_get_package_enable_status() |
| 12 |
# |
| 13 |
# Function that determines a given external or internal package's enable |
| 14 |
# status (e.g. 'ON' or 'OFF' or any valid CMake bool) |
| 15 |
# |
| 16 |
# Usage:: |
| 17 |
# |
| 18 |
# tribits_get_package_enable_status(<packageName> <packageEnableOut> |
| 19 |
# <packageEnableVarNameOut>) |
| 20 |
# |
| 21 |
# On return, if non-empty, the variable ``<packageEnableOut>`` will contain |
| 22 |
# the actual value of ``${${PROJECT_NAME}_ENABLE_<packageName>}`` or |
| 23 |
# ``${TPL_ENABLE_<packageName>}`` or will return empty "". If |
| 24 |
# ``${packageName}_PACKAGE_BUILD_STATUS == "INTERNAL"``, then only the value |
| 25 |
# of ``${PROJECT_NAME}_ENABLE_<packageName>`` will be considered. |
| 26 |
# |
| 27 |
# On return, if non-empty, the variable ``<packageEnableVarNameOut>`` will be |
| 28 |
# either ``${${PROJECT_NAME}_ENABLE_<packageName>}`` or |
| 29 |
# ``${TPL_ENABLE_<packageName>}``, depending on which one is used to obtain |
| 30 |
# the value ``<packageEnableOut>``. |
| 31 |
# |
| 32 |
# This works for both external packages/TPLs and internal packages. |
| 33 |
# |
| 34 |
function(tribits_get_package_enable_status packageName packageEnableOut |
| 35 |
packageEnableVarNameOut |
| 36 |
) |
| 37 |
tribits_get_package_enable_status_assert_args("${packageName}" |
| 38 |
"${packageEnableOut}" "${packageEnableVarNameOut}") |
| 39 |
tribits_assert_package_enable_status(${packageName}) |
| 40 |
# Determine which variable, if any, to extract enable status from |
| 41 |
set(packageEnableVarName "") |
| 42 |
if (NOT "${${PROJECT_NAME}_ENABLE_${packageName}}" STREQUAL "") |
| 43 |
set(packageEnableVarName ${PROJECT_NAME}_ENABLE_${packageName}) |
| 44 |
elseif (NOT "${TPL_ENABLE_${packageName}}" STREQUAL "") |
| 45 |
set(packageEnableVarName TPL_ENABLE_${packageName}) |
| 46 |
elseif (${packageName}_PACKAGE_BUILD_STATUS STREQUAL "INTERNAL") |
| 47 |
set(packageEnableVarName ${PROJECT_NAME}_ENABLE_${packageName}) |
| 48 |
elseif (${packageName}_PACKAGE_BUILD_STATUS STREQUAL "EXTERNAL") |
| 49 |
set(packageEnableVarName TPL_ENABLE_${packageName}) |
| 50 |
else() |
| 51 |
message(FATAL_ERROR "Could not determine status of package ${packageName}") |
| 52 |
endif() |
| 53 |
# Extract the enable status, set output args |
| 54 |
set(packageEnable ${${packageEnableVarName}}) |
| 55 |
if (packageEnableOut) |
| 56 |
set(${packageEnableOut} ${packageEnable} PARENT_SCOPE) |
| 57 |
endif() |
| 58 |
if (packageEnableVarNameOut) |
| 59 |
set(${packageEnableVarNameOut} ${packageEnableVarName} PARENT_SCOPE) |
| 60 |
endif() |
| 61 |
endfunction() |
| 62 |
|
| 63 |
|
| 64 |
# @FUNCTION: tribits_package_is_enabled_or_unset() |
| 65 |
# |
| 66 |
# Function that determines if a package's enable variable evaluates to true or |
| 67 |
# is unset. |
| 68 |
# |
| 69 |
# Usage:: |
| 70 |
# |
| 71 |
# tribits_package_is_enabled_or_unset((<packageEnableVarName> |
| 72 |
# <packageIsEnabledOrUnsetOut>) |
| 73 |
# |
| 74 |
# On return, the value of ``<packageIsEnabledOrUnsetOut>`` will set to |
| 75 |
# ``TRUE`` if the variable ``<packageEnableVarName>`` evaluates to true and |
| 76 |
# or is empty "". Otherwise, ``<packageIsEnabledOrUnsetOut>`` will set |
| 77 |
# to ``FALSE`` on return. |
| 78 |
# |
| 79 |
function(tribits_package_is_enabled_or_unset packageEnableVarName |
| 80 |
packageIsEnabledOrUnsetOut |
| 81 |
) |
| 82 |
if (${packageEnableVarName} OR ("${${packageEnableVarName}}" STREQUAL "")) |
| 83 |
set(packageIsEnabledOrUnset TRUE) |
| 84 |
else() |
| 85 |
set(packageIsEnabledOrUnset FALSE) |
| 86 |
endif() |
| 87 |
set(${packageIsEnabledOrUnsetOut} ${packageIsEnabledOrUnset} |
| 88 |
PARENT_SCOPE) |
| 89 |
endfunction() |
| 90 |
|
| 91 |
|
| 92 |
# @FUNCTION: tribits_package_is_explicitly_disabled() |
| 93 |
# |
| 94 |
# Function that determines if a package's enable variable is |
| 95 |
# explicitly disabled (i.e. evaluates to false but is not emapty). |
| 96 |
# |
| 97 |
# Usage:: |
| 98 |
# |
| 99 |
# tribits_package_is_explicitly_disabled((<packageEnableVarName> |
| 100 |
# <packageIsExplicitlyDisabledOut>) |
| 101 |
# |
| 102 |
# On return, the value of ``<packageIsExplicitlyDisabledOut>`` will set to |
| 103 |
# ``TRUE`` if the variable ``<packageEnableVarName>`` evaluates to false and |
| 104 |
# is not empty "". Otherwise, ``<packageIsExplicitlyDisabledOut>`` will set |
| 105 |
# to ``FALSE`` on return. |
| 106 |
# |
| 107 |
function(tribits_package_is_explicitly_disabled packageEnableVarName |
| 108 |
packageIsExplicitlyDisabledOut |
| 109 |
) |
| 110 |
if ((NOT ${packageEnableVarName}) AND (NOT "${${packageEnableVarName}}" STREQUAL "")) |
| 111 |
set(packageIsExplicitlyDisabled TRUE) |
| 112 |
else() |
| 113 |
set(packageIsExplicitlyDisabled FALSE) |
| 114 |
endif() |
| 115 |
set(${packageIsExplicitlyDisabledOut} ${packageIsExplicitlyDisabled} |
| 116 |
PARENT_SCOPE) |
| 117 |
endfunction() |
| 118 |
|
| 119 |
|
| 120 |
# @FUNCTION: tribits_assert_package_enable_status() |
| 121 |
# |
| 122 |
# Function that asserts that if both ``${PROJECT_NAME}_ENABLE_${packageName}`` |
| 123 |
# and ``TPL_ENABLE_${packageName}`` are both set to non-empty, then they must |
| 124 |
# be the same value or this is an error. |
| 125 |
# |
| 126 |
# Usage:: |
| 127 |
# |
| 128 |
# tribits_assert_package_enable_status(<packageName>) |
| 129 |
# |
| 130 |
function(tribits_assert_package_enable_status packageName) |
| 131 |
if ( (NOT "${${PROJECT_NAME}_ENABLE_${packageName}}" STREQUAL "") |
| 132 |
AND (NOT "${TPL_ENABLE_${packageName}}" STREQUAL "") |
| 133 |
AND (NOT "${${PROJECT_NAME}_ENABLE_${packageName}}" STREQUAL |
| 134 |
"${TPL_ENABLE_${packageName}}") |
| 135 |
) |
| 136 |
message(SEND_ERROR "Error, ${PROJECT_NAME}_ENABLE_${packageName}=" |
| 137 |
"'${${PROJECT_NAME}_ENABLE_${packageName}}' !=" |
| 138 |
" TPL_ENABLE_${packageName} = '${TPL_ENABLE_${packageName}}'") |
| 139 |
endif() |
| 140 |
endfunction() |
| 141 |
# ToDo: Create a cache var for the mode of message() above in case the user |
| 142 |
# wants to disable the warning. |
| 143 |
|
| 144 |
|
| 145 |
function(tribits_get_package_enable_status_assert_args packageName packageEnableOut |
| 146 |
packageEnableVarNameOut |
| 147 |
) |
| 148 |
if ("${packageName}" STREQUAL "") |
| 149 |
message(FATAL_ERROR "Error, packageName='' is not allowed!") |
| 150 |
endif() |
| 151 |
if ("${packageEnableOut}" STREQUAL "" AND "${packageEnableVarNameOut}" STREQUAL "") |
| 152 |
message(FATAL_ERROR "Error, both packageEnableOut='' and" |
| 153 |
" packageEnableVarNameOut='' is not allowed!") |
| 154 |
endif() |
| 155 |
endfunction() |