Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmInstallTargetGenerator.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 <iosfwd>
8
#include <string>
9
#include <vector>
10
11
#include "cmDiagnosticContext.h"
12
#include "cmInstallGenerator.h"
13
#include "cmInstallType.h"
14
15
class cmGeneratorTarget;
16
17
/** \class cmInstallTargetGenerator
18
 * \brief Generate target installation rules.
19
 */
20
class cmInstallTargetGenerator : public cmInstallGenerator
21
{
22
public:
23
  cmInstallTargetGenerator(std::string targetName, std::string const& dest,
24
                           bool implib, std::string filePermissions,
25
                           std::vector<std::string> const& configurations,
26
                           std::string const& component, MessageLevel message,
27
                           bool excludeFromAll, bool optional,
28
                           cmDiagnosticContext context = {});
29
  ~cmInstallTargetGenerator() override;
30
31
  /** Select the policy for installing shared library linkable name
32
      symlinks.  */
33
  enum NamelinkModeType
34
  {
35
    NamelinkModeNone,
36
    NamelinkModeOnly,
37
    NamelinkModeSkip
38
  };
39
0
  void SetNamelinkMode(NamelinkModeType mode) { this->NamelinkMode = mode; }
40
  void SetImportlinkMode(NamelinkModeType mode)
41
0
  {
42
0
    this->ImportlinkMode = mode;
43
0
  }
44
45
  std::string GetInstallFilename(std::string const& config) const;
46
47
  void GetInstallObjectNames(std::string const& config,
48
                             std::vector<std::string>& objects) const;
49
50
  enum NameType
51
  {
52
    NameNormal,
53
    NameImplib,
54
    NameSO,
55
    NameReal,
56
    NameImplibReal
57
  };
58
59
  static std::string GetInstallFilename(cmGeneratorTarget const* target,
60
                                        std::string const& config,
61
                                        NameType nameType = NameNormal);
62
63
  bool Compute(cmLocalGenerator* lg) override;
64
65
  void GetInstallBuildDependencies(
66
    std::string const& config,
67
    std::vector<BuildDependency>& dependencies) const override;
68
69
0
  cmGeneratorTarget* GetTarget() const { return this->Target; }
70
71
0
  bool IsImportLibrary() const { return this->ImportLibrary; }
72
73
  std::string GetDestination(std::string const& config) const;
74
75
  struct Files
76
  {
77
    // Names or paths of files to be read from the source or build tree.
78
    // The paths may be computed as [FromDir/] + From[i].
79
    std::vector<std::string> From;
80
81
    // Corresponding names of files to be written in the install directory.
82
    // The paths may be computed as Destination/ + [ToDir/] + To[i].
83
    std::vector<std::string> To;
84
85
    // Prefix for all files in From.
86
    std::string FromDir;
87
88
    // Prefix for all files in To.
89
    std::string ToDir;
90
91
    NamelinkModeType NamelinkMode = NamelinkModeNone;
92
    bool Rename = false;
93
    bool NoTweak = false;
94
    bool UseSourcePermissions = false;
95
    cmInstallType Type = cmInstallType();
96
  };
97
  Files GetFiles(std::string const& config) const;
98
99
0
  bool GetOptional() const { return this->Optional; }
100
101
protected:
102
  void GenerateScriptForConfig(std::ostream& os, std::string const& config,
103
                               Indent indent) override;
104
  void PreReplacementTweaks(std::ostream& os, Indent indent,
105
                            std::string const& config,
106
                            std::string const& file);
107
  void PostReplacementTweaks(std::ostream& os, Indent indent,
108
                             std::string const& config,
109
                             std::string const& file);
110
  void AddInstallNamePatchRule(std::ostream& os, Indent indent,
111
                               std::string const& config,
112
                               std::string const& toDestDirPath);
113
  void AddChrpathPatchRule(std::ostream& os, Indent indent,
114
                           std::string const& config,
115
                           std::string const& toDestDirPath);
116
  void AddRPathCheckRule(std::ostream& os, Indent indent,
117
                         std::string const& config,
118
                         std::string const& toDestDirPath);
119
120
  void AddStripRule(std::ostream& os, Indent indent,
121
                    std::string const& toDestDirPath);
122
  void AddRanlibRule(std::ostream& os, Indent indent,
123
                     std::string const& toDestDirPath);
124
  void AddUniversalInstallRule(std::ostream& os, Indent indent,
125
                               std::string const& toDestDirPath);
126
  void IssueCMP0095Warning(std::string const& unescapedRpath);
127
128
  std::string const TargetName;
129
  cmGeneratorTarget* Target = nullptr;
130
  std::string const FilePermissions;
131
  NamelinkModeType NamelinkMode;
132
  NamelinkModeType ImportlinkMode;
133
  bool const ImportLibrary;
134
  bool const Optional;
135
};