From 026ef9b312047778ac0638cf2d2ef8bed6a2b3f2 Mon Sep 17 00:00:00 2001 From: Daniel Eiband Date: Wed, 11 Sep 2019 17:56:42 +0200 Subject: Refactoring: Use ConfigName instead of property CMAKE_BUILD_TYPE Use memorized `this->ConfigName` instead of retrieving the value of property CMAKE_BUILD_TYPE. --- Source/cmLocalUnixMakefileGenerator3.cxx | 8 +++----- Source/cmMakefileTargetGenerator.cxx | 28 +++++++++++----------------- Source/cmNinjaTargetGenerator.cxx | 13 ++++++------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index f80695d..0be1de5 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -161,8 +161,7 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( continue; } std::vector objectSources; - gt->GetObjectSources( - objectSources, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); + gt->GetObjectSources(objectSources, this->ConfigName); // Compute full path to object file directory for this target. std::string dir = cmStrCat(gt->LocalGenerator->GetCurrentBinaryDirectory(), '/', this->GetTargetDirectory(gt), '/'); @@ -1864,9 +1863,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo( << "_TARGET_INCLUDE_PATH\n"; std::vector includes; - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - this->GetIncludeDirectories(includes, target, implicitLang.first, config); + this->GetIncludeDirectories(includes, target, implicitLang.first, + this->ConfigName); std::string binaryDir = this->GetState()->GetBinaryDirectory(); if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) { std::string const& sourceDir = this->GetState()->GetSourceDirectory(); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 477badd..84e95ef 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -150,16 +150,13 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() { // -- Write the custom commands for this target - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - // Evaluates generator expressions and expands prop_value auto evaluatedFiles = - [this, &config](const char* prop_value) -> std::vector { + [this](const char* prop_value) -> std::vector { std::vector files; cmGeneratorExpression ge; std::unique_ptr cge = ge.Parse(prop_value); - cmExpandList(cge->Evaluate(this->LocalGenerator, config, false, + cmExpandList(cge->Evaluate(this->LocalGenerator, this->ConfigName, false, this->GeneratorTarget, nullptr, nullptr), files); return files; @@ -191,7 +188,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() // First generate the object rule files. Save a list of all object // files for this target. std::vector customCommands; - this->GeneratorTarget->GetCustomCommands(customCommands, config); + this->GeneratorTarget->GetCustomCommands(customCommands, this->ConfigName); std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); for (cmSourceFile const* sf : customCommands) { @@ -233,17 +230,17 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() } } std::vector headerSources; - this->GeneratorTarget->GetHeaderSources(headerSources, config); + this->GeneratorTarget->GetHeaderSources(headerSources, this->ConfigName); this->OSXBundleGenerator->GenerateMacOSXContentStatements( headerSources, this->MacOSXContentGenerator); std::vector extraSources; - this->GeneratorTarget->GetExtraSources(extraSources, config); + this->GeneratorTarget->GetExtraSources(extraSources, this->ConfigName); this->OSXBundleGenerator->GenerateMacOSXContentStatements( extraSources, this->MacOSXContentGenerator); const char* pchExtension = this->Makefile->GetDefinition("CMAKE_PCH_EXTENSION"); std::vector externalObjects; - this->GeneratorTarget->GetExternalObjects(externalObjects, config); + this->GeneratorTarget->GetExternalObjects(externalObjects, this->ConfigName); for (cmSourceFile const* sf : externalObjects) { auto const& objectFileName = sf->GetFullPath(); if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) { @@ -251,7 +248,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() } } std::vector objectSources; - this->GeneratorTarget->GetObjectSources(objectSources, config); + this->GeneratorTarget->GetObjectSources(objectSources, this->ConfigName); for (cmSourceFile const* sf : objectSources) { // Generate this object file's rule file. this->WriteObjectRuleFiles(*sf); @@ -1610,10 +1607,8 @@ void cmMakefileTargetGenerator::CreateLinkLibs( { std::string frameworkPath; std::string linkPath; - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmComputeLinkInformation* pcli = - this->GeneratorTarget->GetLinkInformation(config); + this->GeneratorTarget->GetLinkInformation(this->ConfigName); this->LocalGenerator->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, linkPath); linkLibs = frameworkPath + linkPath + linkLibs; @@ -1706,13 +1701,12 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags, bool useResponseFile = this->Makefile->IsOn(responseVar); std::vector includes; - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget, - lang, config); + lang, this->ConfigName); std::string includeFlags = this->LocalGenerator->GetIncludeFlags( - includes, this->GeneratorTarget, lang, false, useResponseFile, config); + includes, this->GeneratorTarget, lang, false, useResponseFile, + this->ConfigName); if (includeFlags.empty()) { return; } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 37e9e0e..84a98fd 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -777,11 +777,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) << " target " << this->GetTargetName() << "\n\n"; - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); { std::vector customCommands; - this->GeneratorTarget->GetCustomCommands(customCommands, config); + this->GeneratorTarget->GetCustomCommands(customCommands, this->ConfigName); for (cmSourceFile const* sf : customCommands) { cmCustomCommand const* cc = sf->GetCustomCommand(); this->GetLocalGenerator()->AddCustomCommandTarget( @@ -793,13 +791,13 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() } { std::vector headerSources; - this->GeneratorTarget->GetHeaderSources(headerSources, config); + this->GeneratorTarget->GetHeaderSources(headerSources, this->ConfigName); this->OSXBundleGenerator->GenerateMacOSXContentStatements( headerSources, this->MacOSXContentGenerator.get()); } { std::vector extraSources; - this->GeneratorTarget->GetExtraSources(extraSources, config); + this->GeneratorTarget->GetExtraSources(extraSources, this->ConfigName); this->OSXBundleGenerator->GenerateMacOSXContentStatements( extraSources, this->MacOSXContentGenerator.get()); } @@ -808,7 +806,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() GetMakefile()->GetDefinition("CMAKE_PCH_EXTENSION"); std::vector externalObjects; - this->GeneratorTarget->GetExternalObjects(externalObjects, config); + this->GeneratorTarget->GetExternalObjects(externalObjects, + this->ConfigName); for (cmSourceFile const* sf : externalObjects) { const auto objectFileName = this->GetSourceFilePath(sf); if (!cmSystemTools::StringEndsWith(objectFileName, pchExtension)) { @@ -863,7 +862,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() { std::vector objectSources; - this->GeneratorTarget->GetObjectSources(objectSources, config); + this->GeneratorTarget->GetObjectSources(objectSources, this->ConfigName); for (cmSourceFile const* sf : objectSources) { this->WriteObjectBuildStatement(sf); } -- cgit v0.12 From ccc9685cc1fb61242f179a02661730140b026253 Mon Sep 17 00:00:00 2001 From: Daniel Eiband Date: Wed, 11 Sep 2019 18:05:06 +0200 Subject: Genex: Move genex expansion of paths into AppendPaths utility Refactored internals of cmCustomCommandGenerator to make processing of path lists (evaluation of generator expressions and expansion into a list) available as AppendPaths utility function to be used for byproduct generator expression support. --- Source/cmCustomCommandGenerator.cxx | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 2c0cbfd..d5d7041 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -17,6 +17,26 @@ #include #include +namespace { +void AppendPaths(const std::vector& inputs, + cmGeneratorExpression& ge, cmLocalGenerator* lg, + std::string const& config, std::vector& output) +{ + for (std::string const& in : inputs) { + std::unique_ptr cge = ge.Parse(in); + std::vector result = + cmExpandedList(cge->Evaluate(lg, config)); + for (std::string& it : result) { + cmSystemTools::ConvertToUnixSlashes(it); + if (cmSystemTools::FileIsFullPath(it)) { + it = cmSystemTools::CollapseFullPath(it); + } + } + cmAppend(output, result); + } +} +} + cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, std::string config, cmLocalGenerator* lg) @@ -46,25 +66,14 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, // lists on an empty command may have left this empty. // FIXME: Should we define behavior for removing empty commands? if (argv.empty()) { - argv.push_back(std::string()); + argv.emplace_back(); } this->CommandLines.push_back(std::move(argv)); } - std::vector depends = this->CC.GetDepends(); - for (std::string const& d : depends) { - std::unique_ptr cge = this->GE->Parse(d); - std::vector result = - cmExpandedList(cge->Evaluate(this->LG, this->Config)); - for (std::string& it : result) { - cmSystemTools::ConvertToUnixSlashes(it); - if (cmSystemTools::FileIsFullPath(it)) { - it = cmSystemTools::CollapseFullPath(it); - } - } - cmAppend(this->Depends, result); - } + AppendPaths(cc.GetDepends(), *this->GE, this->LG, this->Config, + this->Depends); const std::string& workingdirectory = this->CC.GetWorkingDirectory(); if (!workingdirectory.empty()) { -- cgit v0.12 From a583b7bc17b30c7772d6ca1909c71c0c14e6fabb Mon Sep 17 00:00:00 2001 From: Daniel Eiband Date: Wed, 11 Sep 2019 18:18:47 +0200 Subject: Genex: Evaluate byproduct generator expressions in cmCustomCommandGenerator Evaluate and expand generator expressions in byproducts of custom commands. Note that it is still not possible to use generator expressions in byproducts of the commands `add_custom_command` and `add_custom_target`. These commands still reject the input. This is a preparation step for OUTPUT generator expression support. Issue: #12877 --- Source/cmCustomCommandGenerator.cxx | 4 +++- Source/cmCustomCommandGenerator.h | 1 + Source/cmMakefileTargetGenerator.cxx | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index d5d7041..ddb855b 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -72,6 +72,8 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, this->CommandLines.push_back(std::move(argv)); } + AppendPaths(cc.GetByproducts(), *this->GE, this->LG, this->Config, + this->Byproducts); AppendPaths(cc.GetDepends(), *this->GE, this->LG, this->Config, this->Depends); @@ -248,7 +250,7 @@ std::vector const& cmCustomCommandGenerator::GetOutputs() const std::vector const& cmCustomCommandGenerator::GetByproducts() const { - return this->CC.GetByproducts(); + return this->Byproducts; } std::vector const& cmCustomCommandGenerator::GetDepends() const diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index 766f4b8..d614302 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -23,6 +23,7 @@ class cmCustomCommandGenerator cmGeneratorExpression* GE; cmCustomCommandLines CommandLines; std::vector> EmulatorsWithArguments; + std::vector Byproducts; std::vector Depends; std::string WorkingDirectory; diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 84e95ef..482af22 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -221,7 +221,8 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() this->GeneratorTarget->GetPostBuildCommands()); for (const auto& be : buildEventCommands) { - const std::vector& byproducts = be.GetByproducts(); + cmCustomCommandGenerator beg(be, this->ConfigName, this->LocalGenerator); + const std::vector& byproducts = beg.GetByproducts(); for (std::string const& byproduct : byproducts) { this->CleanFiles.insert( this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, -- cgit v0.12