1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmCPackNuGetGenerator.h"
13 #include "cmCPackComponentGroup.h"
14 #include "cmCPackLog.h"
16 #include "cmSystemTools.h"
19 bool cmCPackNuGetGenerator::SupportsComponentInstallation() const
21 return this->IsOn("CPACK_NUGET_COMPONENT_INSTALL");
24 int cmCPackNuGetGenerator::PackageFiles()
26 cmCPackLogger(cmCPackLog::LOG_DEBUG
,
27 "Toplevel: " << this->toplevel
<< std::endl
);
29 /* Reset package file name list it will be populated after the
30 * `CPackNuGet.cmake` run */
31 this->packageFileNames
.clear();
33 /* Are we in the component packaging case */
34 if (this->WantsComponentInstallation()) {
35 if (this->componentPackageMethod
== ONE_PACKAGE
) {
36 // CASE 1 : COMPONENT ALL-IN-ONE package
37 // Meaning that all per-component pre-installed files
38 // goes into the single package.
39 this->SetOption("CPACK_NUGET_ALL_IN_ONE", "TRUE");
40 this->SetupGroupComponentVariables(true);
42 // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
43 // There will be 1 package for each component group
44 // however one may require to ignore component group and
45 // in this case you'll get 1 package for each component.
46 this->SetupGroupComponentVariables(this->componentPackageMethod
==
47 ONE_PACKAGE_PER_COMPONENT
);
50 // CASE 3 : NON COMPONENT package.
51 this->SetOption("CPACK_NUGET_ORDINAL_MONOLITIC", "TRUE");
54 auto retval
= this->ReadListFile("Internal/CPack/CPackNuGet.cmake");
56 this->AddGeneratedPackageNames();
58 cmCPackLogger(cmCPackLog::LOG_ERROR
,
59 "Error while execution CPackNuGet.cmake" << std::endl
);
65 void cmCPackNuGetGenerator::SetupGroupComponentVariables(bool ignoreGroup
)
67 // The default behavior is to have one package by component group
68 // unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
70 std::vector
<std::string
> groups
;
71 for (auto const& compG
: this->ComponentGroups
) {
72 cmCPackLogger(cmCPackLog::LOG_VERBOSE
,
73 "Packaging component group: " << compG
.first
<< std::endl
);
74 groups
.push_back(compG
.first
);
76 cmSystemTools::UpperCase(cmSystemTools::MakeCidentifier(compG
.first
));
78 // Collect components for this group
79 std::vector
<std::string
> components
;
80 std::transform(begin(compG
.second
.Components
),
81 end(compG
.second
.Components
),
82 std::back_inserter(components
),
83 [](cmCPackComponent
const* comp
) { return comp
->Name
; });
84 this->SetOption("CPACK_NUGET_" + compGUp
+ "_GROUP_COMPONENTS",
85 cmList::to_string(components
));
87 if (!groups
.empty()) {
88 this->SetOption("CPACK_NUGET_GROUPS", cmList::to_string(groups
));
91 // Handle Orphan components (components not belonging to any groups)
92 std::vector
<std::string
> components
;
93 for (auto const& comp
: this->Components
) {
94 // Does the component belong to a group?
95 if (!comp
.second
.Group
) {
97 cmCPackLog::LOG_VERBOSE
,
100 << "> does not belong to any group, package it separately."
102 components
.push_back(comp
.first
);
105 if (!components
.empty()) {
106 this->SetOption("CPACK_NUGET_COMPONENTS", cmList::to_string(components
));
110 std::vector
<std::string
> components
;
111 components
.reserve(this->Components
.size());
112 std::transform(begin(this->Components
), end(this->Components
),
113 std::back_inserter(components
),
114 [](std::pair
<std::string
, cmCPackComponent
> const& comp
) {
117 this->SetOption("CPACK_NUGET_COMPONENTS", cmList::to_string(components
));
121 void cmCPackNuGetGenerator::AddGeneratedPackageNames()
123 cmValue
const files_list
= this->GetOption("GEN_CPACK_OUTPUT_FILES");
126 cmCPackLog::LOG_ERROR
,
127 "Error while execution CPackNuGet.cmake: No NuGet package has generated"
131 // add the generated packages to package file names list
132 const std::string
& fileNames
= *files_list
;
133 const char sep
= ';';
134 std::string::size_type pos1
= 0;
135 std::string::size_type pos2
= fileNames
.find(sep
, pos1
+ 1);
136 while (pos2
!= std::string::npos
) {
137 this->packageFileNames
.push_back(fileNames
.substr(pos1
, pos2
- pos1
));
139 pos2
= fileNames
.find(sep
, pos1
+ 1);
141 this->packageFileNames
.push_back(fileNames
.substr(pos1
, pos2
- pos1
));