Browse Source

Merge topic 'profile-genex'

4d70a94545 Profiling: Profile genex evaluation
09d7f947d6 cmGeneratorExpression: Require cmake instance
553794e987 cmake::CreateProfilingEntry: Refactor to take lambda for args

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Acked-by: alcroito <[email protected]>
Merge-request: !7898
Brad King 3 years ago
parent
commit
0e2a73fefd

+ 3 - 2
Source/cmCustomCommandGenerator.cxx

@@ -172,7 +172,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(
     };
   }
 
-  cmGeneratorExpression ge(cc.GetBacktrace());
+  cmGeneratorExpression ge(*lg->GetCMakeInstance(), cc.GetBacktrace());
   cmGeneratorTarget const* target{ lg->FindGeneratorTargetToUse(
     this->Target) };
 
@@ -417,7 +417,8 @@ std::string cmCustomCommandGenerator::GetDepfile() const
     return "";
   }
 
-  cmGeneratorExpression ge(this->CC->GetBacktrace());
+  cmGeneratorExpression ge(*this->LG->GetCMakeInstance(),
+                           this->CC->GetBacktrace());
   return EvaluateDepfile(depfile, ge, this->LG, this->OutputConfig);
 }
 

+ 1 - 1
Source/cmExportFileGenerator.cxx

@@ -379,7 +379,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
   const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
   cmValue input = target->GetProperty(propName);
 
