From 5d4e5b2dd10214cf8e421856c4eb71736e560ff5 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 30 Aug 2024 16:08:01 -0600 Subject: [PATCH] Add new function tribits_package_is_enabled_or_unset() This helps to make the code more clear. NOTE: This is tested as part of higher-level code and tests (e.g. DependencyUnitTests tests). --- .../TribitsAdjustPackageEnables.cmake | 4 ++- .../TribitsGetPackageEnableStatus.cmake | 28 +++++++++++++++++++ .../TribitsMacroFunctionDocTemplate.rst | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake b/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake index cf4ab88af..f43490eac 100644 --- a/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake +++ b/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake @@ -945,7 +945,9 @@ macro(tribits_private_disable_required_package_enables fwdDepPkgName packageName libraryDep ) tribits_get_package_enable_status(${fwdDepPkgName} "" fwdDepPkgEnableVarName) - if (${fwdDepPkgEnableVarName} OR "${${fwdDepPkgEnableVarName}}" STREQUAL "") + tribits_package_is_enabled_or_unset(${fwdDepPkgEnableVarName} + fwdDepPkgIsEnabledOrUnset) + if (fwdDepPkgIsEnabledOrUnset) if ("${libraryDep}" STREQUAL "TRUE") tribits_private_print_disable_required_package_enable( ${packageName} ${fwdDepPkgEnableVarName} diff --git a/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake b/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake index aaa3bf827..062c44c35 100644 --- a/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake +++ b/tribits/core/package_arch/TribitsGetPackageEnableStatus.cmake @@ -61,6 +61,34 @@ function(tribits_get_package_enable_status packageName packageEnableOut endfunction() +# @FUNCTION: tribits_package_is_enabled_or_unset() +# +# Function that determines if a package's enable variable evaluates to true or +# is unset. +# +# Usage:: +# +# tribits_package_is_enabled_or_unset(( +# ) +# +# On return, the value of ```` will set to +# ``TRUE`` if the variable ```` evaluates to true and +# or is empty "". Otherwise, ```` will set +# to ``FALSE`` on return. +# +function(tribits_package_is_enabled_or_unset packageEnableVarName + packageIsEnabledOrUnsetOut + ) + if (${packageEnableVarName} OR ("${${packageEnableVarName}}" STREQUAL "")) + set(packageIsEnabledOrUnset TRUE) + else() + set(packageIsEnabledOrUnset FALSE) + endif() + set(${packageIsEnabledOrUnsetOut} ${packageIsEnabledOrUnset} + PARENT_SCOPE) +endfunction() + + # @FUNCTION: tribits_package_is_explicitly_disabled() # # Function that determines if a package's enable variable is diff --git a/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst b/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst index c6b1e4768..1546777bf 100644 --- a/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst +++ b/tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst @@ -40,6 +40,7 @@ @MACRO: tribits_package_def() + @MACRO: tribits_package_define_dependencies() + @MACRO: tribits_process_enabled_standard_tpl() + +@FUNCTION: tribits_package_is_enabled_or_unset() + @FUNCTION: tribits_package_is_explicitly_disabled() + @MACRO: tribits_package_postprocess() + @MACRO: tribits_process_subpackages() +