Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmInstallImportedRuntimeArtifactsGenerator.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 "cmInstallImportedRuntimeArtifactsGenerator.h"
4
5
#include <string>
6
#include <utility>
7
#include <vector>
8
9
#include "cmsys/RegularExpression.hxx"
10
11
#include "cmGeneratorExpression.h"
12
#include "cmGeneratorTarget.h"
13
#include "cmGlobalGenerator.h"
14
#include "cmInstallType.h"
15
#include "cmLocalGenerator.h"
16
#include "cmStringAlgorithms.h"
17
#include "cmTargetTypes.h"
18
#include "cmUnreachable.h"
19
20
namespace {
21
cmsys::RegularExpression const FrameworkRegularExpression(
22
  "^(.*/)?([^/]*)\\.framework/(.*)$");
23
24
cmsys::RegularExpression const BundleRegularExpression(
25
  "^(.*/)?([^/]*)\\.app/(.*)$");
26
27
cmsys::RegularExpression const CFBundleRegularExpression(
28
  "^(.*/)?([^/]*)\\.bundle/(.*)$");
29
}
30
31
cmInstallImportedRuntimeArtifactsGenerator::
32
  cmInstallImportedRuntimeArtifactsGenerator(
33
    std::string targetName, std::string const& dest,
34
    std::string filePermissions,
35
    std::vector<std::string> const& configurations,
36
    std::string const& component, MessageLevel message, bool excludeFromAll,
37
    bool optional, cmDiagnosticContext context)
38
0
  : cmInstallGenerator(dest, configurations, component, message,
39
0
                       excludeFromAll, false, std::move(context))
40
0
  , TargetName(std::move(targetName))
41
0
  , FilePermissions(std::move(filePermissions))
42
0
  , Optional(optional)
43
0
{
44
0
  this->ActionsPerConfig = true;
45
0
}
46
47
bool cmInstallImportedRuntimeArtifactsGenerator::Compute(cmLocalGenerator* lg)
48
0
{
49
  // Lookup this target in the current directory.
50
0
  this->Target = lg->FindGeneratorTargetToUse(this->TargetName);
51
0
  if (!this->Target || !this->Target->IsImported()) {
52
    // If no local target has been found, find it in the global scope.
53
0
    this->Target =
54
0
      lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
55
0
  }
56
57
0
  return true;
58
0
}
59
60
void cmInstallImportedRuntimeArtifactsGenerator::GetInstallBuildDependencies(
61
  std::string const&, std::vector<BuildDependency>& dependencies) const
62
0
{
63
0
  dependencies.push_back({ this->Target, BuildDependencyType::Normal });
64
0
}
65
66
std::string cmInstallImportedRuntimeArtifactsGenerator::GetDestination(
67
  std::string const& config) const
68
0
{
69
0
  std::string dest = cmGeneratorExpression::Evaluate(
70
0
    this->Destination, this->Target->GetLocalGenerator(), config);
71
0
  this->CheckAbsoluteDestination(dest, this->Target->GetLocalGenerator());
72
0
  return dest;
73
0
}
74
75
void cmInstallImportedRuntimeArtifactsGenerator::GenerateScriptForConfig(
76
  std::ostream& os, std::string const& config, Indent indent)
77
0
{
78
0
  auto location = this->Target->GetFullPath(config);
79
80
0
  switch (this->Target->GetType()) {
81
0
    case cm::TargetType::EXECUTABLE:
82
0
      if (this->Target->IsBundleOnApple()) {
83
0
        cmsys::RegularExpressionMatch match;
84
0
        if (BundleRegularExpression.find(location.c_str(), match)) {
85
0
          auto bundleDir = match.match(1);
86
0
          auto bundleName = match.match(2);
87
0
          auto bundlePath = cmStrCat(bundleDir, bundleName, ".app");
88
0
          this->AddInstallRule(os, this->GetDestination(config),
89
0
                               cmInstallType_DIRECTORY, { bundlePath },
90
0
                               this->Optional, nullptr,
91
0
                               this->FilePermissions.c_str(), nullptr,
92
0
                               " USE_SOURCE_PERMISSIONS", indent);
93
0
        }
94
0
      } else {
95
0
        this->AddInstallRule(os, this->GetDestination(config),
96
0
                             cmInstallType_EXECUTABLE, { location },
97
0
                             this->Optional, this->FilePermissions.c_str(),
98
0
                             nullptr, nullptr, nullptr, indent);
99
0
      }
100
0
      break;
101
0
    case cm::TargetType::SHARED_LIBRARY:
102
0
      if (this->Target->IsFrameworkOnApple()) {
103
0
        cmsys::RegularExpressionMatch match;
104
0
        if (FrameworkRegularExpression.find(location.c_str(), match)) {
105
0
          auto frameworkDir = match.match(1);
106
0
          auto frameworkName = match.match(2);
107
0
          auto frameworkPath =
108
0
            cmStrCat(frameworkDir, frameworkName, ".framework");
109
0
          this->AddInstallRule(os, this->GetDestination(config),
110
0
                               cmInstallType_DIRECTORY, { frameworkPath },
111
0
                               this->Optional, nullptr,
112
0
                               this->FilePermissions.c_str(), nullptr,
113
0
                               " USE_SOURCE_PERMISSIONS", indent);
114
0
        }
115
0
      } else {
116
0
        std::vector<std::string> files{ location };
117
0
        if (!this->Target->IsArchivedAIXSharedLibrary()) {
118
0
          auto soName = this->Target->GetSOName(config);
119
0
          auto soNameFile =
120
0
            cmStrCat(this->Target->GetDirectory(config), '/', soName);
121
0
          if (!soName.empty() && soNameFile != location) {
122
0
            files.push_back(soNameFile);
123
0
          }
124
0
        }
125
0
        this->AddInstallRule(os, this->GetDestination(config),
126
0
                             cmInstallType_SHARED_LIBRARY, files,
127
0
                             this->Optional, this->FilePermissions.c_str(),
128
0
                             nullptr, nullptr, nullptr, indent);
129
0
      }
130
0
      break;
131
0
    case cm::TargetType::MODULE_LIBRARY:
132
0
      if (this->Target->IsCFBundleOnApple()) {
133
0
        cmsys::RegularExpressionMatch match;
134
0
        if (CFBundleRegularExpression.find(location.c_str(), match)) {
135
0
          auto bundleDir = match.match(1);
136
0
          auto bundleName = match.match(2);
137
0
          auto bundlePath = cmStrCat(bundleDir, bundleName, ".bundle");
138
0
          this->AddInstallRule(os, this->GetDestination(config),
139
0
                               cmInstallType_DIRECTORY, { bundlePath },
140
0
                               this->Optional, nullptr,
141
0
                               this->FilePermissions.c_str(), nullptr,
142
0
                               " USE_SOURCE_PERMISSIONS", indent);
143
0
        }
144
0
      } else {
145
0
        this->AddInstallRule(os, this->GetDestination(config),
146
0
                             cmInstallType_MODULE_LIBRARY, { location },
147
0
                             this->Optional, this->FilePermissions.c_str(),
148
0
                             nullptr, nullptr, nullptr, indent);
149
0
      }
150
0
      break;
151
0
    default:
152
0
      CM_UNREACHABLE;
153
0
      break;
154
0
  }
155
0
}