diff options
author | Jon Chronopoulos <patches@crondog.com> | 2018-11-29 10:11:07 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2018-12-22 22:03:38 (GMT) |
commit | 25cae1e85d501c463141388e4eb580bdfae6ed2f (patch) | |
tree | 5028fc6c22c526e2b67a4539b6d0a7b69747b17a /Source/cmInstallScriptGenerator.cxx | |
parent | cb995ddea2d633310b270e99d020fe490fff5ec7 (diff) | |
download | CMake-25cae1e85d501c463141388e4eb580bdfae6ed2f.zip CMake-25cae1e85d501c463141388e4eb580bdfae6ed2f.tar.gz CMake-25cae1e85d501c463141388e4eb580bdfae6ed2f.tar.bz2 |
install: Teach CODE,SCRIPT modes to evaluate generator expressions
This also introduces CMP0087 which will keep the OLD behaviour of not
evaluating generator expressions
Fixes: #15785
Diffstat (limited to 'Source/cmInstallScriptGenerator.cxx')
-rw-r--r-- | Source/cmInstallScriptGenerator.cxx | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx index 7d77b7c..b93debb 100644 --- a/Source/cmInstallScriptGenerator.cxx +++ b/Source/cmInstallScriptGenerator.cxx @@ -2,11 +2,15 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallScriptGenerator.h" -#include "cmScriptGenerator.h" - #include <ostream> #include <vector> +#include "cmGeneratorExpression.h" +#include "cmLocalGenerator.h" +#include "cmPolicies.h" +#include "cmScriptGenerator.h" +#include "cmake.h" + cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script, bool code, const char* component, @@ -15,25 +19,71 @@ cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script, MessageDefault, exclude_from_all) , Script(script) , Code(code) + , AllowGenex(false) { + // We need per-config actions if the script has generator expressions. + if (cmGeneratorExpression::Find(Script) != std::string::npos) { + this->ActionsPerConfig = true; + } } cmInstallScriptGenerator::~cmInstallScriptGenerator() { } -void cmInstallScriptGenerator::GenerateScript(std::ostream& os) +void cmInstallScriptGenerator::Compute(cmLocalGenerator* lg) { - Indent indent; - std::string component_test = - this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll); - os << indent << "if(" << component_test << ")\n"; + this->LocalGenerator = lg; + if (this->ActionsPerConfig) { + switch (this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0087)) { + case cmPolicies::WARN: + this->LocalGenerator->IssueMessage( + cmake::AUTHOR_WARNING, + cmPolicies::GetPolicyWarning(cmPolicies::CMP0087)); + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + this->AllowGenex = true; + break; + } + } +} + +void cmInstallScriptGenerator::AddScriptInstallRule(std::ostream& os, + Indent indent, + std::string const& script) +{ if (this->Code) { - os << indent << this->Script << "\n"; + os << indent << script << "\n"; } else { - os << indent << "include(\"" << this->Script << "\")\n"; + os << indent << "include(\"" << script << "\")\n"; } +} - os << indent << "endif()\n\n"; +void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os, + Indent indent) +{ + if (this->AllowGenex && this->ActionsPerConfig) { + this->cmInstallGenerator::GenerateScriptActions(os, indent); + } else { + this->AddScriptInstallRule(os, indent, this->Script); + } +} + +void cmInstallScriptGenerator::GenerateScriptForConfig( + std::ostream& os, const std::string& config, Indent indent) +{ + if (this->AllowGenex) { + cmGeneratorExpression ge; + std::unique_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(this->Script); + this->AddScriptInstallRule(os, indent, + cge->Evaluate(this->LocalGenerator, config)); + } else { + this->AddScriptInstallRule(os, indent, this->Script); + } } |