-  cmGeneratorExpression ge;
+  cmGeneratorExpression ge(*target->Makefile->GetCMakeInstance());
 
   std::string dirs = cmGeneratorExpression::Preprocess(
     cmJoin(target->Target->GetInstallIncludeDirectoriesEntries(te), ";"),

+ 2 - 2
Source/cmExportInstallFileGenerator.cxx

@@ -570,7 +570,7 @@ std::string cmExportInstallFileGenerator::GetFileSetDirectories(
   auto configs =
     gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
 
-  cmGeneratorExpression ge;
+  cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance());
   auto cge = ge.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
 
   for (auto const& config : configs) {
@@ -617,7 +617,7 @@ std::string cmExportInstallFileGenerator::GetFileSetFiles(
   auto fileEntries = fileSet->CompileFileEntries();
   auto directoryEntries = fileSet->CompileDirectoryEntries();
 
-  cmGeneratorExpression destGe;
+  cmGeneratorExpression destGe(*gte->Makefile->GetCMakeInstance());
   auto destCge =
     destGe.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
 

+ 1 - 1
Source/cmExportTryCompileFileGenerator.cxx

@@ -70,7 +70,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
     return std::string();
   }
 
-  cmGeneratorExpression ge;
+  cmGeneratorExpression ge(*tgt->Makefile->GetCMakeInstance());
 
   std::unique_ptr<cmGeneratorExpressionDAGChecker> parentDagChecker;
   if (propName == "INTERFACE_LINK_OPTIONS") {

+ 4 - 2
Source/cmFileCommand.cxx

@@ -2462,11 +2462,13 @@ void AddEvaluationFile(const std::string& inputName,
 {
   cmListFileBacktrace lfbt = status.GetMakefile().GetBacktrace();
 
-  cmGeneratorExpression outputGe(lfbt);
+  cmGeneratorExpression outputGe(*status.GetMakefile().GetCMakeInstance(),
+                                 lfbt);
   std::unique_ptr<cmCompiledGeneratorExpression> outputCge =
     outputGe.Parse(outputExpr);
 
-  cmGeneratorExpression conditionGe(lfbt);
+  cmGeneratorExpression conditionGe(*status.GetMakefile().GetCMakeInstance(),
+                                    lfbt);
   std::unique_ptr<cmCompiledGeneratorExpression> conditionCge =
     conditionGe.Parse(condition);
 

+ 5 - 4
Source/cmFileSet.cxx

@@ -78,9 +78,10 @@ bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis)
   return false;
 }
 
-cmFileSet::cmFileSet(std::string name, std::string type,
+cmFileSet::cmFileSet(cmake& cmakeInstance, std::string name, std::string type,
                      cmFileSetVisibility visibility)
-  : Name(std::move(name))
+  : CMakeInstance(cmakeInstance)
+  , Name(std::move(name))
   , Type(std::move(type))
   , Visibility(visibility)
 {
@@ -113,7 +114,7 @@ cmFileSet::CompileFileEntries() const
 
   for (auto const& entry : this->FileEntries) {
     for (auto const& ex : cmExpandedList(entry.Value)) {
-      cmGeneratorExpression ge(entry.Backtrace);
+      cmGeneratorExpression ge(this->CMakeInstance, entry.Backtrace);
       auto cge = ge.Parse(ex);
       result.push_back(std::move(cge));
     }
@@ -129,7 +130,7 @@ cmFileSet::CompileDirectoryEntries() const
 
   for (auto const& entry : this->DirectoryEntries) {
     for (auto const& ex : cmExpandedList(entry.Value)) {
-      cmGeneratorExpression ge(entry.Backtrace);
+      cmGeneratorExpression ge(this->CMakeInstance, entry.Backtrace);
       auto cge = ge.Parse(ex);
       result.push_back(std::move(cge));
     }

+ 3 - 1
Source/cmFileSet.h

@@ -17,6 +17,7 @@ struct cmGeneratorExpressionDAGChecker;
 class cmGeneratorTarget;
 class cmLocalGenerator;
 class cmMakefile;
+class cmake;
 
 enum class cmFileSetVisibility
 {
@@ -33,7 +34,7 @@ bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis);
 class cmFileSet
 {
 public:
-  cmFileSet(std::string name, std::string type,
+  cmFileSet(cmake& cmakeInstance, std::string name, std::string type,
             cmFileSetVisibility visibility);
 
   const std::string& GetName() const { return this->Name; }
@@ -77,6 +78,7 @@ public:
   static bool IsValidName(const std::string& name);
 
 private:
+  cmake& CMakeInstance;
   std::string Name;
   std::string Type;
   cmFileSetVisibility Visibility;

+ 21 - 5
Source/cmGeneratorExpression.cxx

@@ -13,11 +13,15 @@
 #include "cmGeneratorExpressionEvaluator.h"
 #include "cmGeneratorExpressionLexer.h"
 #include "cmGeneratorExpressionParser.h"
+#include "cmLocalGenerator.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
+#include "cmake.h"
 
-cmGeneratorExpression::cmGeneratorExpression(cmListFileBacktrace backtrace)
-  : Backtrace(std::move(backtrace))
+cmGeneratorExpression::cmGeneratorExpression(cmake& cmakeInstance,
+                                             cmListFileBacktrace backtrace)
+  : CMakeInstance(cmakeInstance)
+  , Backtrace(std::move(backtrace))
 {
 }
 
@@ -29,7 +33,8 @@ std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
   std::string input) const
 {
   return std::unique_ptr<cmCompiledGeneratorExpression>(
-    new cmCompiledGeneratorExpression(this->Backtrace, std::move(input)));
+    new cmCompiledGeneratorExpression(this->CMakeInstance, this->Backtrace,
+                                      std::move(input)));
 }
 
 std::string cmGeneratorExpression::Evaluate(
@@ -39,7 +44,13 @@ std::string cmGeneratorExpression::Evaluate(
   cmGeneratorTarget const* currentTarget, std::string const& language)
 {
   if (Find(input) != std::string::npos) {
-    cmCompiledGeneratorExpression cge(cmListFileBacktrace(), std::move(input));
+#ifndef CMAKE_BOOTSTRAP
+    auto profilingRAII = lg->GetCMakeInstance()->CreateProfilingEntry(
+      "genex_compile_eval", input);
+#endif
+
+    cmCompiledGeneratorExpression cge(*lg->GetCMakeInstance(),
+                                      cmListFileBacktrace(), std::move(input));
     return cge.Evaluate(lg, config, headTarget, dagChecker, currentTarget,
                         language);
   }
@@ -97,10 +108,15 @@ const std::string& cmCompiledGeneratorExpression::EvaluateWithContext(
 }
 
 cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
-  cmListFileBacktrace backtrace, std::string input)
+  cmake& cmakeInstance, cmListFileBacktrace backtrace, std::string input)
   : Backtrace(std::move(backtrace))
   , Input(std::move(input))
 {
+#ifndef CMAKE_BOOTSTRAP
+  auto profilingRAII =
+    cmakeInstance.CreateProfilingEntry("genex_compile", this->Input);
+#endif
+
   cmGeneratorExpressionLexer l;
   std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(this->Input);
   this->NeedsEvaluation = l.GetSawGeneratorExpression();

+ 9 - 4
Source/cmGeneratorExpression.h

@@ -12,10 +12,11 @@
 #include <vector>
 
 #include "cmListFileCache.h"
+#include "cmLocalGenerator.h"
 
+class cmake;
 class cmCompiledGeneratorExpression;
 class cmGeneratorTarget;
-class cmLocalGenerator;
 struct cmGeneratorExpressionContext;
 struct cmGeneratorExpressionDAGChecker;
 struct cmGeneratorExpressionEvaluator;
@@ -33,7 +34,8 @@ class cmGeneratorExpression
 {
 public:
   /** Construct. */
-  cmGeneratorExpression(cmListFileBacktrace backtrace = cmListFileBacktrace());
+  cmGeneratorExpression(cmake& cmakeInstance,
+                        cmListFileBacktrace backtrace = cmListFileBacktrace());
   ~cmGeneratorExpression();
 
   cmGeneratorExpression(cmGeneratorExpression const&) = delete;
@@ -82,6 +84,7 @@ public:
                                    const std::string& replacement);
 
 private:
+  cmake& CMakeInstance;
   cmListFileBacktrace Backtrace;
 };
 
@@ -152,7 +155,8 @@ private:
     cmGeneratorExpressionContext& context,
     cmGeneratorExpressionDAGChecker* dagChecker) const;
 
-  cmCompiledGeneratorExpression(cmListFileBacktrace backtrace,
+  cmCompiledGeneratorExpression(cmake& cmakeInstance,
+                                cmListFileBacktrace backtrace,
                                 std::string input);
 
   friend class cmGeneratorExpression;
@@ -184,7 +188,8 @@ public:
                                    std::string config,
                                    cmGeneratorTarget const* headTarget,
                                    std::string language = std::string())
-    : LocalGenerator(localGenerator)
+    : GeneratorExpression(*localGenerator->GetCMakeInstance())
+    , LocalGenerator(localGenerator)
     , Config(std::move(config))
     , HeadTarget(headTarget)
     , Language(std::move(language))

+ 1 - 1
Source/cmGeneratorExpressionEvaluationFile.cxx

@@ -165,7 +165,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg)
   }
 
   cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace();
-  cmGeneratorExpression contentGE(lfbt);
+  cmGeneratorExpression contentGE(*lg->GetCMakeInstance(), lfbt);
   std::unique_ptr<cmCompiledGeneratorExpression> inputExpression =
     contentGE.Parse(inputContent);
 

+ 30 - 1
Source/cmGeneratorExpressionEvaluator.cxx

@@ -4,8 +4,14 @@
 
 #include <sstream>
 
+#ifndef CMAKE_BOOTSTRAP
+#  include <cm3p/json/value.h>
+#endif
+
 #include "cmGeneratorExpressionContext.h"
 #include "cmGeneratorExpressionNode.h"
+#include "cmLocalGenerator.h"
+#include "cmake.h"
 
 GeneratorExpressionContent::GeneratorExpressionContent(
   const char* startContent, size_t length)
@@ -61,6 +67,12 @@ std::string GeneratorExpressionContent::Evaluate(
   cmGeneratorExpressionContext* context,
   cmGeneratorExpressionDAGChecker* dagChecker) const
 {
+#ifndef CMAKE_BOOTSTRAP
+  auto evalProfilingRAII =
+    context->LG->GetCMakeInstance()->CreateProfilingEntry(
+      "genex_eval", this->GetOriginalExpression());
+#endif
+
   std::string identifier;
   {
     for (const auto& pExprEval : this->IdentifierChildren) {
@@ -101,7 +113,24 @@ std::string GeneratorExpressionContent::Evaluate(
     return std::string();
   }
 
-  return node->Evaluate(parameters, context, this, dagChecker);
+  {
+#ifndef CMAKE_BOOTSTRAP
+    auto execProfilingRAII =
+      context->LG->GetCMakeInstance()->CreateProfilingEntry(
+        "genex_exec", identifier, [&parameters]() -> Json::Value {
+          Json::Value args = Json::objectValue;
+          if (!parameters.empty()) {
+            args["genexArgs"] = Json::arrayValue;
+            for (auto const& parameter : parameters) {
+              args["genexArgs"].append(parameter);
+            }
+          }
+          return args;
+        });
+#endif
+
+    return node->Evaluate(parameters, context, this, dagChecker);
+  }
 }
 
 std::string GeneratorExpressionContent::EvaluateParameters(

+ 1 - 1
Source/cmGeneratorExpressionNode.cxx

@@ -57,7 +57,7 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
   cmGeneratorExpressionDAGChecker* dagChecker,
   cmGeneratorTarget const* currentTarget)
 {
-  cmGeneratorExpression ge(context->Backtrace);
+  cmGeneratorExpression ge(*lg->GetCMakeInstance(), context->Backtrace);
   std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
   cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
   cge->SetQuiet(context->Quiet);

+ 37 - 22
Source/cmGeneratorTarget.cxx

@@ -241,15 +241,16 @@ private:
 
 std::unique_ptr<
   cmGeneratorTarget::
-    TargetPropertyEntry> static CreateTargetPropertyEntry(const BT<std::
-                                                                     string>&
+    TargetPropertyEntry> static CreateTargetPropertyEntry(cmake& cmakeInstance,
+                                                          const BT<
+                                                            std::string>&
                                                             propertyValue,
                                                           bool
                                                             evaluateForBuildsystem =
                                                               false)
 {
   if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) {
-    cmGeneratorExpression ge(propertyValue.Backtrace);
+    cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace);
     std::unique_ptr<cmCompiledGeneratorExpression> cge =
       ge.Parse(propertyValue.Value);
     cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
@@ -262,12 +263,13 @@ std::unique_ptr<
 }
 
 static void CreatePropertyGeneratorExpressions(
-  cmBTStringRange entries,
+  cmake& cmakeInstance, cmBTStringRange entries,
   std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
   bool evaluateForBuildsystem = false)
 {
   for (auto const& entry : entries) {
-    items.push_back(CreateTargetPropertyEntry(entry, evaluateForBuildsystem));
+    items.push_back(
+      CreateTargetPropertyEntry(cmakeInstance, entry, evaluateForBuildsystem));
   }
 }
 
@@ -343,29 +345,36 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
 
   this->GlobalGenerator->ComputeTargetObjectDirectory(this);
 
-  CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetIncludeDirectoriesEntries(),
                                      this->IncludeDirectoriesEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetCompileOptionsEntries(),
                                      this->CompileOptionsEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetCompileFeaturesEntries(),
                                      this->CompileFeaturesEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetCompileDefinitionsEntries(),
                                      this->CompileDefinitionsEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetLinkOptionsEntries(),
                                      this->LinkOptionsEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetLinkDirectoriesEntries(),
                                      this->LinkDirectoriesEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetPrecompileHeadersEntries(),
+  CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
+                                     t->GetPrecompileHeadersEntries(),
                                      this->PrecompileHeadersEntries);
 
-  CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
-                                     this->SourceEntries, true);
+  CreatePropertyGeneratorExpressions(
+    *lg->GetCMakeInstance(), t->GetSourceEntries(), this->SourceEntries, true);
 
   this->PolicyMap = t->GetPolicyMap();
 
@@ -753,6 +762,7 @@ void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
   this->SourceEntries.insert(
     before ? this->SourceEntries.begin() : this->SourceEntries.end(),
     CreateTargetPropertyEntry(
+      *this->LocalGenerator->GetCMakeInstance(),
       BT<std::string>(src, this->Makefile->GetBacktrace()), true));
   this->ClearSourcesCache();
 }
@@ -780,6 +790,7 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
     before ? this->IncludeDirectoriesEntries.begin()
            : this->IncludeDirectoriesEntries.end(),
     CreateTargetPropertyEntry(
+      *this->Makefile->GetCMakeInstance(),
       BT<std::string>(src, this->Makefile->GetBacktrace()), true));
 }
 
@@ -1653,7 +1664,8 @@ void AddObjectEntries(cmGeneratorTarget const* headTarget,
           headTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
             lib.Target);
         std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
-        cmGeneratorExpression ge(lib.Backtrace);
+        cmGeneratorExpression ge(*headTarget->Makefile->GetCMakeInstance(),
+                                 lib.Backtrace);
         std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
         cge->SetEvaluateForBuildsystem(true);
 
@@ -4192,7 +4204,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
         }
         case cmPolicies::OLD: {
           std::unique_ptr<TargetPropertyEntry> entry =
-            CreateTargetPropertyEntry(*configProp);
+            CreateTargetPropertyEntry(
+              *this->LocalGenerator->GetCMakeInstance(), *configProp);
           entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
             this, config, language, &dagChecker, *entry));
         } break;
