install(TARGETS): Don't ignore non-extant file sets

When installing FILE_SETs, it is possible the FILE_SET has not yet been
created with target_sources(FILE_SET). Instead of ignoring this
situation, we need to track the installed FILE_SET names and their
possible install destinations.

At generation time we resolve the names and destinations concretely. If
a FILE_SET wasn't provided or isn't an INTERFACE, we silently bail out.

Fixes: #26697
This commit is contained in:
Vito Gamberini
2025-06-12 16:58:11 -04:00
parent e84aaa27af
commit d71b59a4f7
11 changed files with 124 additions and 53 deletions
+50 -3
View File
@@ -2,29 +2,38 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmInstallFileSetGenerator.h"
#include <algorithm>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <cm/string_view>
#include <cmext/string_view>
#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmInstallType.h"
#include "cmList.h"
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
cmInstallFileSetGenerator::cmInstallFileSetGenerator(
std::string targetName, cmFileSet* fileSet, std::string const& dest,
std::string targetName, std::string fileSetName, cmFileSetDestinations dests,
std::string file_permissions, std::vector<std::string> const& configurations,
std::string const& component, MessageLevel message, bool exclude_from_all,
bool optional, cmListFileBacktrace backtrace)
: cmInstallGenerator(dest, configurations, component, message,
: cmInstallGenerator("", configurations, component, message,
exclude_from_all, false, std::move(backtrace))
, TargetName(std::move(targetName))
, FileSet(fileSet)
, FileSetName(std::move(fileSetName))
, FilePermissions(std::move(file_permissions))
, FileSetDestinations(std::move(dests))
, Optional(optional)
{
this->ActionsPerConfig = true;
@@ -44,6 +53,39 @@ bool cmInstallFileSetGenerator::Compute(cmLocalGenerator* lg)
lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
}
auto const& target = *this->Target->Target;
this->FileSet = target.GetFileSet(this->FileSetName);
if (!this->FileSet) {
// No file set of the given name was ever provided for this target, nothing
// for this generator to do
return true;
}
cmList interfaceFileSetEntries{ target.GetSafeProperty(
cmTarget::GetInterfaceFileSetsPropertyName(this->FileSet->GetType())) };
if (std::find(interfaceFileSetEntries.begin(), interfaceFileSetEntries.end(),
this->FileSetName) != interfaceFileSetEntries.end()) {
if (this->FileSet->GetType() == "HEADERS"_s) {
this->Destination = this->FileSetDestinations.Headers;
} else {
this->Destination = this->FileSetDestinations.CXXModules;
}
} else {
// File set of the given name was provided but it's private, so give up
this->FileSet = nullptr;
return true;
}
if (this->Destination.empty()) {
lg->IssueMessage(MessageType::FATAL_ERROR,
cmStrCat("File set \"", this->FileSetName,
"\" installed by target \"", this->TargetName,
"\" has no destination."));
return false;
}
return true;
}
@@ -57,6 +99,11 @@ std::string cmInstallFileSetGenerator::GetDestination(
void cmInstallFileSetGenerator::GenerateScriptForConfig(
std::ostream& os, std::string const& config, Indent indent)
{
if (!this->FileSet) {
return;
}
for (auto const& dirEntry : this->CalculateFilesPerDir(config)) {
std::string destSub;
if (!dirEntry.first.empty()) {