浏览代码

GenEx: Collect evaluation arguments into local Context structures

Brad King 1 月之前
父节点
当前提交
d4d204382f

+ 6 - 4
Source/cmCommonTargetGenerator.cxx

@@ -11,6 +11,7 @@
 #include <cmext/string_view>
 
 #include "cmComputeLinkInformation.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmGeneratorTarget.h"
@@ -521,13 +522,14 @@ std::string cmCommonTargetGenerator::GetLinkerLauncher(
   std::string propName = lang + "_LINKER_LAUNCHER";
   cmValue launcherProp = this->GeneratorTarget->GetProperty(propName);
   if (cmNonempty(launcherProp)) {
+    cm::GenEx::Context context(this->LocalCommonGenerator, config, lang);
     cmGeneratorExpressionDAGChecker dagChecker{
-      this->GeneratorTarget,      propName, nullptr, nullptr,
-      this->LocalCommonGenerator, config,
+      this->GeneratorTarget, propName, nullptr, nullptr, context.LG,
+      context.Config
     };
     std::string evaluatedLinklauncher = cmGeneratorExpression::Evaluate(
-      *launcherProp, this->LocalCommonGenerator, config, this->GeneratorTarget,
-      &dagChecker, this->GeneratorTarget, lang);
+      *launcherProp, context.LG, context.Config, this->GeneratorTarget,
+      &dagChecker, this->GeneratorTarget, context.Language);
     // Convert ;-delimited list to single string
     cmList args{ evaluatedLinklauncher, cmList::EmptyElements::Yes };
     if (!args.empty()) {

+ 18 - 15
Source/cmComputeLinkDepends.cxx

@@ -19,6 +19,7 @@
 #include "cmsys/RegularExpression.hxx"
 
 #include "cmComputeComponentGraph.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmGeneratorTarget.h"
@@ -599,29 +600,31 @@ std::string const& cmComputeLinkDepends::LinkEntry::DEFAULT =
   cmLinkItem::DEFAULT;
 
 cmComputeLinkDepends::cmComputeLinkDepends(cmGeneratorTarget const* target,
-                                           std::string const& config,
-                                           std::string const& linkLanguage,
+                                           std::string config,
+                                           std::string linkLanguage,
                                            LinkLibrariesStrategy strategy)
   : Target(target)
   , Makefile(this->Target->Target->GetMakefile())
   , GlobalGenerator(this->Target->GetLocalGenerator()->GetGlobalGenerator())
   , CMakeInstance(this->GlobalGenerator->GetCMakeInstance())
-  , Config(config)
+  , Config(std::move(config))
   , DebugMode(this->Makefile->IsOn("CMAKE_LINK_DEPENDS_DEBUG_MODE") ||
               this->Target->GetProperty("LINK_DEPENDS_DEBUG_MODE").IsOn())
-  , LinkLanguage(linkLanguage)
+  , LinkLanguage(std::move(linkLanguage))
   , LinkType(ComputeLinkType(
       this->Config, this->Makefile->GetCMakeInstance()->GetDebugConfigs()))
   , Strategy(strategy)
 
 {
+  cm::GenEx::Context context(this->Target->LocalGenerator, this->Config,
+                             this->LinkLanguage);
   // target oriented feature override property takes precedence over
   // global override property
   cm::string_view lloPrefix = "LINK_LIBRARY_OVERRIDE_"_s;
   auto const& keys = this->Target->GetPropertyKeys();
   std::for_each(
     keys.cbegin(), keys.cend(),
-    [this, &lloPrefix, &config, &linkLanguage](std::string const& key) {
+    [this, &lloPrefix, &context](std::string const& key) {
       if (cmHasPrefix(key, lloPrefix)) {
         if (cmValue feature = this->Target->GetProperty(key)) {
           if (!feature->empty() && key.length() > lloPrefix.length()) {
@@ -631,13 +634,13 @@ cmComputeLinkDepends::cmComputeLinkDepends(cmGeneratorTarget const* target,
               "LINK_LIBRARY_OVERRIDE",
               nullptr,
               nullptr,
-              this->Target->GetLocalGenerator(),
-              config,
+              context.LG,
+              context.Config,
               this->Target->GetBacktrace(),
             };
             auto overrideFeature = cmGeneratorExpression::Evaluate(
-              *feature, this->Target->GetLocalGenerator(), config,
-              this->Target, &dagChecker, this->Target, linkLanguage);
+              *feature, context.LG, context.Config, this->Target, &dagChecker,
+              this->Target, context.Language);
             this->LinkLibraryOverride.emplace(item, overrideFeature);
           }
         }
@@ -647,17 +650,17 @@ cmComputeLinkDepends::cmComputeLinkDepends(cmGeneratorTarget const* target,
   if (cmValue linkLibraryOverride =
         this->Target->GetProperty("LINK_LIBRARY_OVERRIDE")) {
     cmGeneratorExpressionDAGChecker dagChecker{
-      target,
+      this->Target,
       "LINK_LIBRARY_OVERRIDE",
       nullptr,
       nullptr,
-      target->GetLocalGenerator(),
-      config,
-      target->GetBacktrace(),
+      context.LG,
+      context.Config,
+      this->Target->GetBacktrace(),
     };
     auto overrideValue = cmGeneratorExpression::Evaluate(
-      *linkLibraryOverride, target->GetLocalGenerator(), config, target,
-      &dagChecker, target, linkLanguage);
+      *linkLibraryOverride, context.LG, context.Config, this->Target,
+      &dagChecker, this->Target, context.Language);
 
     std::vector<std::string> overrideList =
       cmTokenize(overrideValue, ',', cmTokenizerMode::New);

+ 2 - 3
Source/cmComputeLinkDepends.h

@@ -39,9 +39,8 @@ enum class LinkLibrariesStrategy
 class cmComputeLinkDepends
 {
 public:
-  cmComputeLinkDepends(cmGeneratorTarget const* target,
-                       std::string const& config,
-                       std::string const& linkLanguage,
+  cmComputeLinkDepends(cmGeneratorTarget const* target, std::string config,
+                       std::string linkLanguage,
                        LinkLibrariesStrategy strategy);
   ~cmComputeLinkDepends();
 

+ 4 - 2
Source/cmDyndepCollation.cxx

@@ -20,6 +20,7 @@
 #include "cmExportBuildFileGenerator.h"
 #include "cmExportSet.h"
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h" // IWYU pragma: keep
 #include "cmGeneratorTarget.h"
@@ -50,6 +51,7 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt,
                                           std::string const& config,
                                           cmDyndepGeneratorCallbacks const& cb)
 {
+  cm::GenEx::Context const context(gt->LocalGenerator, config);
   TdiSourceInfo info;
   cmTarget const* tgt = gt->Target;
   auto all_file_sets = tgt->GetAllFileSetNames();
@@ -109,11 +111,11 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt,
     auto directoryEntries = file_set->CompileDirectoryEntries();
 
     auto directories = file_set->EvaluateDirectoryEntries(
-      directoryEntries, gt->LocalGenerator, config, gt);
+      directoryEntries, context.LG, context.Config, gt);
     std::map<std::string, std::vector<std::string>> files_per_dirs;
     for (auto const& entry : fileEntries) {
       file_set->EvaluateFileEntry(directories, files_per_dirs, entry,
-                                  gt->LocalGenerator, config, gt);
+                                  context.LG, context.Config, gt);
     }
 
     Json::Value fs_dest = Json::nullValue;

+ 7 - 4
Source/cmExportBuildCMakeConfigGenerator.cxx

@@ -17,6 +17,7 @@
 #include "cmCryptoHash.h"
 #include "cmExportSet.h"
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
@@ -176,8 +177,9 @@ std::string cmExportBuildCMakeConfigGenerator::GetFileSetDirectories(
   auto directoryEntries = fileSet->CompileDirectoryEntries();
 
   for (auto const& config : configs) {
+    cm::GenEx::Context context(gte->LocalGenerator, config);
     auto directories = fileSet->EvaluateDirectoryEntries(
-      directoryEntries, gte->LocalGenerator, config, gte);
+      directoryEntries, context.LG, context.Config, gte);
 
     bool const contextSensitive =
       std::any_of(directoryEntries.begin(), directoryEntries.end(),
@@ -226,13 +228,14 @@ std::string cmExportBuildCMakeConfigGenerator::GetFileSetFiles(
   auto directoryEntries = fileSet->CompileDirectoryEntries();
 
   for (auto const& config : configs) {
+    cm::GenEx::Context context(gte->LocalGenerator, config);
     auto directories = fileSet->EvaluateDirectoryEntries(
-      directoryEntries, gte->LocalGenerator, config, gte);
+      directoryEntries, context.LG, context.Config, gte);
 
     std::map<std::string, std::vector<std::string>> files;
     for (auto const& entry : fileEntries) {
-      fileSet->EvaluateFileEntry(directories, files, entry,
-                                 gte->LocalGenerator, config, gte);
+      fileSet->EvaluateFileEntry(directories, files, entry, context.LG,
+                                 context.Config, gte);
     }
 
     bool const contextSensitive =

+ 5 - 3
Source/cmExportInstallCMakeConfigGenerator.cxx

@@ -16,6 +16,7 @@
 #include "cmExportFileGenerator.h"
 #include "cmExportSet.h"
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
@@ -339,13 +340,14 @@ std::string cmExportInstallCMakeConfigGenerator::GetFileSetFiles(
     te->FileSetGenerators.at(fileSet->GetName())->GetDestination());
 
   for (auto const& config : configs) {
+    cm::GenEx::Context context(gte->LocalGenerator, config);
     auto directories = fileSet->EvaluateDirectoryEntries(
-      directoryEntries, gte->LocalGenerator, config, gte);
+      directoryEntries, context.LG, context.Config, gte);
 
     std::map<std::string, std::vector<std::string>> files;
     for (auto const& entry : fileEntries) {
-      fileSet->EvaluateFileEntry(directories, files, entry,
-                                 gte->LocalGenerator, config, gte);
+      fileSet->EvaluateFileEntry(directories, files, entry, context.LG,
+                                 context.Config, gte);
     }
     auto unescapedDest = destCge->Evaluate(gte->LocalGenerator, config, gte);
     auto dest =

+ 7 - 10
Source/cmExportTryCompileFileGenerator.cxx

@@ -9,6 +9,7 @@
 #include <cm/string_view>
 
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmGeneratorTarget.h"
@@ -76,6 +77,8 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
     return std::string();
   }
 
+  cm::GenEx::Context context(tgt->LocalGenerator, this->Config, language);
+
   cmGeneratorExpression ge(*tgt->Makefile->GetCMakeInstance());
 
   std::unique_ptr<cmGeneratorExpressionDAGChecker> parentDagChecker;
@@ -83,16 +86,10 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
     // To please constraint checks of DAGChecker, this property must have
     // LINK_OPTIONS property as parent
     parentDagChecker = cm::make_unique<cmGeneratorExpressionDAGChecker>(
-      tgt, "LINK_OPTIONS", nullptr, nullptr, tgt->GetLocalGenerator(),
-      this->Config);
+      tgt, "LINK_OPTIONS", nullptr, nullptr, context.LG, context.Config);
   }
   cmGeneratorExpressionDAGChecker dagChecker{
-    tgt,
-    propName,
-    nullptr,
-    parentDagChecker.get(),
-    tgt->GetLocalGenerator(),
-    this->Config,
+    tgt, propName, nullptr, parentDagChecker.get(), context.LG, context.Config,
   };
 
   std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*prop);
@@ -103,8 +100,8 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
 
   cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
 
-  std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
-                                     &gDummyHead, &dagChecker, tgt, language);
+  std::string result = cge->Evaluate(context.LG, context.Config, &gDummyHead,
+                                     &dagChecker, tgt, context.Language);
 
   std::set<cmGeneratorTarget const*> const& allTargets =
     cge->GetAllTargetsSeen();

+ 12 - 9
Source/cmFileAPICodemodel.cxx

@@ -24,6 +24,7 @@
 #include "cmExportSet.h"
 #include "cmFileAPI.h"
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
@@ -1080,16 +1081,17 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen)
 
     auto* target = installFileSet->GetTarget();
 
+    cm::GenEx::Context context(target->LocalGenerator, this->Config);
+
     auto dirCges = fileSet->CompileDirectoryEntries();
-    auto dirs = fileSet->EvaluateDirectoryEntries(
-      dirCges, target->GetLocalGenerator(), this->Config, target);
+    auto dirs = fileSet->EvaluateDirectoryEntries(dirCges, context.LG,
+                                                  context.Config, target);
 
     auto entryCges = fileSet->CompileFileEntries();
     std::map<std::string, std::vector<std::string>> entries;
     for (auto const& entryCge : entryCges) {
-      fileSet->EvaluateFileEntry(dirs, entries, entryCge,
-                                 target->GetLocalGenerator(), this->Config,
-                                 target);
+      fileSet->EvaluateFileEntry(dirs, entries, entryCge, context.LG,
+                                 context.Config, target);
     }
 
     Json::Value files = Json::arrayValue;
@@ -1608,19 +1610,20 @@ std::pair<Json::Value, Target::FileSetDatabase> Target::DumpFileSets()
         continue;
       }
 
+      cm::GenEx::Context context(this->GT->LocalGenerator, this->Config);
+
       auto fileEntries = fs->CompileFileEntries();
       auto directoryEntries = fs->CompileDirectoryEntries();
 
       auto directories = fs->EvaluateDirectoryEntries(
-        directoryEntries, this->GT->LocalGenerator, this->Config, this->GT);
+        directoryEntries, context.LG, context.Config, this->GT);
 
       fsJson.append(this->DumpFileSet(fs, directories));
 
       std::map<std::string, std::vector<std::string>> files_per_dirs;
       for (auto const& entry : fileEntries) {
-        fs->EvaluateFileEntry(directories, files_per_dirs, entry,
-                              this->GT->LocalGenerator, this->Config,
-                              this->GT);
+        fs->EvaluateFileEntry(directories, files_per_dirs, entry, context.LG,
+                              context.Config, this->GT);
       }
 
       for (auto const& files_per_dir : files_per_dirs) {

+ 7 - 4
Source/cmGeneratorExpression.cxx

@@ -454,17 +454,20 @@ std::string const& cmGeneratorExpressionInterpreter::Evaluate(
   this->CompiledGeneratorExpression =
     this->GeneratorExpression.Parse(std::move(expression));
 
+  cm::GenEx::Context context(this->LocalGenerator, this->Config,
+                             this->Language);
+
   // Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS
   cmGeneratorExpressionDAGChecker dagChecker{
     this->HeadTarget,
     property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property,
     nullptr,
     nullptr,
-    this->LocalGenerator,
-    this->Config,
+    context.LG,
+    context.Config,
   };
 
   return this->CompiledGeneratorExpression->Evaluate(
-    this->LocalGenerator, this->Config, this->HeadTarget, &dagChecker, nullptr,
-    this->Language);
+    context.LG, context.Config, this->HeadTarget, &dagChecker, nullptr,
+    context.Language);
 }

+ 13 - 9
Source/cmGeneratorExpressionEvaluationFile.cxx

@@ -8,6 +8,7 @@
 
 #include "cmsys/FStream.hxx"
 
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGlobalGenerator.h"
 #include "cmListFileCache.h"
@@ -39,11 +40,12 @@ void cmGeneratorExpressionEvaluationFile::Generate(
   cmCompiledGeneratorExpression* inputExpression,
   std::map<std::string, std::string>& outputFiles, mode_t perm)
 {
+  cm::GenEx::Context context(lg, config, lang);
   std::string rawCondition = this->Condition->GetInput();
   cmGeneratorTarget* target = lg->FindGeneratorTargetToUse(this->Target);
   if (!rawCondition.empty()) {
-    std::string condResult =
-      this->Condition->Evaluate(lg, config, target, nullptr, nullptr, lang);
+    std::string condResult = this->Condition->Evaluate(
+      context.LG, context.Config, target, nullptr, nullptr, context.Language);
     if (condResult == "0") {
       return;
     }
@@ -58,10 +60,10 @@ void cmGeneratorExpressionEvaluationFile::Generate(
     }
   }
 
-  std::string const outputFileName =
-    this->GetOutputFileName(lg, target, config, lang);
-  std::string const& outputContent =
-    inputExpression->Evaluate(lg, config, target, nullptr, nullptr, lang);
+  std::string const outputFileName = this->GetOutputFileName(
+    context.LG, target, context.Config, context.Language);
+  std::string const& outputContent = inputExpression->Evaluate(
+    context.LG, context.Config, target, nullptr, nullptr, context.Language);
 
   auto it = outputFiles.find(outputFileName);
 
@@ -207,13 +209,15 @@ std::string cmGeneratorExpressionEvaluationFile::GetOutputFileName(
   cmLocalGenerator const* lg, cmGeneratorTarget* target,
   std::string const& config, std::string const& lang)
 {
-  std::string outputFileName =
-    this->OutputFileExpr->Evaluate(lg, config, target, nullptr, nullptr, lang);
+  cm::GenEx::Context context(lg, config, lang);
+  std::string outputFileName = this->OutputFileExpr->Evaluate(
+    context.LG, context.Config, target, nullptr, nullptr, context.Language);
 
   if (cmSystemTools::FileIsFullPath(outputFileName)) {
     outputFileName = cmSystemTools::CollapseFullPath(outputFileName);
   } else {
-    outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg);
+    outputFileName =
+      this->FixRelativePath(outputFileName, PathForOutput, context.LG);
   }
 
   return outputFileName;

+ 32 - 24
Source/cmGeneratorTarget.cxx

@@ -27,6 +27,7 @@
 #include "cmExperimental.h"
 #include "cmFileSet.h"
 #include "cmFileTimes.h"
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
@@ -630,7 +631,7 @@ std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
 }
 
 namespace {
-void handleSystemIncludesDep(cmLocalGenerator* lg,
+void handleSystemIncludesDep(cmLocalGenerator const* lg,
                              cmGeneratorTarget const* depTgt,
                              std::string const& config,
                              cmGeneratorTarget const* headTarget,
@@ -737,12 +738,13 @@ std::string cmGeneratorTarget::GetLinkerTypeProperty(
   std::string propName{ "LINKER_TYPE" };
   auto linkerType = this->GetProperty(propName);
   if (!linkerType.IsEmpty()) {
+    cm::GenEx::Context context(this->LocalGenerator, config, lang);
     cmGeneratorExpressionDAGChecker dagChecker{
-      this, propName, nullptr, nullptr, this->LocalGenerator, config,
+      this, propName, nullptr, nullptr, context.LG, context.Config,
     };
-    auto ltype =
-      cmGeneratorExpression::Evaluate(*linkerType, this->GetLocalGenerator(),
-                                      config, this, &dagChecker, this, lang);
+    auto ltype = cmGeneratorExpression::Evaluate(
+      *linkerType, context.LG, context.Config, this, &dagChecker, this,
+      context.Language);
     if (this->IsDeviceLink()) {
       cmList list{ ltype };
       auto const DL_BEGIN = "<DEVICE_LINK>"_s;
@@ -1199,24 +1201,26 @@ void cmGeneratorTarget::AddSystemIncludeCacheKey(
   std::string const& key, std::string const& config,
   std::string const& language) const
 {
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
   cmGeneratorExpressionDAGChecker dagChecker{
-    this,    "SYSTEM_INCLUDE_DIRECTORIES", nullptr,
-    nullptr, this->LocalGenerator,         config,
+    this,           "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr, context.LG,
+    context.Config,
   };
 
   bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
 
   cmList result;
   for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
-    result.append(cmGeneratorExpression::Evaluate(
-      it, this->LocalGenerator, config, this, &dagChecker, nullptr, language));
+    result.append(
+      cmGeneratorExpression::Evaluate(it, context.LG, context.Config, this,
+                                      &dagChecker, nullptr, context.Language));
   }
 
   std::vector<cmGeneratorTarget const*> const& deps =
     this->GetLinkImplementationClosure(config, UseTo::Compile);
   for (cmGeneratorTarget const* dep : deps) {
-    handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
-                            &dagChecker, result, excludeImported, language);
+    handleSystemIncludesDep(context.LG, dep, context.Config, this, &dagChecker,
+                            result, excludeImported, context.Language);
   }
 
   cmLinkImplementation const* impl =
@@ -1226,9 +1230,9 @@ void cmGeneratorTarget::AddSystemIncludeCacheKey(
     if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
       for (auto const& lib : runtimeEntries->second) {
         if (lib.Target) {
-          handleSystemIncludesDep(this->LocalGenerator, lib.Target, config,
-                                  this, &dagChecker, result, excludeImported,
-                                  language);
+          handleSystemIncludesDep(context.LG, lib.Target, context.Config, this,
+                                  &dagChecker, result, excludeImported,
+                                  context.Language);
         }
       }
     }
@@ -1975,11 +1979,12 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
     return;
   }
 
+  cm::GenEx::Context context(this->LocalGenerator, config);
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "AUTOUIC_OPTIONS", nullptr, nullptr, this->LocalGenerator, config,
+    this, "AUTOUIC_OPTIONS", nullptr, nullptr, context.LG, context.Config,
   };
-  cmExpandList(cmGeneratorExpression::Evaluate(prop, this->LocalGenerator,
-                                               config, this, &dagChecker),
+  cmExpandList(cmGeneratorExpression::Evaluate(
+                 prop, context.LG, context.Config, this, &dagChecker),
                result);
 }
 
@@ -5439,17 +5444,18 @@ bool cmGeneratorTarget::AddHeaderSetVerification()
     bool first = true;
     for (auto const& config : this->Makefile->GetGeneratorConfigs(
            cmMakefile::GeneratorConfigQuery::IncludeEmptyConfig)) {
+      cm::GenEx::Context context(this->LocalGenerator, config);
       if (first || dirCgesContextSensitive) {
-        dirs = fileSet->EvaluateDirectoryEntries(dirCges, this->LocalGenerator,
-                                                 config, this);
+        dirs = fileSet->EvaluateDirectoryEntries(dirCges, context.LG,
+                                                 context.Config, this);
         dirCgesContextSensitive =
           std::any_of(dirCges.begin(), dirCges.end(), contextSensitive);
       }
       if (first || fileCgesContextSensitive) {
         filesPerDir.clear();
         for (auto const& fileCge : fileCges) {
-          fileSet->EvaluateFileEntry(dirs, filesPerDir, fileCge,
-                                     this->LocalGenerator, config, this);
+          fileSet->EvaluateFileEntry(dirs, filesPerDir, fileCge, context.LG,
+                                     context.Config, this);
           if (fileCge->GetHadContextSensitiveCondition()) {
             fileCgesContextSensitive = true;
           }
@@ -5980,15 +5986,17 @@ void cmGeneratorTarget::BuildFileSetInfoCache(std::string const& config) const
       continue;
     }
 
+    cm::GenEx::Context context(this->LocalGenerator, config);
+
     auto fileEntries = file_set->CompileFileEntries();
     auto directoryEntries = file_set->CompileDirectoryEntries();
     auto directories = file_set->EvaluateDirectoryEntries(
-      directoryEntries, this->LocalGenerator, config, this);
+      directoryEntries, context.LG, context.Config, this);
 
     std::map<std::string, std::vector<std::string>> files;
     for (auto const& entry : fileEntries) {
-      file_set->EvaluateFileEntry(directories, files, entry,
-                                  this->LocalGenerator, config, this);
+      file_set->EvaluateFileEntry(directories, files, entry, context.LG,
+                                  context.Config, this);
     }
 
     for (auto const& it : files) {

+ 19 - 18
Source/cmGeneratorTarget_IncludeDirectories.cxx

@@ -17,6 +17,7 @@
 #include <cmext/algorithm>
 
 #include "cmEvaluatedTargetProperty.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmGlobalGenerator.h"
 #include "cmLinkItem.h"
@@ -44,15 +45,16 @@ std::string AddLangSpecificInterfaceIncludeDirectories(
   cmGeneratorTarget const* root, cmGeneratorTarget const* target,
   std::string const& lang, std::string const& config,
   std::string const& propertyName, IncludeDirectoryFallBack mode,
-  cmGeneratorExpressionDAGChecker* context)
+  cmGeneratorExpressionDAGChecker* dagCheckerParent)
 {
+  cm::GenEx::Context context(target->LocalGenerator, config);
   cmGeneratorExpressionDAGChecker dagChecker{
     target,
     propertyName,
     nullptr,
-    context,
-    target->GetLocalGenerator(),
-    config,
+    dagCheckerParent,
+    context.LG,
+    context.Config,
     target->GetBacktrace(),
   };
   switch (dagChecker.Check()) {
@@ -103,14 +105,10 @@ void AddLangSpecificImplicitIncludeDirectories(
 {
   if (auto const* libraries =
         target->GetLinkImplementationLibraries(config, UseTo::Compile)) {
+    cm::GenEx::Context context(target->LocalGenerator, config, lang);
     cmGeneratorExpressionDAGChecker dagChecker{
-      target,
-      propertyName,
-      nullptr,
-      nullptr,
-      target->GetLocalGenerator(),
-      config,
-      target->GetBacktrace(),
+      target,         propertyName,           nullptr, nullptr, context.LG,
+      context.Config, target->GetBacktrace(),
     };
 
     for (cmLinkImplItem const& library : libraries->Libraries) {
@@ -137,8 +135,8 @@ void AddLangSpecificImplicitIncludeDirectories(
           }
 
           cmExpandList(AddLangSpecificInterfaceIncludeDirectories(
-                         target, dependency, lang, config, propertyName, mode,
-                         &dagChecker),
+                         target, dependency, context.Language, context.Config,
+                         propertyName, mode, &dagChecker),
                        entry.Values);
           entries.Entries.emplace_back(std::move(entry));
         }
@@ -231,9 +229,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
   std::vector<BT<std::string>> includes;
   std::unordered_set<std::string> uniqueIncludes;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, lang);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this,    "INCLUDE_DIRECTORIES", nullptr,
-    nullptr, this->LocalGenerator,  config,
+    this, "INCLUDE_DIRECTORIES", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -244,7 +243,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
   this->DebugIncludesDone = true;
 
   EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, lang, &dagChecker, this->IncludeDirectoriesEntries);
+    this, context.Config, context.Language, &dagChecker,
+    this->IncludeDirectoriesEntries);
 
   if (lang == "Swift") {
     AddLangSpecificImplicitIncludeDirectories(
@@ -271,8 +271,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
       entries);
   }
 
-  AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes);
+  AddInterfaceEntries(this, context.Config, "INTERFACE_INCLUDE_DIRECTORIES",
+                      context.Language, &dagChecker, entries,
+                      IncludeRuntimeInterface::Yes);
 
   processIncludeDirectories(this, entries, includes, uniqueIncludes,
                             debugIncludes);

+ 13 - 9
Source/cmGeneratorTarget_Link.cxx

@@ -25,6 +25,7 @@
 
 #include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmGlobalGenerator.h"
@@ -541,13 +542,15 @@ void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
     return;
   }
   // Keep this logic in sync with ComputeLinkImplementationLibraries.
+  cm::GenEx::Context context(this->LocalGenerator, config,
+                             headTarget->LinkerLanguage);
   cmGeneratorExpressionDAGChecker dagChecker{
     this,
     prop,
     nullptr,
     nullptr,
-    this->LocalGenerator,
-    config,
+    context.LG,
+    context.Config,
     cmListFileBacktrace(),
     cmGeneratorExpressionDAGChecker::ComputingLinkLibraries::Yes,
   };
@@ -565,9 +568,8 @@ void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
                              entry.Backtrace);
     std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(entry.Value);
     cge->SetEvaluateForBuildsystem(true);
-    cmList libs{ cge->Evaluate(this->LocalGenerator, config, headTarget,
-                               &dagChecker, this,
-                               headTarget->LinkerLanguage) };
+    cmList libs{ cge->Evaluate(context.LG, context.Config, headTarget,
+                               &dagChecker, this, context.Language) };
 
     auto linkFeature = cmLinkItem::DEFAULT;
     for (auto const& lib : libs) {
@@ -1133,6 +1135,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
   std::string const& config, cmOptionalLinkImplementation& impl,
   UseTo usage) const
 {
+  cm::GenEx::Context context(this->LocalGenerator, config,
+                             this->LinkerLanguage);
   cmLocalGenerator const* lg = this->LocalGenerator;
   cmMakefile const* mf = lg->GetMakefile();
   cmBTStringRange entryRange = this->Target->GetLinkImplementationEntries();
@@ -1145,8 +1149,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
       "LINK_LIBRARIES",
       nullptr,
       nullptr,
-      this->LocalGenerator,
-      config,
+      context.LG,
+      context.Config,
       cmListFileBacktrace(),
       cmGeneratorExpressionDAGChecker::ComputingLinkLibraries::Yes,
     };
@@ -1169,8 +1173,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
       ge.Parse(entry.Value);
     cge->SetEvaluateForBuildsystem(true);
     std::string const& evaluated =
-      cge->Evaluate(this->LocalGenerator, config, this, &dagChecker, nullptr,
-                    this->LinkerLanguage);
+      cge->Evaluate(context.LG, context.Config, this, &dagChecker, nullptr,
+                    context.Language);
     cmList llibs(evaluated);
     if (cge->GetHadHeadSensitiveCondition()) {
       impl.HadHeadSensitiveCondition = true;

+ 9 - 6
Source/cmGeneratorTarget_LinkDirectories.cxx

@@ -14,6 +14,7 @@
 #include <cmext/algorithm>
 
 #include "cmEvaluatedTargetProperty.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmLinkItem.h"
 #include "cmList.h"
@@ -122,8 +123,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
   std::vector<BT<std::string>> result;
   std::unordered_set<std::string> uniqueDirectories;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "LINK_DIRECTORIES", nullptr, nullptr, this->LocalGenerator, config,
+    this, "LINK_DIRECTORIES", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -136,11 +139,11 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
   EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
     this, config, language, &dagChecker, this->LinkDirectoriesEntries);
 
-  AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes,
-                      this->GetPolicyStatusCMP0099() == cmPolicies::NEW
-                        ? UseTo::Link
-                        : UseTo::Compile);
+  AddInterfaceEntries(
+    this, context.Config, "INTERFACE_LINK_DIRECTORIES", context.Language,
+    &dagChecker, entries, IncludeRuntimeInterface::Yes,
+    this->GetPolicyStatusCMP0099() == cmPolicies::NEW ? UseTo::Link
+                                                      : UseTo::Compile);
 
   processLinkDirectories(this, entries, result, uniqueDirectories,
                          debugDirectories);

+ 60 - 38
Source/cmGeneratorTarget_Options.cxx

@@ -18,6 +18,7 @@
 #include <cmext/string_view>
 
 #include "cmEvaluatedTargetProperty.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmList.h"
 #include "cmListFileCache.h"
@@ -230,8 +231,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
   std::vector<BT<std::string>> result;
   std::unordered_set<std::string> uniqueOptions;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "COMPILE_OPTIONS", nullptr, nullptr, this->LocalGenerator, config,
+    this, "COMPILE_OPTIONS", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -241,11 +244,13 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
 
   this->DebugCompileOptionsDone = true;
 
-  EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, language, &dagChecker, this->CompileOptionsEntries);
+  EvaluatedTargetPropertyEntries entries =
+    EvaluateTargetPropertyEntries(this, context.Config, context.Language,
+                                  &dagChecker, this->CompileOptionsEntries);
 
-  AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS", language,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes);
+  AddInterfaceEntries(this, context.Config, "INTERFACE_COMPILE_OPTIONS",
+                      context.Language, &dagChecker, entries,
+                      IncludeRuntimeInterface::Yes);
 
   processOptions(this, entries, result, uniqueOptions, debugOptions,
                  "compile options", OptionsParse::Shell);
@@ -270,8 +275,11 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
   std::vector<BT<std::string>> result;
   std::unordered_set<std::string> uniqueFeatures;
 
+  cm::GenEx::Context context(this->LocalGenerator, config,
+                             /*language=*/std::string());
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "COMPILE_FEATURES", nullptr, nullptr, this->LocalGenerator, config,
+    this, "COMPILE_FEATURES", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -281,11 +289,12 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
 
   this->DebugCompileFeaturesDone = true;
 
-  EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, std::string(), &dagChecker, this->CompileFeaturesEntries);
+  EvaluatedTargetPropertyEntries entries =
+    EvaluateTargetPropertyEntries(this, context.Config, context.Language,
+                                  &dagChecker, this->CompileFeaturesEntries);
 
-  AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
-                      std::string(), &dagChecker, entries,
+  AddInterfaceEntries(this, context.Config, "INTERFACE_COMPILE_FEATURES",
+                      context.Language, &dagChecker, entries,
                       IncludeRuntimeInterface::Yes);
 
   processOptions(this, entries, result, uniqueFeatures, debugFeatures,
@@ -319,9 +328,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
   std::vector<BT<std::string>> list;
   std::unordered_set<std::string> uniqueOptions;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this,    "COMPILE_DEFINITIONS", nullptr,
-    nullptr, this->LocalGenerator,  config,
+    this, "COMPILE_DEFINITIONS", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -332,10 +342,12 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
   this->DebugCompileDefinitionsDone = true;
 
   EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, language, &dagChecker, this->CompileDefinitionsEntries);
+    this, context.Config, context.Language, &dagChecker,
+    this->CompileDefinitionsEntries);
 