@@ -4778,8 +4791,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
   if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
     std::vector<std::string> options = cmExpandedList(*linkOptions);
     for (const auto& option : options) {
-      std::unique_ptr<TargetPropertyEntry> entry =
-        CreateTargetPropertyEntry(option);
+      std::unique_ptr<TargetPropertyEntry> entry = CreateTargetPropertyEntry(
+        *this->LocalGenerator->GetCMakeInstance(), option);
       entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
         this, config, language, &dagChecker, *entry));
     }
@@ -4931,8 +4944,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
   if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
     std::vector<std::string> depends = cmExpandedList(*linkDepends);
     for (const auto& depend : depends) {
-      std::unique_ptr<TargetPropertyEntry> entry =
-        CreateTargetPropertyEntry(depend);
+      std::unique_ptr<TargetPropertyEntry> entry = CreateTargetPropertyEntry(
+        *this->LocalGenerator->GetCMakeInstance(), depend);
       entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
         this, config, language, &dagChecker, *entry));
     }
@@ -6756,7 +6769,8 @@ void cmGeneratorTarget::ExpandLinkItems(
   cmMakefile const* mf = this->LocalGenerator->GetMakefile();
   LookupLinkItemScope scope{ this->LocalGenerator };
   for (BT<std::string> const& entry : entries) {
-    cmGeneratorExpression ge(entry.Backtrace);
+    cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(),
+                             entry.Backtrace);
     std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(entry.Value);
     cge->SetEvaluateForBuildsystem(true);
     std::vector<std::string> libs = cmExpandedList(
@@ -8195,7 +8209,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
           break;
       }
     }
