Skip to content

Commit

Permalink
WIP: Add failing test with call to tribits_disable_optional_dependency()
Browse files Browse the repository at this point in the history
This adds a failing test for the call of tribits_disable_optional_dependency()
discovered while testing the Trilinos PR trilinos/Trilinos#12291.

Some other changes as part of this:

* Add optional argument PACKAGE_NAME <packageName> to macro
  tribits_disable_optional_dependency() to allow the disable of a subpackage's
  dependency from its parent package's CMakeList.txt file.

* Added new function tribits_get_have_package_dependency_macro_name(...) to
  eliminate code duplication for the naming of the
  HAVE_<PACKAGE_NAME_UC>_<UPSTREAM_PACKAGE_UC> macro.
  • Loading branch information
bartlettroscoe committed Oct 9, 2023
1 parent 4be87d2 commit e16191e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ tribits_add_advanced_test( TribitsExampleProject_NoFortran_reduced_tarball
-DTribitsExProj_ENABLE_ALL_PACKAGES=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DTribitsExProj_ASSERT_DEFINED_DEPENDENCIES=WARNING
-DWithSubpackagesB_DISABLE_SUPPORT_FOR_MixedLang=ON
../tribitsexproj-1.1-Source
PASS_REGULAR_EXPRESSION_ALL
"CMake Warning at .*/tribits/core/package_arch/TribitsProcessPackagesAndDirsLists.cmake"
Expand Down
6 changes: 3 additions & 3 deletions tribits/core/package_arch/TribitsAdjustPackageEnables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include(TribitsPrintEnabledPackagesLists)
include(TribitsPrintDependencyInfo)
include(TribitsPackageDependencies)
include(TribitsGetPackageEnableStatus)
include(TribitsGetHavePackageDependencyMacroName)

include(AdvancedOption)
include(AdvancedSet)
Expand Down Expand Up @@ -1189,9 +1190,8 @@ macro(tribits_private_postprocess_optional_package_enable packageName optDepPk
"${optDepPkgEnable} is set!")
endif()

string(TOUPPER ${packageName} packageName_UPPER)
string(TOUPPER ${optDepPkg} optDepPkg_UPPER)
set(macroDefineName HAVE_${packageName_UPPER}_${optDepPkg_UPPER})
tribits_get_have_package_dependency_macro_name(${packageName} ${optDepPkg}
macroDefineName)

if(${packageName}_ENABLE_${optDepPkg})
set(${macroDefineName} ON)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function(tribits_get_have_package_dependency_macro_name packageName upstreamPackageName
haveDepMacroNameOut
)
string(TOUPPER ${packageName} packageName_UC)
string(TOUPPER ${upstreamPackageName} upstreamPackageName_UC)
set(haveDepMacroName
HAVE_${packageName_UC}_${upstreamPackageName_UC})
set(${haveDepMacroNameOut} ${haveDepMacroName} PARENT_SCOPE)
endfunction()
34 changes: 26 additions & 8 deletions tribits/core/package_arch/TribitsPackageMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ include(TribitsAddExecutable)
include(TribitsAddExecutableAndTest)
include(TribitsCopyFilesToBinaryDir)
include(TribitsReportInvalidTribitsUsage)
include(TribitsGetHavePackageDependencyMacroName)


#
Expand Down Expand Up @@ -415,19 +416,37 @@ endmacro()
#
# Usage::
#
# tribits_disable_optional_dependency(<upstreamPackageName> "<reasonStr>")
# tribits_disable_optional_dependency(<upstreamPackageName> "<reasonStr>"
# [PACKAGE_NAME <packageName>] )
#
# This macro can be called from a top-level package's
# ``<packageDir>/CMakeLists.txt`` file to disable an optional dependency that
# may have been enabled by the user or through automated enable/disable logic.
# This will disable the dependency of the package ``<packageName>`` on the
# upstream package ``<upstreamPackageName>``. If the argument ``PACKAGE_NAME
# <packageName>`` is missing, then ``<packageName>`` will be
# ``${PACKAGE_NAME}``.
#
# This macro can be called from the top-level package's
# ``<packageDir>/CMakeLists.txt`` file (or from a subpackages's parent
# top-level ``<packageDir>/CMakeLists.txt`` if ``<packageName>`` is the name
# of a subpackage) to disable an optional dependency that may have been
# enabled by the user or through automated enable/disable logic.
#
# This is most useful in cases where multiple criteria must be considered
# before support for some upstream dependency can really be supported. In
# that case, the dependency can be disabled in the current package and
# telegraphed to all downstream packages. See `How to tweak downstream
# TriBITS "ENABLE" variables during package configuration`_ for more details.
#
# NOTE: The constraint that this must be called from a top-level package's
# ``<packageDir>/CMakeLists.txt`` is because this macro sets non-cache
# variables at the base project-level scope.)
#
macro(tribits_disable_optional_dependency upstreamPackageName reasonStr)
cmake_parse_arguments(TDOD_PARSE "" "PACKAGE_NAME" "" ${ARGN})
if (TDOD_PARSE_PACKAGE_NAME)
set(tdod_packageName ${TDOD_PARSE_PACKAGE_NAME})
else()
set(tdod_packageName ${PACKAGE_NAME})
endif()
# Assert called in the correct context
if (NOT "${${PACKAGE_NAME}_PARENT_PACKAGE}" STREQUAL "")
message(FATAL_ERROR "ERROR: Calling tribits_disable_optional_dependency() from"
Expand All @@ -441,11 +460,10 @@ macro(tribits_disable_optional_dependency upstreamPackageName reasonStr)
" '${${PACKAGE_NAME}_SOURCE_DIR}/CMakeLists.txt'" )
endif()
# Get the variable names that are going to be set assert they exist already
set(packageEnableVarName ${PACKAGE_NAME}_ENABLE_${upstreamPackageName})
set(packageEnableVarName ${tdod_packageName}_ENABLE_${upstreamPackageName})
assert_defined(${packageEnableVarName})
string(TOUPPER ${upstreamPackageName} upstreamPackageName_UC)
set(havePackageUpstreamPackageMacroVarName
HAVE_${PACKAGE_NAME_UC}_${upstreamPackageName_UC})
tribits_get_have_package_dependency_macro_name(${tdod_packageName}
${upstreamPackageName} havePackageUpstreamPackageMacroVarName)
assert_defined(${havePackageUpstreamPackageMacroVarName})
# Set the variables to OFF in local and project-level scopes
if (NOT "${reasonStr}" STREQUAL "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ tribits_package_decl(WithSubpackages)

tribits_add_debug_option()

if (WithSubpackagesB_DISABLE_SUPPORT_FOR_MixedLang)
tribits_disable_optional_dependency(MixedLang
"WithSubpackagesB: Disabling support for MixedLang because WithSubpackagesB_DISABLE_SUPPORT_FOR_MixedLang='${WithSubpackagesB_DISABLE_SUPPORT_FOR_MixedLang}'!"
PACKAGE_NAME WithSubpackagesB)
endif()

tribits_process_subpackages()

tribits_exclude_files(
Expand Down

0 comments on commit e16191e

Please sign in to comment.