-  AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes);
+  AddInterfaceEntries(this, context.Config, "INTERFACE_COMPILE_DEFINITIONS",
+                      context.Language, &dagChecker, entries,
+                      IncludeRuntimeInterface::Yes);
 
   processOptions(this, entries, list, uniqueOptions, debugDefines,
                  "compile definitions", OptionsParse::None);
@@ -356,8 +368,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
   }
   std::unordered_set<std::string> uniqueOptions;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "PRECOMPILE_HEADERS", nullptr, nullptr, this->LocalGenerator, config,
+    this, "PRECOMPILE_HEADERS", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -368,11 +382,13 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
 
   this->DebugPrecompileHeadersDone = true;
 
-  EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, language, &dagChecker, this->PrecompileHeadersEntries);
+  EvaluatedTargetPropertyEntries entries =
+    EvaluateTargetPropertyEntries(this, context.Config, context.Language,
+                                  &dagChecker, this->PrecompileHeadersEntries);
 
-  AddInterfaceEntries(this, config, "INTERFACE_PRECOMPILE_HEADERS", language,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes);
+  AddInterfaceEntries(this, context.Config, "INTERFACE_PRECOMPILE_HEADERS",
+                      context.Language, &dagChecker, entries,
+                      IncludeRuntimeInterface::Yes);
 
   std::vector<BT<std::string>> list;
   processOptions(this, entries, list, uniqueOptions, debugDefines,
@@ -413,8 +429,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
   std::vector<BT<std::string>> result;
   std::unordered_set<std::string> uniqueOptions;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "LINK_OPTIONS", nullptr, nullptr, this->LocalGenerator, config,
+    this, "LINK_OPTIONS", nullptr, nullptr, context.LG, context.Config,
   };
 
   cmList debugProperties{ this->Makefile->GetDefinition(
@@ -424,14 +442,15 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
 
   this->DebugLinkOptionsDone = true;
 
-  EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, language, &dagChecker, this->LinkOptionsEntries);
+  EvaluatedTargetPropertyEntries entries =
+    EvaluateTargetPropertyEntries(this, context.Config, context.Language,
+                                  &dagChecker, this->LinkOptionsEntries);
 
-  AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes,
-                      this->GetPolicyStatusCMP0099() == cmPolicies::NEW
-                        ? UseTo::Link
-                        : UseTo::Compile);
+  AddInterfaceEntries(
+    this, context.Config, "INTERFACE_LINK_OPTIONS", context.Language,
+    &dagChecker, entries, IncludeRuntimeInterface::Yes,
+    this->GetPolicyStatusCMP0099() == cmPolicies::NEW ? UseTo::Link
+                                                      : UseTo::Compile);
 
   processOptions(this, entries, result, uniqueOptions, debugOptions,
                  "link options", OptionsParse::Shell, this->IsDeviceLink());