-    cmGeneratorExpression ge(entry.Backtrace);
+    cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(),
+                             entry.Backtrace);
     std::unique_ptr<cmCompiledGeneratorExpression> const cge =
       ge.Parse(entry.Value);
     cge->SetEvaluateForBuildsystem(true);

+ 2 - 2
Source/cmInstalledFile.cxx

@@ -21,7 +21,7 @@ cmInstalledFile::Property::~Property() = default;
 void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
 {
   cmListFileBacktrace backtrace = mf->GetBacktrace();
-  cmGeneratorExpression ge(backtrace);
+  cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace);
 
   this->Name = name;
   this->NameExpression = ge.Parse(name);
@@ -56,7 +56,7 @@ void cmInstalledFile::AppendProperty(cmMakefile const* mf,
                                      bool /*asString*/)
 {
   cmListFileBacktrace backtrace = mf->GetBacktrace();
-  cmGeneratorExpression ge(backtrace);
+  cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace);
 
   Property& property = this->Properties[prop];
   property.ValueExpressions.push_back(ge.Parse(value));

+ 1 - 1
Source/cmLocalGenerator.cxx

@@ -4503,7 +4503,7 @@ std::vector<std::string> cmLocalGenerator::ExpandCustomCommandOutputGenex(
   std::string const& o, cmListFileBacktrace const& bt)
 {
   std::vector<std::string> allConfigOutputs;
-  cmGeneratorExpression ge(bt);
+  cmGeneratorExpression ge(*this->GetCMakeInstance(), bt);
   std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(o);
   std::vector<std::string> configs =
     this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);

