Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmInstallFileSetGenerator.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 "cmInstallFileSetGenerator.h"
4
5
#include <algorithm>
6
#include <map>
7
#include <string>
8
#include <utility>
9
#include <vector>
10
11
#include <cm/string_view>
12
13
#include "cmFileSetMetadata.h"
14
#include "cmGenExContext.h"
15
#include "cmGeneratorExpression.h"
16
#include "cmGeneratorFileSet.h"
17
#include "cmGeneratorTarget.h"
18
#include "cmGlobalGenerator.h"
19
#include "cmInstallDirs.h"
20
#include "cmInstallType.h"
21
#include "cmList.h"
22
#include "cmListFileCache.h"
23
#include "cmLocalGenerator.h"
24
#include "cmMessageType.h"
25
#include "cmStringAlgorithms.h"
26
#include "cmTarget.h"
27
28
cmInstallFileSetGenerator::cmInstallFileSetGenerator(
29
  std::string targetName, std::string fileSetName, std::string destination,
30
  std::string file_permissions, std::vector<std::string> const& configurations,
31
  std::string const& component, MessageLevel message, bool exclude_from_all,
32
  bool optional, cmListFileBacktrace backtrace)
33
0
  : cmInstallGenerator(std::move(destination), configurations, component,
34
0
                       message, exclude_from_all, false, std::move(backtrace))
35
0
  , TargetName(std::move(targetName))
36
0
  , FileSetName(std::move(fileSetName))
37
0
  , FilePermissions(std::move(file_permissions))
38
0
  , Optional(optional)
39
0
{
40
0
  this->ActionsPerConfig = true;
41
0
}
42
43
0
cmInstallFileSetGenerator::~cmInstallFileSetGenerator() = default;
44
45
bool cmInstallFileSetGenerator::Compute(cmLocalGenerator* lg)
46
0
{
47
0
  this->LocalGenerator = lg;
48
49
  // Lookup this target in the current directory.
50
0
  this->Target = lg->FindLocalNonAliasGeneratorTarget(this->TargetName);
51
0
  if (!this->Target) {
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
  this->FileSet = this->Target->GetFileSet(this->FileSetName);
58
59
0
  if (!this->FileSet) {
60
    // No file set of the given name was ever provided for this target, nothing
61
    // for this generator to do
62
0
    return true;
63
0
  }
64
65
0
  auto const& target = *this->Target->Target;
66
0
  cmList interfaceFileSetEntries{ target.GetSafeProperty(
67
0
    target.GetInterfaceFileSetsPropertyName(this->FileSet->GetType())) };
68
69
0
  if (std::find(interfaceFileSetEntries.begin(), interfaceFileSetEntries.end(),
70
0
                this->FileSetName) != interfaceFileSetEntries.end()) {
71
0
    if (this->FileSet->GetType() == cm::FileSetMetadata::HEADERS) {
72
0
      if (this->Destination.empty()) {
73
0
        this->Destination =
74
0
          cm::InstallDirs::GetIncludeDirectory(lg->GetMakefile());
75
0
      }
76
0
    }
77
0
  } else {
78
    // File set of the given name was provided but it's private, so give up
79
0
    this->FileSet = nullptr;
80
0
    return true;
81
0
  }
82
83
0
  if (this->Destination.empty()) {
84
0
    lg->IssueMessage(MessageType::FATAL_ERROR,
85
0
                     cmStrCat("File set \"", this->FileSetName,
86
0
                              "\" installed by target \"", this->TargetName,
87
0
                              "\" has no destination."));
88
0
    return false;
89
0
  }
90
91
0
  return true;
92
0
}
93
94
std::string cmInstallFileSetGenerator::GetDestination(
95
  std::string const& config) const
96
0
{
97
0
  return cmGeneratorExpression::Evaluate(this->Destination,
98
0
                                         this->LocalGenerator, config);
99
0
}
100
101
void cmInstallFileSetGenerator::GenerateScriptForConfig(
102
  std::ostream& os, std::string const& config, Indent indent)
103
0
{
104
105
0
  if (!this->FileSet) {
106
0
    return;
107
0
  }
108
109
0
  for (auto const& dirEntry : this->CalculateFilesPerDir(config)) {
110
0
    std::string destSub;
111
0
    if (!dirEntry.first.empty()) {
112
0
      destSub = cmStrCat('/', dirEntry.first);
113
0
    }
114
0
    this->AddInstallRule(os, cmStrCat(this->GetDestination(config), destSub),
115
0
                         cmInstallType_FILES, dirEntry.second,
116
0
                         this->GetOptional(), this->FilePermissions.c_str(),
117
0
                         nullptr, nullptr, nullptr, indent);
118
0
  }
119
0
}
120
121
std::map<std::string, std::vector<std::string>>
122
cmInstallFileSetGenerator::CalculateFilesPerDir(
123
  std::string const& config) const
124
0
{
125
0
  cm::GenEx::Context context(this->LocalGenerator, config);
126
127
0
  return this->FileSet->GetFiles(context, this->Target).first;
128
0
}