Coverage Report

Created: 2026-06-15 07:03

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 <cassert>
6
#include <string>
7
#include <utility>
8
#include <vector>
9
10
#include "cmsys/RegularExpression.hxx"
11
12
#include "cmGeneratorExpression.h"
13
#include "cmGeneratorTarget.h"
14
#include "cmGlobalGenerator.h"
15
#include "cmInstallType.h"
16
#include "cmLocalGenerator.h"
17
#include "cmStateTypes.h"
18
#include "cmStringAlgorithms.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
std::string cmInstallImportedRuntimeArtifactsGenerator::GetDestination(
61
  std::string const& config) const
62
0
{
63
0
  std::string dest = cmGeneratorExpression::Evaluate(
64
0
    this->Destination, this->Target->GetLocalGenerator(), config);
65
0
  this->CheckAbsoluteDestination(dest, this->Target->GetLocalGenerator());
66
0
  return dest;
67
0
}
68
69
void cmInstallImportedRuntimeArtifactsGenerator::GenerateScriptForConfig(
70
  std::ostream& os, std::string const& config, Indent indent)
71
0
{
72
0
  auto location = this->Target->GetFullPath(config);
73
74
0
  switch (this->Target->GetType()) {
75
0
    case cmStateEnums::EXECUTABLE:
76
0
      if (this->Target->IsBundleOnApple()) {
77
0
        cmsys::RegularExpressionMatch match;
78
0
        if (BundleRegularExpression.find(location.c_str(), match)) {
79
0
          auto bundleDir = match.match(1);
80
0
          auto bundleName = match.match(2);
81
0
          auto bundlePath = cmStrCat(bundleDir, bundleName, ".app");
82
0
          this->AddInstallRule(os, this->GetDestination(config),
83
0
                               cmInstallType_DIRECTORY, { bundlePath },
84
0
                               this->Optional, nullptr,
85
0
                               this->FilePermissions.c_str(), nullptr,
86
0
                               " USE_SOURCE_PERMISSIONS", indent);
87
0
        }
88
0
      } else {
89
0
        this->AddInstallRule(os, this->GetDestination(config),
90
0
                             cmInstallType_EXECUTABLE, { location },
91
0
                             this->Optional, this->FilePermissions.c_str(),
92
0
                             nullptr, nullptr, nullptr, indent);
93
0
      }
94
0
      break;
95
0
    case cmStateEnums::SHARED_LIBRARY:
96
0
      if (this->Target->IsFrameworkOnApple()) {
97
0
        cmsys::RegularExpressionMatch match;
98
0
        if (FrameworkRegularExpression.find(location.c_str(), match)) {
99
0
          auto frameworkDir = match.match(1);
100
0
          auto frameworkName = match.match(2);
101
0
          auto frameworkPath =
102
0
            cmStrCat(frameworkDir, frameworkName, ".framework");
103
0
          this->AddInstallRule(os, this->GetDestination(config),
104
0
                               cmInstallType_DIRECTORY, { frameworkPath },
105
0
                               this->Optional, nullptr,
106
0
                               this->FilePermissions.c_str(), nullptr,
107
0
                               " USE_SOURCE_PERMISSIONS", indent);
108
0
        }
109
0
      } else {
110
0
        std::vector<std::string> files{ location };
111
0
        if (!this->Target->IsArchivedAIXSharedLibrary()) {
112
0
          auto soName = this->Target->GetSOName(config);
113
0
          auto soNameFile =
114
0
            cmStrCat(this->Target->GetDirectory(config), '/', soName);
115
0
          if (!soName.empty() && soNameFile != location) {
116
0
            files.push_back(soNameFile);
117
0
          }
118
0
        }
119
0
        this->AddInstallRule(os, this->GetDestination(config),
120
0
                             cmInstallType_SHARED_LIBRARY, files,
121
0
                             this->Optional, this->FilePermissions.c_str(),
122
0
                             nullptr, nullptr, nullptr, indent);
123
0
      }
124
0
      break;
125
0
    case cmStateEnums::MODULE_LIBRARY:
126
0
      if (this->Target->IsCFBundleOnApple()) {
127
0
        cmsys::RegularExpressionMatch match;
128
0
        if (CFBundleRegularExpression.find(location.c_str(), match)) {
129
0
          auto bundleDir = match.match(1);
130
0
          auto bundleName = match.match(2);
131
0
          auto bundlePath = cmStrCat(bundleDir, bundleName, ".bundle");
132
0
          this->AddInstallRule(os, this->GetDestination(config),
133
0
                               cmInstallType_DIRECTORY, { bundlePath },
134
0
                               this->Optional, nullptr,
135
0
                               this->FilePermissions.c_str(), nullptr,
136
0
                               " USE_SOURCE_PERMISSIONS", indent);
137
0
        }
138
0
      } else {
139
0
        this->AddInstallRule(os, this->GetDestination(config),
140
0
                             cmInstallType_MODULE_LIBRARY, { location },
141
0
                             this->Optional, this->FilePermissions.c_str(),
142
0
                             nullptr, nullptr, nullptr, indent);
143
0
      }
144
0
      break;
145
0
    default:
146
      assert(false && "This should never happen");
147
0
      break;
148
0
  }
149
0
}