Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmExportBuildPackageInfoGenerator.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 "cmExportBuildPackageInfoGenerator.h"
4
5
#include <cassert>
6
#include <functional>
7
#include <map>
8
#include <utility>
9
#include <vector>
10
11
#include <cmext/string_view>
12
13
#include <cm3p/json/value.h>
14
15
#include "cmAlgorithms.h"
16
#include "cmGeneratorExpression.h"
17
#include "cmList.h"
18
#include "cmPackageInfoArguments.h"
19
#include "cmStateTypes.h"
20
#include "cmStringAlgorithms.h"
21
22
cmExportBuildPackageInfoGenerator::cmExportBuildPackageInfoGenerator(
23
  cmPackageInfoArguments arguments)
24
0
  : cmExportPackageInfoGenerator(std::move(arguments))
25
0
{
26
0
  this->SetNamespace(cmStrCat(this->GetPackageName(), "::"_s));
27
0
}
Unexecuted instantiation: cmExportBuildPackageInfoGenerator::cmExportBuildPackageInfoGenerator(cmPackageInfoArguments)
Unexecuted instantiation: cmExportBuildPackageInfoGenerator::cmExportBuildPackageInfoGenerator(cmPackageInfoArguments)
28
29
bool cmExportBuildPackageInfoGenerator::GenerateMainFile(std::ostream& os)
30
0
{
31
0
  if (!this->CollectExports([&](cmGeneratorTarget const*) {})) {
32
0
    return false;
33
0
  }
34
35
0
  if (!this->CheckPackage()) {
36
0
    return false;
37
0
  }
38
39
0
  Json::Value root = this->GeneratePackageInfo();
40
0
  root["cps_path"] = "@prefix@";
41
42
0
  Json::Value& components = root["components"];
43
44
  // Create all the imported targets.
45
0
  for (auto const& exp : this->Exports) {
46
0
    cmGeneratorTarget* const target = exp.Target;
47
0
    cmStateEnums::TargetType targetType = this->GetExportTargetType(target);
48
49
0
    Json::Value* const component =
50
0
      this->GenerateImportTarget(components, target, targetType);
51
0
    if (!component) {
52
0
      return false;
53
0
    }
54
55
0
    ImportPropertyMap properties;
56
0
    if (!this->PopulateInterfaceProperties(target, properties)) {
57
0
      return false;
58
0
    }
59
0
    this->PopulateInterfaceLinkLibrariesProperty(
60
0
      target, cmGeneratorExpression::InstallInterface, properties);
61
62
0
    if (targetType != cmStateEnums::INTERFACE_LIBRARY) {
63
0
      auto configurations = Json::Value{ Json::objectValue };
64
65
      // Add per-configuration properties.
66
0
      for (std::string const& c : this->Configurations) {
67
0
        this->GenerateInterfacePropertiesConfig(configurations, target, c);
68
0
      }
69
70
0
      if (!configurations.empty()) {
71
0
        (*component)["configurations"] = configurations;
72
0
      }
73
0
    }
74
75
    // De-duplicate include directories prior to generation.
76
0
    auto it = properties.find("INTERFACE_INCLUDE_DIRECTORIES");
77
0
    if (it != properties.end()) {
78
0
      auto list = cmList{ it->second };
79
0
      list = cmList{ list.begin(), cmRemoveDuplicates(list) };
80
0
      properties["INTERFACE_INCLUDE_DIRECTORIES"] = list.to_string();
81
0
    }
82
83
    // Set configuration-agnostic properties for component.
84
0
    this->GenerateInterfaceProperties(*component, target, properties);
85
0
  }
86
87
0
  this->GeneratePackageRequires(root);
88
89
  // Write the primary packing information file.
90
0
  this->WritePackageInfo(root, os);
91
92
0
  bool result = true;
93
94
0
  return result;
95
0
}
96
97
void cmExportBuildPackageInfoGenerator::GenerateInterfacePropertiesConfig(
98
  Json::Value& configurations, cmGeneratorTarget* target,
99
  std::string const& config)
100
0
{
101
0
  std::string const& suffix = PropertyConfigSuffix(config);
102
103
0
  ImportPropertyMap properties;
104
105
0
  assert(this->GetExportTargetType(target) != cmStateEnums::INTERFACE_LIBRARY);
106
0
  this->SetImportLocationProperty(config, suffix, target, properties);
107
0
  if (properties.empty()) {
108
0
    return;
109
0
  }
110
111
0
  this->SetImportDetailProperties(config, suffix, target, properties);
112
113
  // TODO: PUBLIC_HEADER_LOCATION
114
115
0
  Json::Value component =
116
0
    this->GenerateInterfaceConfigProperties(suffix, properties);
117
118
0
  this->GenerateCxxModules(component, target, this->FileDir, config);
119
120
0
  if (!component.empty()) {
121
0
    configurations[config.empty() ? std::string{ "noconfig" } : config] =
122
0
      std::move(component);
123
0
  }
124
0
}
125
126
std::string cmExportBuildPackageInfoGenerator::GetCxxModulesDirectory() const
127
0
{
128
0
  return this->CxxModulesDirectory;
129
0
}