diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake index 651ba2f4f..aa4a7dc09 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake @@ -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" diff --git a/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake b/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake index 814533ea3..50457ddd6 100644 --- a/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake +++ b/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake @@ -45,6 +45,7 @@ include(TribitsPrintEnabledPackagesLists) include(TribitsPrintDependencyInfo) include(TribitsPackageDependencies) include(TribitsGetPackageEnableStatus) +include(TribitsGetHavePackageDependencyMacroName) include(AdvancedOption) include(AdvancedSet) @@ -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) diff --git a/tribits/core/package_arch/TribitsGetHavePackageDependencyMacroName.cmake b/tribits/core/package_arch/TribitsGetHavePackageDependencyMacroName.cmake new file mode 100644 index 000000000..cacc5a686 --- /dev/null +++ b/tribits/core/package_arch/TribitsGetHavePackageDependencyMacroName.cmake @@ -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() diff --git a/tribits/core/package_arch/TribitsPackageMacros.cmake b/tribits/core/package_arch/TribitsPackageMacros.cmake index d7931c406..e0c331182 100644 --- a/tribits/core/package_arch/TribitsPackageMacros.cmake +++ b/tribits/core/package_arch/TribitsPackageMacros.cmake @@ -61,6 +61,7 @@ include(TribitsAddExecutable) include(TribitsAddExecutableAndTest) include(TribitsCopyFilesToBinaryDir) include(TribitsReportInvalidTribitsUsage) +include(TribitsGetHavePackageDependencyMacroName) # @@ -415,11 +416,19 @@ endmacro() # # Usage:: # -# tribits_disable_optional_dependency( "") +# tribits_disable_optional_dependency( "" +# [PACKAGE_NAME ] ) # -# This macro can be called from a top-level package's -# ``/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 ```` on the +# upstream package ````. If the argument ``PACKAGE_NAME +# `` is missing, then ```` will be +# ``${PACKAGE_NAME}``. +# +# This macro can be called from the top-level package's +# ``/CMakeLists.txt`` file (or from a subpackages's parent +# top-level ``/CMakeLists.txt`` if ```` 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 @@ -427,7 +436,17 @@ endmacro() # 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 +# ``/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" @@ -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 "") diff --git a/tribits/examples/TribitsExampleProject/packages/with_subpackages/CMakeLists.txt b/tribits/examples/TribitsExampleProject/packages/with_subpackages/CMakeLists.txt index 53c3811ad..85a468caa 100644 --- a/tribits/examples/TribitsExampleProject/packages/with_subpackages/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject/packages/with_subpackages/CMakeLists.txt @@ -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(