mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
CPS: Refactor getting file set destination for install
Modify `cmExportInstallPackageInfoGenerator::GetFileSetDirectory` to not have side effects, moving that logic to the call site instead. This will allow the method to be used in other contexts. Also, tweak a bunch of methods called by this method to not unnecessarily require mutable objects.
This commit is contained in:
@@ -220,21 +220,19 @@ std::string cmExportInstallPackageInfoGenerator::GetCxxModulesDirectory() const
|
||||
|
||||
cm::optional<std::string>
|
||||
cmExportInstallPackageInfoGenerator::GetFileSetDirectory(
|
||||
cmGeneratorTarget* gte, cmTargetExport const* te,
|
||||
cmGeneratorTarget const* target, cmTargetExport const* targetExport,
|
||||
cmGeneratorFileSet const* fileSet, cm::optional<std::string> const& config)
|
||||
{
|
||||
cmInstallFileSetGenerator::DestinationContext result =
|
||||
te->FileSetGenerators.at(fileSet->GetName())
|
||||
->GetDestination(gte, config.value_or(""));
|
||||
cmInstallFileSetGenerator const* const fsg =
|
||||
targetExport->FileSetGenerators.at(fileSet->GetName());
|
||||
cmInstallFileSetGenerator::DestinationContext const result =
|
||||
fsg->GetDestination(target, config.value_or(""));
|
||||
|
||||
if (config && !result.HadContextSensitiveCondition) {
|
||||
return {};
|
||||
}
|
||||
if (!config && result.HadContextSensitiveCondition) {
|
||||
this->RequiresConfigFiles = true;
|
||||
if (!config == result.HadContextSensitiveCondition) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Use cm::optional here to enable NRVO.
|
||||
cm::optional<std::string> dest = cmOutputConverter::EscapeForCMake(
|
||||
result.UnescapedDestination, cmOutputConverter::WrapQuotes::NoWrap);
|
||||
|
||||
@@ -267,8 +265,11 @@ bool cmExportInstallPackageInfoGenerator::GenerateFileSetProperties(
|
||||
this->GetFileSetDirectory(gte, te, fileSet, config);
|
||||
|
||||
if (fileSet->GetType() == cm::FileSetMetadata::HEADERS) {
|
||||
if (fileSetDirectory &&
|
||||
!cm::contains(seenIncludeDirectories, *fileSetDirectory)) {
|
||||
if (!fileSetDirectory) {
|
||||
if (!config) {
|
||||
this->RequiresConfigFiles = true;
|
||||
}
|
||||
} else if (!cm::contains(seenIncludeDirectories, *fileSetDirectory)) {
|
||||
component["includes"].append(*fileSetDirectory);
|
||||
seenIncludeDirectories.insert(*fileSetDirectory);
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ protected:
|
||||
|
||||
std::string GetCxxModulesDirectory() const override;
|
||||
|
||||
cm::optional<std::string> GetFileSetDirectory(
|
||||
cmGeneratorTarget* gte, cmTargetExport const* te,
|
||||
static cm::optional<std::string> GetFileSetDirectory(
|
||||
cmGeneratorTarget const* target, cmTargetExport const* targetExport,
|
||||
cmGeneratorFileSet const* fileSet,
|
||||
cm::optional<std::string> const& config = {});
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ std::string cmInstallFileSetGenerator::GetDestination(
|
||||
}
|
||||
|
||||
cmInstallFileSetGenerator::DestinationContext
|
||||
cmInstallFileSetGenerator::GetDestination(cmGeneratorTarget* gte,
|
||||
cmInstallFileSetGenerator::GetDestination(cmGeneratorTarget const* gte,
|
||||
std::string const& config) const
|
||||
{
|
||||
cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance());
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
bool HadContextSensitiveCondition;
|
||||
};
|
||||
std::string GetDestination(std::string const& config) const;
|
||||
DestinationContext GetDestination(cmGeneratorTarget* gt,
|
||||
DestinationContext GetDestination(cmGeneratorTarget const* gt,
|
||||
std::string const& config) const;
|
||||
bool GetOptional() const { return this->Optional; }
|
||||
std::string GetFileSetName() const { return this->FileSetName; }
|
||||
|
||||
@@ -230,8 +230,8 @@ std::string cmInstallGenerator::ConvertToAbsoluteDestination(
|
||||
return result;
|
||||
}
|
||||
|
||||
void cmInstallGenerator::CheckAbsoluteDestination(std::string const& dest,
|
||||
cmLocalGenerator* lg) const
|
||||
void cmInstallGenerator::CheckAbsoluteDestination(
|
||||
std::string const& dest, cmLocalGenerator const* lg) const
|
||||
{
|
||||
if (!cmSystemTools::FileIsFullPath(dest)) {
|
||||
return;
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
installation script. */
|
||||
static std::string ConvertToAbsoluteDestination(std::string const& dest);
|
||||
void CheckAbsoluteDestination(std::string const& dest,
|
||||
cmLocalGenerator* lg) const;
|
||||
cmLocalGenerator const* lg) const;
|
||||
|
||||
/** Test if this generator installs something for a given configuration. */
|
||||
bool InstallsForConfig(std::string const& config);
|
||||
|
||||
Reference in New Issue
Block a user