diff options
author | Craig Scott <craig.scott@crascit.com> | 2018-12-23 22:19:31 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-12-23 22:19:57 (GMT) |
commit | 170fcebf2e866ce5266067716025a57c7e7e6ec4 (patch) | |
tree | 1a15da7e27a0b1ef1b73e2470772588347e7f5e2 /Source | |
parent | 2cc78b962331c776810b3bc15039813a1589cf4f (diff) | |
parent | 25cae1e85d501c463141388e4eb580bdfae6ed2f (diff) | |
download | CMake-170fcebf2e866ce5266067716025a57c7e7e6ec4.zip CMake-170fcebf2e866ce5266067716025a57c7e7e6ec4.tar.gz CMake-170fcebf2e866ce5266067716025a57c7e7e6ec4.tar.bz2 |
Merge topic 'install-code-script-genex'
25cae1e85d install: Teach CODE,SCRIPT modes to evaluate generator expressions
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2688
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmInstallScriptGenerator.cxx | 70 | ||||
-rw-r--r-- | Source/cmInstallScriptGenerator.h | 14 | ||||
-rw-r--r-- | Source/cmPolicies.h | 6 |
3 files changed, 78 insertions, 12 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); + } } diff --git a/Source/cmInstallScriptGenerator.h b/Source/cmInstallScriptGenerator.h index fe0f7c6..05199d7 100644 --- a/Source/cmInstallScriptGenerator.h +++ b/Source/cmInstallScriptGenerator.h @@ -6,10 +6,13 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmInstallGenerator.h" +#include "cmScriptGenerator.h" #include <iosfwd> #include <string> +class cmLocalGenerator; + /** \class cmInstallScriptGenerator * \brief Generate target installation rules. */ @@ -20,10 +23,19 @@ public: const char* component, bool exclude_from_all); ~cmInstallScriptGenerator() override; + void Compute(cmLocalGenerator* lg) override; + protected: - void GenerateScript(std::ostream& os) override; + void GenerateScriptActions(std::ostream& os, Indent indent) override; + void GenerateScriptForConfig(std::ostream& os, const std::string& config, + Indent indent) override; + void AddScriptInstallRule(std::ostream& os, Indent indent, + std::string const& script); + std::string Script; bool Code; + cmLocalGenerator* LocalGenerator; + bool AllowGenex; }; #endif diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 7674877..206dd3d 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -254,7 +254,11 @@ class cmMakefile; 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0086, \ "UseSWIG honors SWIG_MODULE_NAME via -module flag.", 3, 14, 0, \ - cmPolicies::WARN) + cmPolicies::WARN) \ + SELECT(POLICY, CMP0087, \ + "Install CODE|SCRIPT allow the use of generator " \ + "expressions.", \ + 3, 14, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ |