Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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 "cmInstallType.h"
13
#include "cmListFileCache.h"
14
#include "cmScriptGenerator.h"
15
16
class cmLocalGenerator;
17
class cmMakefile;
18
19
/** \class cmInstallGenerator
20
 * \brief Support class for generating install scripts.
21
 *
22
 */
23
class cmInstallGenerator : public cmScriptGenerator
24
{
25
public:
26
  enum MessageLevel
27
  {
28
    MessageDefault,
29
    MessageAlways,
30
    MessageLazy,
31
    MessageNever
32
  };
33
34
  cmInstallGenerator(std::string destination,
35
                     std::vector<std::string> const& configurations,
36
                     std::string component, MessageLevel message,
37
                     bool exclude_from_all, bool all_components,
38
                     cmListFileBacktrace backtrace);
39
  ~cmInstallGenerator() override;
40
41
  cmInstallGenerator(cmInstallGenerator const&) = delete;
42
  cmInstallGenerator& operator=(cmInstallGenerator const&) = delete;
43
44
  virtual bool HaveInstall();
45
  virtual void CheckCMP0082(bool& haveSubdirectoryInstall,
46
                            bool& haveInstallAfterSubdirectory);
47
48
  void AddInstallRule(
49
    std::ostream& os, std::string const& dest, cmInstallType type,
50
    std::vector<std::string> const& files, bool optional = false,
51
    char const* permissions_file = nullptr,
52
    char const* permissions_dir = nullptr, char const* rename = nullptr,
53
    char const* literal_args = nullptr, Indent indent = Indent(),
54
    char const* files_var = nullptr);
55
56
  /** Get the install destination as it should appear in the
57
      installation script.  */
58
  static std::string ConvertToAbsoluteDestination(std::string const& dest);
59
60
  /** Test if this generator installs something for a given configuration.  */
61
  bool InstallsForConfig(std::string const& config);
62
63
  /** Select message level from CMAKE_INSTALL_MESSAGE or 'never'.  */
64
  static MessageLevel SelectMessageLevel(cmMakefile* mf, bool never = false);
65
66
0
  virtual bool Compute(cmLocalGenerator*) { return true; }
67
68
0
  std::string const& GetComponent() const { return this->Component; }
69
70
0
  bool GetExcludeFromAll() const { return this->ExcludeFromAll; }
71
0
  bool GetAllComponentsFlag() const { return this->AllComponents; }
72
73
0
  cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; }
74
75
  static std::string GetDestDirPath(std::string const& file);
76
77
protected:
78
  void GenerateScript(std::ostream& os) override;
79
80
  std::string CreateComponentTest(std::string const& component,
81
                                  bool exclude_from_all,
82
                                  bool all_components = false);
83
84
  using TweakMethod =
85
    std::function<void(std::ostream& os, Indent indent,
86
                       std::string const& config, std::string const& file)>;
87
  static void AddTweak(std::ostream& os, Indent indent,
88
                       std::string const& config, std::string const& file,
89
                       TweakMethod const& tweak);
90
  static void AddTweak(std::ostream& os, Indent indent,
91
                       std::string const& config, std::string const& dir,
92
                       std::vector<std::string> const& files,
93
                       TweakMethod const& tweak);
94
95
  // Information shared by most generator types.
96
  std::string Destination;
97
  std::string const Component;
98
  MessageLevel const Message;
99
  bool const ExcludeFromAll;
100
  bool const AllComponents;
101
  cmListFileBacktrace const Backtrace;
102
};