@@ -595,9 +614,11 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
   std::vector<BT<std::string>> result;
   std::unordered_set<std::string> uniqueOptions;
 
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this,    "STATIC_LIBRARY_OPTIONS", nullptr,
-    nullptr, this->LocalGenerator,     config,
+    this,       "STATIC_LIBRARY_OPTIONS", nullptr, nullptr,
+    context.LG, context.Config,
   };
 
   EvaluatedTargetPropertyEntries entries;
@@ -605,7 +626,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
     std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
       *this->LocalGenerator->GetCMakeInstance(), *linkOptions);
     entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
-      this, config, language, &dagChecker, *entry));
+      this, context.Config, context.Language, &dagChecker, *entry));
   }
   processOptions(this, entries, result, uniqueOptions, false,
                  "static library link options", OptionsParse::Shell);
@@ -640,8 +661,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
 {
   std::vector<BT<std::string>> result;
   std::unordered_set<std::string> uniqueOptions;
+  cm::GenEx::Context context(this->LocalGenerator, config, language);
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "LINK_DEPENDS", nullptr, nullptr, this->LocalGenerator, config,
+    this, "LINK_DEPENDS", nullptr, nullptr, context.LG, context.Config,
   };
 
   EvaluatedTargetPropertyEntries entries;
@@ -651,14 +673,14 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
       std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
         *this->LocalGenerator->GetCMakeInstance(), depend);
       entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
