/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, |
18 | | std::vector<std::string> buildDepends, cmListFileBacktrace backtrace) |
19 | 0 | : cmInstallGenerator("", std::vector<std::string>(), component, |
20 | 0 | MessageDefault, excludeFromAll, allComponents, |
21 | 0 | cmDiagnosticContext{ std::move(backtrace) }) |
22 | 0 | , Script(std::move(script)) |
23 | 0 | , Code(code) |
24 | 0 | , BuildDepends(std::move(buildDepends)) |
25 | 0 | { |
26 | | // We need per-config actions if the script has generator expressions. |
27 | 0 | if (cmGeneratorExpression::Find(this->Script) != std::string::npos) { |
28 | 0 | this->ActionsPerConfig = true; |
29 | 0 | } |
30 | 0 | } |
31 | | |
32 | 0 | cmInstallScriptGenerator::~cmInstallScriptGenerator() = default; |
33 | | |
34 | | bool cmInstallScriptGenerator::Compute(cmLocalGenerator* lg) |
35 | 0 | { |
36 | 0 | this->LocalGenerator = lg; |
37 | 0 | if (!this->ResolveBuildDepends(lg, this->Code ? "CODE" : "SCRIPT", |
38 | 0 | this->BuildDepends, |
39 | 0 | this->ResolvedBuildDepends)) { |
40 | 0 | return false; |
41 | 0 | } |
42 | | |
43 | 0 | if (this->ActionsPerConfig) { |
44 | 0 | switch (this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0087)) { |
45 | 0 | case cmPolicies::WARN: |
46 | 0 | this->LocalGenerator->IssuePolicyWarning(cmPolicies::CMP0087); |
47 | 0 | CM_FALLTHROUGH; |
48 | 0 | case cmPolicies::OLD: |
49 | 0 | break; |
50 | 0 | case cmPolicies::NEW: |
51 | 0 | this->AllowGenex = true; |
52 | 0 | break; |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | 0 | return true; |
57 | 0 | } |
58 | | |
59 | | void cmInstallScriptGenerator::GetInstallBuildDependencies( |
60 | | std::string const& config, std::vector<BuildDependency>& dependencies) const |
61 | 0 | { |
62 | 0 | AddBuildDependsDependencies(this->LocalGenerator, config, |
63 | 0 | this->ResolvedBuildDepends, dependencies); |
64 | 0 | } |
65 | | |
66 | | std::string cmInstallScriptGenerator::GetScript( |
67 | | std::string const& config) const |
68 | 0 | { |
69 | 0 | std::string script = this->Script; |
70 | 0 | if (this->AllowGenex && this->ActionsPerConfig) { |
71 | 0 | cmGeneratorExpression::ReplaceInstallPrefix(script, |
72 | 0 | "${CMAKE_INSTALL_PREFIX}"); |
73 | 0 | script = |
74 | 0 | cmGeneratorExpression::Evaluate(script, this->LocalGenerator, config); |
75 | 0 | } |
76 | 0 | return script; |
77 | 0 | } |
78 | | |
79 | | void cmInstallScriptGenerator::AddScriptInstallRule( |
80 | | std::ostream& os, Indent indent, std::string const& script) const |
81 | 0 | { |
82 | 0 | if (this->Code) { |
83 | 0 | os << indent << script << "\n"; |
84 | 0 | } else { |
85 | 0 | os << indent << "include(\"" << script << "\")\n"; |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os, |
90 | | Indent indent) |
91 | 0 | { |
92 | 0 | if (this->AllowGenex && this->ActionsPerConfig) { |
93 | 0 | this->cmInstallGenerator::GenerateScriptActions(os, indent); |
94 | 0 | } else { |
95 | 0 | this->AddScriptInstallRule(os, indent, this->Script); |
96 | 0 | } |
97 | 0 | } |
98 | | |
99 | | void cmInstallScriptGenerator::GenerateScriptForConfig( |
100 | | std::ostream& os, std::string const& config, Indent indent) |
101 | 0 | { |
102 | 0 | this->AddScriptInstallRule(os, indent, this->GetScript(config)); |
103 | 0 | } |