Coverage Report

Created: 2026-02-09 06:05

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 "cmInstallGenerator.h"
12
#include "cmInstallType.h"
13
#include "cmListFileCache.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(
24
    std::string targetName, std::string const& dest, bool implib,
25
    std::string file_permissions,
26
    std::vector<std::string> const& configurations,
27
    std::string const& component, MessageLevel message, bool exclude_from_all,
28
    bool optional, cmListFileBacktrace backtrace = cmListFileBacktrace());
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
0
  cmGeneratorTarget* GetTarget() const { return this->Target; }
66
67
0
  bool IsImportLibrary() const { return this->ImportLibrary; }
68
69
  std::string GetDestination(std::string const& config) const;
70
71
  struct Files
72
  {
73
    // Names or paths of files to be read from the source or build tree.
74
    // The paths may be computed as [FromDir/] + From[i].
75
    std::vector<std::string> From;
76
77
    // Corresponding names of files to be written in the install directory.
78
    // The paths may be computed as Destination/ + [ToDir/] + To[i].
79
    std::vector<std::string> To;
80
81
    // Prefix for all files in From.
82
    std::string FromDir;
83
84
    // Prefix for all files in To.
85
    std::string ToDir;
86
87
    NamelinkModeType NamelinkMode = NamelinkModeNone;
88
    bool Rename = false;
89
    bool NoTweak = false;
90
    bool UseSourcePermissions = false;
91
    cmInstallType Type = cmInstallType();
92
  };
93
  Files GetFiles(std::string const& config) const;
94
95
0
  bool GetOptional() const { return this->Optional; }
96
97
protected:
98
  void GenerateScriptForConfig(std::ostream& os, std::string const& config,
99
                               Indent indent) override;
100
  void PreReplacementTweaks(std::ostream& os, Indent indent,
101
                            std::string const& config,
102
                            std::string const& file);
103
  void PostReplacementTweaks(std::ostream& os, Indent indent,
104
                             std::string const& config,
105
                             std::string const& file);
106
  void AddInstallNamePatchRule(std::ostream& os, Indent indent,
107
                               std::string const& config,
108
                               std::string const& toDestDirPath);
109
  void AddChrpathPatchRule(std::ostream& os, Indent indent,
110
                           std::string const& config,
111
                           std::string const& toDestDirPath);
112
  void AddRPathCheckRule(std::ostream& os, Indent indent,
113
                         std::string const& config,
114
                         std::string const& toDestDirPath);
115
116
  void AddStripRule(std::ostream& os, Indent indent,
117
                    std::string const& toDestDirPath);
118
  void AddRanlibRule(std::ostream& os, Indent indent,
119
                     std::string const& toDestDirPath);
120
  void AddUniversalInstallRule(std::ostream& os, Indent indent,
121
                               std::string const& toDestDirPath);
122
  void IssueCMP0095Warning(std::string const& unescapedRpath);
123
124
  std::string const TargetName;
125
  cmGeneratorTarget* Target = nullptr;
126
  std::string const FilePermissions;
127
  NamelinkModeType NamelinkMode;
128
  NamelinkModeType ImportlinkMode;
129
  bool const ImportLibrary;
130
  bool const Optional;
131
};