-        this, config, language, &dagChecker, *entry));
+        this, context.Config, context.Language, &dagChecker, *entry));
     }
   }
-  AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
-                      &dagChecker, entries, IncludeRuntimeInterface::Yes,
-                      this->GetPolicyStatusCMP0099() == cmPolicies::NEW
-                        ? UseTo::Link
-                        : UseTo::Compile);
+  AddInterfaceEntries(
+    this, context.Config, "INTERFACE_LINK_DEPENDS", context.Language,
+    &dagChecker, entries, IncludeRuntimeInterface::Yes,
+    this->GetPolicyStatusCMP0099() == cmPolicies::NEW ? UseTo::Link
+                                                      : UseTo::Compile);
 
   processOptions(this, entries, result, uniqueOptions, false, "link depends",
                  OptionsParse::None);

+ 16 - 10
Source/cmGeneratorTarget_Sources.cxx

@@ -24,6 +24,7 @@
 #include "cmAlgorithms.h"
 #include "cmEvaluatedTargetProperty.h"
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
 #include "cmGlobalGenerator.h"
@@ -84,9 +85,11 @@ void addFileSetEntry(cmGeneratorTarget const* headTarget,
                      cmFileSet const* fileSet,
                      EvaluatedTargetPropertyEntries& entries)
 {
+  cm::GenEx::Context context(headTarget->GetLocalGenerator(), config,
+                             /*language=*/std::string());
   auto dirCges = fileSet->CompileDirectoryEntries();
   auto dirs = fileSet->EvaluateDirectoryEntries(
-    dirCges, headTarget->GetLocalGenerator(), config, headTarget, dagChecker);
+    dirCges, context.LG, context.Config, headTarget, dagChecker);
   bool contextSensitiveDirs = false;
   for (auto const& dirCge : dirCges) {
     if (dirCge->GetHadContextSensitiveCondition()) {
@@ -98,8 +101,8 @@ void addFileSetEntry(cmGeneratorTarget const* headTarget,
   for (auto& entryCge : fileSet->CompileFileEntries()) {
     auto tpe = cmGeneratorTarget::TargetPropertyEntry::CreateFileSet(
       dirs, contextSensitiveDirs, std::move(entryCge), fileSet);
-    entries.Entries.emplace_back(
-      EvaluateTargetPropertyEntry(headTarget, config, "", dagChecker, *tpe));
+    entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
+      headTarget, context.Config, context.Language, dagChecker, *tpe));
     EvaluatedTargetPropertyEntry const& entry = entries.Entries.back();
     for (auto const& file : entry.Values) {
       auto* sf = headTarget->Makefile->GetOrCreateSource(file);
@@ -240,12 +243,15 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
 
   this->DebugSourcesDone = true;
 
+  cm::GenEx::Context context(this->LocalGenerator, config,
+                             /*language=*/std::string());
+
   cmGeneratorExpressionDAGChecker dagChecker{
-    this, "SOURCES", nullptr, nullptr, this->LocalGenerator, config,
+    this, "SOURCES", nullptr, nullptr, context.LG, context.Config,
   };
 
   EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
-    this, config, std::string(), &dagChecker, this->SourceEntries);
+    this, context.Config, context.Language, &dagChecker, this->SourceEntries);
 
   std::unordered_set<std::string> uniqueSrcs;
   bool contextDependentDirectSources =
@@ -253,9 +259,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
 
   // Collect INTERFACE_SOURCES of all direct link-dependencies.
   EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries;
-  AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(),
-                      &dagChecker, linkInterfaceSourcesEntries,
-                      IncludeRuntimeInterface::No, UseTo::Compile);
+  AddInterfaceEntries(
+    this, context.Config, "INTERFACE_SOURCES", context.Language, &dagChecker,
+    linkInterfaceSourcesEntries, IncludeRuntimeInterface::No, UseTo::Compile);
   bool contextDependentInterfaceSources = processSources(
     this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources);
 
