/src/CMake/Source/cmInstallScriptGenerator.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmInstallScriptGenerator.h" |
4 | | |
5 | | #include <ostream> |
6 | | #include <utility> |
7 | | #include <vector> |
8 | | |
9 | | #include "cmDiagnosticContext.h" |
10 | | #include "cmGeneratorExpression.h" |
11 | | #include "cmLocalGenerator.h" |
12 | | #include "cmPolicies.h" |
13 | | #include "cmScriptGenerator.h" |
14 | | |
15 | | cmInstallScriptGenerator::cmInstallScriptGenerator( |
16 | | std::string script, bool code, std::string const& component, |
17 | | bool excludeFromAll, bool allComponents, cmListFileBacktrace backtrace) |
18 | 0 | : cmInstallGenerator("", std::vector<std::string>(), component, |
19 | 0 | MessageDefault, excludeFromAll, allComponents, |
20 | 0 | cmDiagnosticContext{ std::move(backtrace) }) |
21 | 0 | , Script(std::move(script)) |
22 | 0 | , Code(code) |
23 | 0 | { |
24 | | // We need per-config actions if the script has generator expressions. |
25 | 0 | if (cmGeneratorExpression::Find(this->Script) != std::string::npos) { |
26 | 0 | this->ActionsPerConfig = true; |
27 | 0 | } |
28 | 0 | } |
29 | | |
30 | 0 | cmInstallScriptGenerator::~cmInstallScriptGenerator() = default; |
31 | | |
32 | | bool cmInstallScriptGenerator::Compute(cmLocalGenerator* lg) |
33 | 0 | { |
34 | 0 | this->LocalGenerator = lg; |
35 | |
|
36 | 0 | if (this->ActionsPerConfig) { |
37 | 0 | switch (this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0087)) { |
38 | 0 | case cmPolicies::WARN: |
39 | 0 | this->LocalGenerator->IssuePolicyWarning(cmPolicies::CMP0087); |
40 | 0 | CM_FALLTHROUGH; |
41 | 0 | case cmPolicies::OLD: |
42 | 0 | break; |
43 | 0 | case cmPolicies::NEW: |
44 | 0 | this->AllowGenex = true; |
45 | 0 | break; |
46 | 0 | } |
47 | 0 | } |
48 | | |
49 | 0 | return true; |
50 | 0 | } |
51 | | |
52 | | std::string cmInstallScriptGenerator::GetScript( |
53 | | std::string const& config) const |
54 | 0 | { |
55 | 0 | std::string script = this->Script; |
56 | 0 | if (this->AllowGenex && this->ActionsPerConfig) { |
57 | 0 | cmGeneratorExpression::ReplaceInstallPrefix(script, |
58 | 0 | "${CMAKE_INSTALL_PREFIX}"); |
59 | 0 | script = |
60 | 0 | cmGeneratorExpression::Evaluate(script, this->LocalGenerator, config); |
61 | 0 | } |
62 | 0 | return script; |
63 | 0 | } |
64 | | |
65 | | void cmInstallScriptGenerator::AddScriptInstallRule( |
66 | | std::ostream& os, Indent indent, std::string const& script) const |
67 | 0 | { |
68 | 0 | if (this->Code) { |
69 | 0 | os << indent << script << "\n"; |
70 | 0 | } else { |
71 | 0 | os << indent << "include(\"" << script << "\")\n"; |
72 | 0 | } |
73 | 0 | } |
74 | | |
75 | | void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os, |
76 | | Indent indent) |
77 | 0 | { |
78 | 0 | if (this->AllowGenex && this->ActionsPerConfig) { |
79 | 0 | this->cmInstallGenerator::GenerateScriptActions(os, indent); |
80 | 0 | } else { |
81 | 0 | this->AddScriptInstallRule(os, indent, this->Script); |
82 | 0 | } |
83 | 0 | } |
84 | | |
85 | | void cmInstallScriptGenerator::GenerateScriptForConfig( |
86 | | std::ostream& os, std::string const& config, Indent indent) |
87 | 0 | { |
88 | 0 | this->AddScriptInstallRule(os, indent, this->GetScript(config)); |
89 | 0 | } |