File: cmExportBuildPackageInfoGenerator.cxx

package info (click to toggle)
cmake 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,412 kB
  • sloc: ansic: 403,924; cpp: 290,826; sh: 4,091; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 98; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (116 lines) | stat: -rw-r--r-- 3,328 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */
#include "cmExportBuildPackageInfoGenerator.h"

#include <cassert>
#include <utility>
#include <vector>

#include <cmext/string_view>

#include <cm3p/json/value.h>

#include "cmGeneratorExpression.h"
#include "cmPackageInfoArguments.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"

cmExportBuildPackageInfoGenerator::cmExportBuildPackageInfoGenerator(
  cmPackageInfoArguments arguments)
  : cmExportPackageInfoGenerator(std::move(arguments))
{
  this->SetNamespace(cmStrCat(this->GetPackageName(), "::"_s));
}

bool cmExportBuildPackageInfoGenerator::GenerateMainFile(std::ostream& os)
{
  if (!this->CollectExports([&](cmGeneratorTarget const*) {})) {
    return false;
  }

  if (!this->CheckDefaultTargets()) {
    return false;
  }

  Json::Value root = this->GeneratePackageInfo();
  root["cps_path"] = "@prefix@";

  Json::Value& components = root["components"];

  // Create all the imported targets.
  for (auto const& exp : this->Exports) {
    cmGeneratorTarget* const target = exp.Target;
    cmStateEnums::TargetType targetType = this->GetExportTargetType(target);

    Json::Value* const component =
      this->GenerateImportTarget(components, target, targetType);
    if (!component) {
      return false;
    }

    ImportPropertyMap properties;
    if (!this->PopulateInterfaceProperties(target, properties)) {
      return false;
    }
    this->PopulateInterfaceLinkLibrariesProperty(
      target, cmGeneratorExpression::InstallInterface, properties);

    if (targetType != cmStateEnums::INTERFACE_LIBRARY) {
      auto configurations = Json::Value{ Json::objectValue };

      // Add per-configuration properties.
      for (std::string const& c : this->Configurations) {
        this->GenerateInterfacePropertiesConfig(configurations, target, c);
      }

      if (!configurations.empty()) {
        (*component)["configurations"] = configurations;
      }
    }

    // Set configuration-agnostic properties for component.
    this->GenerateInterfaceProperties(*component, target, properties);
  }

  this->GeneratePackageRequires(root);

  // Write the primary packing information file.
  this->WritePackageInfo(root, os);

  bool result = true;

  return result;
}

void cmExportBuildPackageInfoGenerator::GenerateInterfacePropertiesConfig(
  Json::Value& configurations, cmGeneratorTarget* target,
  std::string const& config)
{
  std::string const& suffix = PropertyConfigSuffix(config);

  ImportPropertyMap properties;

  assert(this->GetExportTargetType(target) != cmStateEnums::INTERFACE_LIBRARY);
  this->SetImportLocationProperty(config, suffix, target, properties);
  if (properties.empty()) {
    return;
  }

  this->SetImportDetailProperties(config, suffix, target, properties);

  // TODO: PUBLIC_HEADER_LOCATION

  Json::Value component =
    this->GenerateInterfaceConfigProperties(suffix, properties);
  if (!component.empty()) {
    configurations[config.empty() ? std::string{ "noconfig" } : config] =
      std::move(component);
  }
}

std::string cmExportBuildPackageInfoGenerator::GetCxxModulesDirectory() const
{
  // TODO: Implement a not-CMake-specific mechanism for providing module
  // information.
  return {};
}