From dde5f41a12fcb89b86463014a205ae0c9b2b91f1 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 2 Dec 2021 15:08:35 -0700 Subject: [PATCH] Fix failing test for Config.cmake missing subpackage includes (#299) This sets _ENABLE_=ON if the subpackage is enabled even if optional packages are disabled. This will fix trilinos/Trilinos#9972 and trilinos/Trilinos#9973. This also updates the logic that generates Config.cmake files to only include Config.cmake files for direct dependencies, not all dependencies. (The indirect includes should take care of the rest.) --- .../TribitsExampleApp_Tests.cmake | 6 +++++ .../TribitsAdjustPackageEnables.cmake | 25 ++++++++++++++++++- .../TribitsWriteClientExportFiles.cmake | 13 +++++++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleApp_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleApp_Tests.cmake index eb9dd4669..247c63979 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleApp_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleApp_Tests.cmake @@ -469,6 +469,12 @@ function(TribitsExampleApp_NoOptionalPackages_test byProjectOrPackage sharedOrSt ${buildSharedLibsArg} -DCMAKE_INSTALL_PREFIX=${testDir}/install ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject + PASS_REGULAR_EXPRESSION_ALL + "-- Setting TribitsExProj_ENABLE_WithSubpackages=ON because TribitsExProj_ENABLE_WithSubpackagesA=ON" + "-- Setting WithSubpackages_ENABLE_WithSubpackagesA=ON because TribitsExProj_ENABLE_WithSubpackagesA=ON" + "-- Setting WithSubpackages_ENABLE_WithSubpackagesB=ON because TribitsExProj_ENABLE_WithSubpackagesB=ON" + "-- Setting WithSubpackages_ENABLE_WithSubpackagesC=ON because TribitsExProj_ENABLE_WithSubpackagesC=ON" + ALWAYS_FAIL_ON_NONZERO_RETURN TEST_1 MESSAGE "Build and install TribitsExampleProject locally" diff --git a/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake b/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake index a08508730..7db948b66 100644 --- a/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake +++ b/tribits/core/package_arch/TribitsAdjustPackageEnables.cmake @@ -57,6 +57,7 @@ include(MessageWrapper) include(DualScopeSet) include(CMakeParseArguments) + # # Private helper macros # @@ -314,7 +315,6 @@ macro(tribits_disable_parents_subpackages PARENT_PACKAGE_NAME) endmacro() -# # Macro that enables all of the subpackages of a parent package. # macro(tribits_enable_parents_subpackages PARENT_PACKAGE_NAME) @@ -698,6 +698,8 @@ macro(tribits_postprocess_package_with_subpackages_enables PACKAGE_NAME) "Setting ${PROJECT_NAME}_ENABLE_${PACKAGE_NAME}=ON" " because ${PROJECT_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}=ON") set(${PROJECT_NAME}_ENABLE_${PACKAGE_NAME} ON) + tribits_postprocess_package_with_subpackages_optional_subpackage_enables( + ${PACKAGE_NAME}) tribits_postprocess_package_with_subpackages_test_example_enables( ${PACKAGE_NAME} TESTS) tribits_postprocess_package_with_subpackages_test_example_enables( @@ -711,6 +713,27 @@ macro(tribits_postprocess_package_with_subpackages_enables PACKAGE_NAME) endmacro() +# Set _ENABLE_=ON if not already enabled for all +# subpackages of a parent package. +# +macro(tribits_postprocess_package_with_subpackages_optional_subpackage_enables + PACKAGE_NAME + ) + #message("TRIBITS_POSTPROCESS_PACKAGE_WITH_SUBPACKAGES_TEST_EXAMPLE_ENABLES '${PACKAGE_NAME}'") + foreach(TRIBITS_SUBPACKAGE ${${PACKAGE_NAME}_SUBPACKAGES}) + set(SUBPACKAGE_FULLNAME ${PACKAGE_NAME}${TRIBITS_SUBPACKAGE}) + if (${PROJECT_NAME}_ENABLE_${SUBPACKAGE_FULLNAME} + AND "${${PACKAGE_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}}" STREQUAL "" + ) + message("-- " + "Setting ${PACKAGE_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}=ON" + " because ${PROJECT_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}=ON") + set(${PACKAGE_NAME}_ENABLE_${SUBPACKAGE_FULLNAME} ON) + endif() + endforeach() +endmacro() + + # Set the parent package tests/examples enables if one subpackage is enabled # and has its tests/examples # diff --git a/tribits/core/package_arch/TribitsWriteClientExportFiles.cmake b/tribits/core/package_arch/TribitsWriteClientExportFiles.cmake index 767cc62e8..b7050f92d 100644 --- a/tribits/core/package_arch/TribitsWriteClientExportFiles.cmake +++ b/tribits/core/package_arch/TribitsWriteClientExportFiles.cmake @@ -537,10 +537,17 @@ function(tribits_append_dependent_package_config_file_includes packageName) # Include configurations of dependent packages string(APPEND configFileStr "# Include configuration of dependent packages\n") - foreach(depPkg IN LISTS ${packageName}_FULL_ENABLED_DEP_PACKAGES) - set(cmakePkgDir "${pkgConfigFileBaseDir}/${depPkg}") + foreach(depPkg IN LISTS ${packageName}_LIB_REQUIRED_DEP_PACKAGES) + set(cmakeTplDir "${pkgConfigFileBaseDir}/${depPkg}") string(APPEND configFileStr - "include(\"${cmakePkgDir}/${depPkg}Config.cmake\")\n") + "include(\"${cmakeTplDir}/${depPkg}Config.cmake\")\n") + endforeach() + foreach(depPkg IN LISTS ${packageName}_LIB_OPTIONAL_DEP_PACKAGES) + if (${packageName}_ENABLE_${depPkg}) + set(cmakeTplDir "${pkgConfigFileBaseDir}/${depPkg}") + string(APPEND configFileStr + "include(\"${cmakeTplDir}/${depPkg}Config.cmake\")\n") + endif() endforeach() # Include configurations of dependent external packages/TPLs