@@ -263,7 +269,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
   bool contextDependentObjects = false;
   if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
     EvaluatedTargetPropertyEntries linkObjectsEntries;
-    AddObjectEntries(this, config, &dagChecker, linkObjectsEntries);
+    AddObjectEntries(this, context.Config, &dagChecker, linkObjectsEntries);
     contextDependentObjects = processSources(this, linkObjectsEntries, files,
                                              uniqueSrcs, debugSources);
     // Note that for imported targets or multi-config generators supporting
@@ -274,7 +280,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
 
   // Collect this target's file sets.
   EvaluatedTargetPropertyEntries fileSetEntries;
-  AddFileSetEntries(this, config, &dagChecker, fileSetEntries);
+  AddFileSetEntries(this, context.Config, &dagChecker, fileSetEntries);
   bool contextDependentFileSets =
     processSources(this, fileSetEntries, files, uniqueSrcs, debugSources);
 

+ 6 - 3
Source/cmInstallFileSetGenerator.cxx

@@ -12,6 +12,7 @@
 #include <cmext/string_view>
 
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
@@ -122,14 +123,16 @@ cmInstallFileSetGenerator::CalculateFilesPerDir(
 {
   std::map<std::string, std::vector<std::string>> result;
 
+  cm::GenEx::Context context(this->LocalGenerator, config);
+
   auto dirCges = this->FileSet->CompileDirectoryEntries();
   auto dirs = this->FileSet->EvaluateDirectoryEntries(
-    dirCges, this->LocalGenerator, config, this->Target);
+    dirCges, context.LG, context.Config, this->Target);
 
   auto fileCges = this->FileSet->CompileFileEntries();
   for (auto const& fileCge : fileCges) {
-    this->FileSet->EvaluateFileEntry(
-      dirs, result, fileCge, this->LocalGenerator, config, this->Target);
+    this->FileSet->EvaluateFileEntry(dirs, result, fileCge, context.LG,
+                                     context.Config, this->Target);
   }
 
   return result;

+ 5 - 5
Source/cmMakefileTargetGenerator.cxx

@@ -23,6 +23,7 @@
 #include "cmCustomCommand.h"
 #include "cmCustomCommandGenerator.h"
 #include "cmFileSet.h"
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorOptions.h"
@@ -205,6 +206,7 @@ void cmMakefileTargetGenerator::CreateRuleFile()
 
 void cmMakefileTargetGenerator::WriteTargetBuildRules()
 {
+  cm::GenEx::Context context(this->LocalGenerator, this->GetConfigName());
   this->GeneratorTarget->CheckCxxModuleStatus(this->GetConfigName());
 
   // -- Write the custom commands for this target
@@ -362,14 +364,12 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
     auto fileEntries = file_set->CompileFileEntries();
     auto directoryEntries = file_set->CompileDirectoryEntries();
     auto directories = file_set->EvaluateDirectoryEntries(
-      directoryEntries, this->LocalGenerator, this->GetConfigName(),
-      this->GeneratorTarget);
+      directoryEntries, context.LG, context.Config, this->GeneratorTarget);
 
     std::map<std::string, std::vector<std::string>> files;
     for (auto const& entry : fileEntries) {
-      file_set->EvaluateFileEntry(directories, files, entry,
-                                  this->LocalGenerator, this->GetConfigName(),
-                                  this->GeneratorTarget);
+      file_set->EvaluateFileEntry(directories, files, entry, context.LG,
+                                  context.Config, this->GeneratorTarget);
     }
 
     for (auto const& it : files) {

+ 14 - 11
Source/cmQtAutoGenInitializer.cxx

@@ -31,6 +31,7 @@
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmEvaluatedTargetProperty.h"
+#include "cmGenExContext.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpressionDAGChecker.h"
@@ -1966,24 +1967,26 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
     if (this->MultiConfig) {
       for (auto const& cfg : this->ConfigsList) {
         if (!cfg.empty()) {
+          cm::GenEx::Context context(this->LocalGen, cfg, "CXX");
           cmGeneratorExpressionDAGChecker dagChecker{
-            this->GenTarget, "AUTOMOC_MACRO_NAMES", nullptr,
-            nullptr,         this->LocalGen,        cfg,
+            this->GenTarget, "AUTOMOC_MACRO_NAMES", nullptr, nullptr,
+            context.LG,      context.Config,
           };
-          AddInterfaceEntries(this->GenTarget, cfg,
-                              "INTERFACE_AUTOMOC_MACRO_NAMES", "CXX",
-                              &dagChecker, InterfaceAutoMocMacroNamesEntries,
-                              IncludeRuntimeInterface::Yes);
+          AddInterfaceEntries(
+            this->GenTarget, context.Config, "INTERFACE_AUTOMOC_MACRO_NAMES",
+            context.Language, &dagChecker, InterfaceAutoMocMacroNamesEntries,
+            IncludeRuntimeInterface::Yes);
         }
       }
     } else {
+      cm::GenEx::Context context(this->LocalGen, this->ConfigDefault, "CXX");
       cmGeneratorExpressionDAGChecker dagChecker{
-        this->GenTarget, "AUTOMOC_MACRO_NAMES", nullptr,
-        nullptr,         this->LocalGen,        this->ConfigDefault,
+        this->GenTarget, "AUTOMOC_MACRO_NAMES", nullptr, nullptr,
+        context.LG,      context.Config,
       };
-      AddInterfaceEntries(this->GenTarget, this->ConfigDefault,
-                          "INTERFACE_AUTOMOC_MACRO_NAMES", "CXX", &dagChecker,
-                          InterfaceAutoMocMacroNamesEntries,
+      AddInterfaceEntries(this->GenTarget, context.Config,
+                          "INTERFACE_AUTOMOC_MACRO_NAMES", context.Language,
+                          &dagChecker, InterfaceAutoMocMacroNamesEntries,
                           IncludeRuntimeInterface::Yes);
     }