+ 1 - 1
Source/cmLocalNinjaGenerator.cxx

@@ -701,7 +701,7 @@ bool cmLocalNinjaGenerator::HasUniqueByproducts(
 {
   std::vector<std::string> configs =
     this->GetMakefile()->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
-  cmGeneratorExpression ge(bt);
+  cmGeneratorExpression ge(*this->GetCMakeInstance(), bt);
   for (std::string const& p : byproducts) {
     if (cmGeneratorExpression::Find(p) == std::string::npos) {
       return false;

+ 14 - 1
Source/cmMakefile.cxx

@@ -376,7 +376,20 @@ public:
     this->Makefile->ExecutionStatusStack.push_back(&status);
 #if !defined(CMAKE_BOOTSTRAP)
     this->ProfilingDataRAII =
-      this->Makefile->GetCMakeInstance()->CreateProfilingEntry(lff, lfc);
+      this->Makefile->GetCMakeInstance()->CreateProfilingEntry(
+        "script", lff.LowerCaseName(), [&lff, &lfc]() -> Json::Value {
+          Json::Value argsValue = Json::objectValue;
+          if (!lff.Arguments().empty()) {
+            std::string args;
+            for (auto const& a : lff.Arguments()) {
+              args = cmStrCat(args, args.empty() ? "" : " ", a.Value);
+            }
+            argsValue["functionArgs"] = args;
+          }
+          argsValue["location"] =
+            cmStrCat(lfc.FilePath, ':', std::to_string(lfc.Line));
+          return argsValue;
+        });
 #endif
   }
 

+ 9 - 20
Source/cmMakefileProfilingData.cxx

@@ -6,9 +6,6 @@
 #include <stdexcept>
 #include <type_traits>
 #include <utility>
-#include <vector>
-
-#include <cm/utility>
 
 #include <cm3p/json/value.h>
 #include <cm3p/json/writer.h>
@@ -16,7 +13,6 @@
 #include "cmsys/FStream.hxx"
 #include "cmsys/SystemInformation.hxx"
 
-#include "cmListFileCache.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
@@ -47,22 +43,6 @@ cmMakefileProfilingData::~cmMakefileProfilingData() noexcept
   }
 }
 
-void cmMakefileProfilingData::StartEntry(const cmListFileFunction& lff,
-                                         cmListFileContext const& lfc)
-{
-  cm::optional<Json::Value> argsValue(cm::in_place, Json::objectValue);
-  if (!lff.Arguments().empty()) {
-    std::string args;
-    for (auto const& a : lff.Arguments()) {
-      args = cmStrCat(args, args.empty() ? "" : " ", a.Value);
-    }
-    (*argsValue)["functionArgs"] = args;
-  }
-  (*argsValue)["location"] =
-    cmStrCat(lfc.FilePath, ':', std::to_string(lfc.Line));
-  this->StartEntry("script", lff.LowerCaseName(), std::move(argsValue));
-}
-
 void cmMakefileProfilingData::StartEntry(const std::string& category,
                                          const std::string& name,
                                          cm::optional<Json::Value> args)
@@ -127,6 +107,15 @@ void cmMakefileProfilingData::StopEntry()
   }
 }
 
