/src/CMake/Source/cmInstallGenerator.h
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 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <functional> |
8 | | #include <iosfwd> |
9 | | #include <string> |
10 | | #include <vector> |
11 | | |
12 | | #include "cmDiagnosticContext.h" |
13 | | #include "cmInstallType.h" |
14 | | #include "cmScriptGenerator.h" |
15 | | |
16 | | class cmLocalGenerator; |
17 | | class cmMakefile; |
18 | | class cmListFileBacktrace; |
19 | | |
20 | | /** \class cmInstallGenerator |
21 | | * \brief Support class for generating install scripts. |
22 | | * |
23 | | */ |
24 | | class cmInstallGenerator : public cmScriptGenerator |
25 | | { |
26 | | public: |
27 | | enum MessageLevel |
28 | | { |
29 | | MessageDefault, |
30 | | MessageAlways, |
31 | | MessageLazy, |
32 | | MessageNever |
33 | | }; |
34 | | |
35 | | cmInstallGenerator(std::string destination, |
36 | | std::vector<std::string> const& configurations, |
37 | | std::string component, MessageLevel message, |
38 | | bool excludeFromAll, bool allComponents, |
39 | | cmDiagnosticContext context); |
40 | | ~cmInstallGenerator() override; |
41 | | |
42 | | cmInstallGenerator(cmInstallGenerator const&) = delete; |
43 | | cmInstallGenerator& operator=(cmInstallGenerator const&) = delete; |
44 | | |
45 | | virtual bool HaveInstall(); |
46 | | virtual void CheckCMP0082(bool& haveSubdirectoryInstall, |
47 | | bool& haveInstallAfterSubdirectory); |
48 | | |
49 | | void AddInstallRule( |
50 | | std::ostream& os, std::string const& dest, cmInstallType type, |
51 | | std::vector<std::string> const& files, bool optional = false, |
52 | | char const* permissionsFile = nullptr, |
53 | | char const* permissionsDir = nullptr, char const* rename = nullptr, |
54 | | char const* literalArgs = nullptr, Indent indent = Indent(), |
55 | | char const* filesVar = nullptr); |
56 | | |
57 | | /** Get the install destination as it should appear in the |
58 | | installation script. */ |
59 | | static std::string ConvertToAbsoluteDestination(std::string const& dest); |
60 | | void CheckAbsoluteDestination(std::string const& dest, |
61 | | cmLocalGenerator* lg) const; |
62 | | |
63 | | /** Test if this generator installs something for a given configuration. */ |
64 | | bool InstallsForConfig(std::string const& config); |
65 | | |
66 | | /** Select message level from CMAKE_INSTALL_MESSAGE or 'never'. */ |
67 | | static MessageLevel SelectMessageLevel(cmMakefile* mf, bool never = false); |
68 | | |
69 | | /** Capture context for generator. */ |
70 | | static cmDiagnosticContext CaptureContext(cmMakefile const& mf); |
71 | | static cmDiagnosticContext CaptureContext(cmMakefile const* mf) |
72 | 0 | { |
73 | 0 | return cmInstallGenerator::CaptureContext(*mf); |
74 | 0 | } |
75 | | |
76 | 0 | virtual bool Compute(cmLocalGenerator*) { return true; } |
77 | | |
78 | 0 | std::string const& GetComponent() const { return this->Component; } |
79 | | |
80 | 0 | bool GetExcludeFromAll() const { return this->ExcludeFromAll; } |
81 | 0 | bool GetAllComponentsFlag() const { return this->AllComponents; } |
82 | | |
83 | | cmListFileBacktrace const& GetBacktrace() const |
84 | 0 | { |
85 | 0 | return this->Context.GetBacktrace(); |
86 | 0 | } |
87 | | |
88 | | static std::string GetDestDirPath(std::string const& file); |
89 | | |
90 | | protected: |
91 | | void GenerateScript(std::ostream& os) override; |
92 | | |
93 | | std::string CreateComponentTest(std::string const& component, |
94 | | bool excludeFromAll, |
95 | | bool allComponents = false); |
96 | | |
97 | | using TweakMethod = |
98 | | std::function<void(std::ostream& os, Indent indent, |
99 | | std::string const& config, std::string const& file)>; |
100 | | static void AddTweak(std::ostream& os, Indent indent, |
101 | | std::string const& config, std::string const& file, |
102 | | TweakMethod const& tweak); |
103 | | static void AddTweak(std::ostream& os, Indent indent, |
104 | | std::string const& config, std::string const& dir, |
105 | | std::vector<std::string> const& files, |
106 | | TweakMethod const& tweak); |
107 | | |
108 | | // Information shared by most generator types. |
109 | | std::string Destination; |
110 | | std::string const Component; |
111 | | MessageLevel const Message; |
112 | | bool const ExcludeFromAll; |
113 | | bool const AllComponents; |
114 | | cmDiagnosticContext const Context; |
115 | | }; |