+cmMakefileProfilingData::RAII::RAII(cmMakefileProfilingData& data,
+                                    const std::string& category,
+                                    const std::string& name,
+                                    cm::optional<Json::Value> args)
+  : Data(&data)
+{
+  this->Data->StartEntry(category, name, std::move(args));
+}
+
 cmMakefileProfilingData::RAII::RAII(RAII&& other) noexcept
   : Data(other.Data)
 {

+ 3 - 11
Source/cmMakefileProfilingData.h

@@ -3,7 +3,6 @@
 #pragma once
 #include <memory>
 #include <string>
-#include <utility>
 
 #include <cm/optional>
 
@@ -15,15 +14,11 @@ namespace Json {
 class StreamWriter;
 }
 
-class cmListFileContext;
-class cmListFileFunction;
-
 class cmMakefileProfilingData
 {
 public:
   cmMakefileProfilingData(const std::string&);
   ~cmMakefileProfilingData() noexcept;
-  void StartEntry(const cmListFileFunction& lff, cmListFileContext const& lfc);
   void StartEntry(const std::string& category, const std::string& name,
                   cm::optional<Json::Value> args = cm::nullopt);
   void StopEntry();
@@ -35,12 +30,9 @@ public:
     RAII(const RAII&) = delete;
     RAII(RAII&&) noexcept;
 
-    template <typename... Args>
-    RAII(cmMakefileProfilingData& data, Args&&... args)
-      : Data(&data)
-    {
-      this->Data->StartEntry(std::forward<Args>(args)...);
-    }
+    RAII(cmMakefileProfilingData& data, const std::string& category,
+         const std::string& name,
+         cm::optional<Json::Value> args = cm::nullopt);
 
     ~RAII();
 

+ 1 - 1
Source/cmQtAutoGenInitializer.cxx

@@ -2095,7 +2095,7 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
       // Evaluate generator expression
       {
         cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
-        cmGeneratorExpression ge(lfbt);
+        cmGeneratorExpression ge(*this->Makefile->GetCMakeInstance(), lfbt);
         std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
         genVars.Executable = cge->Evaluate(this->LocalGen, "");
       }

+ 3 - 2
Source/cmTarget.cxx

@@ -2656,8 +2656,9 @@ cmFileSet* cmTarget::GetFileSet(const std::string& name)
 std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
   const std::string& name, const std::string& type, cmFileSetVisibility vis)
 {
-  auto result = this->impl->FileSets.emplace(
-    std::make_pair(name, cmFileSet(name, type, vis)));
+  auto result = this->impl->FileSets.emplace(std::make_pair(
+    name,
+    cmFileSet(*this->GetMakefile()->GetCMakeInstance(), name, type, vis)));
   if (result.second) {
     auto bt = this->impl->Makefile->GetBacktrace();
     if (type == this->impl->HeadersFileSets.TypeName) {

+ 2 - 1
Source/cmTestGenerator.cxx

@@ -127,7 +127,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
   this->TestGenerated = true;
 
   // Set up generator expression evaluation context.
-  cmGeneratorExpression ge(this->Test->GetBacktrace());
+  cmGeneratorExpression ge(*this->Test->GetMakefile()->GetCMakeInstance(),
+                           this->Test->GetBacktrace());
 
   // Determine if policy CMP0110 is set to NEW.
   const bool quote_test_name =

+ 5 - 5
Source/cmVisualStudio10TargetGenerator.cxx

@@ -2090,7 +2090,7 @@ void cmVisualStudio10TargetGenerator::ParseSettingsProperty(
   const std::string& settingsPropertyValue, ConfigToSettings& toolSettings)
 {
   if (!settingsPropertyValue.empty()) {
-    cmGeneratorExpression ge;
+    cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
 
     std::unique_ptr<cmCompiledGeneratorExpression> cge =
       ge.Parse(settingsPropertyValue);
@@ -2190,7 +2190,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
     }
     // Figure out if there's any additional flags to use
     if (cmValue saf = sf->GetProperty("VS_SHADER_FLAGS")) {
-      cmGeneratorExpression ge;
+      cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
       std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*saf);
 
       for (const std::string& config : this->Configurations) {
@@ -2203,7 +2203,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
     }
     // Figure out if debug information should be generated
     if (cmValue sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
-      cmGeneratorExpression ge;
+      cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
       std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*sed);
 
       for (const std::string& config : this->Configurations) {
@@ -2217,7 +2217,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
     }
     // Figure out if optimizations should be disabled
     if (cmValue sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
-      cmGeneratorExpression ge;
+      cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
       std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*sdo);
 
       for (const std::string& config : this->Configurations) {
@@ -2331,7 +2331,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
     this->FinishWritingSource(e2, toolSettings);
 
     if (!deployContent.empty()) {
-      cmGeneratorExpression ge;
+      cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
       std::unique_ptr<cmCompiledGeneratorExpression> cge =
         ge.Parse(deployContent);
       // Deployment location cannot be set on a configuration basis

+ 10 - 3
Source/cmake.h

@@ -638,13 +638,20 @@ public:
   cmMakefileProfilingData& GetProfilingOutput();
   bool IsProfilingEnabled() const;
 
-  template <typename... Args>
   cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
-    Args&&... args)
+    const std::string& category, const std::string& name)
+  {
+    return this->CreateProfilingEntry(
+      category, name, []() -> cm::nullopt_t { return cm::nullopt; });
+  }
+
+  template <typename ArgsFunc>
+  cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
+    const std::string& category, const std::string& name, ArgsFunc&& argsFunc)
   {
     if (this->IsProfilingEnabled()) {
       return cm::make_optional<cmMakefileProfilingData::RAII>(
-        this->GetProfilingOutput(), std::forward<Args>(args)...);
+        this->GetProfilingOutput(), category, name, argsFunc());
     }
     return cm::nullopt;
   }