export: Fix handling of import prefix

Fix some additional places in export generation logic that were still
hard-coding the import prefix. Change cmGeneratorExpression::Preprocess
to take the desired prefix as an argument. (This replaces taking a
boolean whether to resolve relative paths; if a non-empty prefix is
given, that is used to resolve relative paths, otherwise relative paths
are left alone.) This should ensure that import properties always spell
the prefix according to the format being generated.
This commit is contained in:
Matthew Woehlke
2024-07-26 16:40:03 -04:00
parent e5b73b60e3
commit 8178fd43e9
4 changed files with 35 additions and 27 deletions

View File

@@ -83,7 +83,8 @@ std::string cmExportInstallFileGenerator::GetImportXcFrameworkLocation(
if (!importedXcFrameworkLocation.empty()) {
importedXcFrameworkLocation = cmGeneratorExpression::Preprocess(
importedXcFrameworkLocation,
cmGeneratorExpression::PreprocessContext::InstallInterface, true);
cmGeneratorExpression::PreprocessContext::InstallInterface,
this->GetImportPrefixWithSlash());
importedXcFrameworkLocation = cmGeneratorExpression::Evaluate(
importedXcFrameworkLocation, targetExport->Target->GetLocalGenerator(),
config, targetExport->Target, nullptr, targetExport->Target);
@@ -156,7 +157,7 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
std::string value;
if (!cmSystemTools::FileIsFullPath(dest)) {
// The target is installed relative to the installation prefix.
value = "${_IMPORT_PREFIX}/";
value = std::string{ this->GetImportPrefixWithSlash() };
}
value += dest;
value += "/";
@@ -399,10 +400,11 @@ bool isSubDirectory(std::string const& a, std::string const& b)
return (cmSystemTools::ComparePath(a, b) ||
cmSystemTools::IsSubDirectory(a, b));
}
}
bool checkInterfaceDirs(std::string const& prepro,
cmGeneratorTarget const* target,
std::string const& prop)
bool cmExportInstallFileGenerator::CheckInterfaceDirs(
std::string const& prepro, cmGeneratorTarget const* target,
std::string const& prop) const
{
std::string const& installDir =
target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
@@ -423,7 +425,7 @@ bool checkInterfaceDirs(std::string const& prepro,
if (genexPos == 0) {
continue;
}
if (cmHasLiteralPrefix(li, "${_IMPORT_PREFIX}")) {
if (cmHasPrefix(li, this->GetImportPrefixWithSlash())) {
continue;
}
MessageType messageType = MessageType::FATAL_ERROR;
@@ -521,7 +523,6 @@ bool checkInterfaceDirs(std::string const& prepro,
}
return !hadFatalError;
}
}
void cmExportInstallFileGenerator::PopulateSourcesInterface(
cmGeneratorTarget const* gt,
@@ -542,12 +543,12 @@ void cmExportInstallFileGenerator::PopulateSourcesInterface(
return;
}
std::string prepro =
cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
std::string prepro = cmGeneratorExpression::Preprocess(
*input, preprocessRule, this->GetImportPrefixWithSlash());
if (!prepro.empty()) {
this->ResolveTargetsInGeneratorExpressions(prepro, gt);
if (!checkInterfaceDirs(prepro, gt, propName)) {
if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
return;
}
properties[propName] = prepro;
@@ -571,7 +572,7 @@ void cmExportInstallFileGenerator::PopulateIncludeDirectoriesInterface(
std::string dirs = cmGeneratorExpression::Preprocess(
cmList::to_string(target->Target->GetInstallIncludeDirectoriesEntries(te)),
preprocessRule, true);
preprocessRule, this->GetImportPrefixWithSlash());
this->ReplaceInstallPrefix(dirs);
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
std::string exportDirs =
@@ -605,12 +606,12 @@ void cmExportInstallFileGenerator::PopulateIncludeDirectoriesInterface(
std::string includes = (input ? *input : "");
char const* const sep = input ? ";" : "";
includes += sep + exportDirs;
std::string prepro =
cmGeneratorExpression::Preprocess(includes, preprocessRule, true);
std::string prepro = cmGeneratorExpression::Preprocess(
includes, preprocessRule, this->GetImportPrefixWithSlash());
if (!prepro.empty()) {
this->ResolveTargetsInGeneratorExpressions(prepro, target);
if (!checkInterfaceDirs(prepro, target, propName)) {
if (!this->CheckInterfaceDirs(prepro, target, propName)) {
return;
}
properties[propName] = prepro;
@@ -636,12 +637,12 @@ void cmExportInstallFileGenerator::PopulateLinkDependsInterface(
return;
}
std::string prepro =
cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
std::string prepro = cmGeneratorExpression::Preprocess(
*input, preprocessRule, this->GetImportPrefixWithSlash());
if (!prepro.empty()) {
this->ResolveTargetsInGeneratorExpressions(prepro, gt);
if (!checkInterfaceDirs(prepro, gt, propName)) {
if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
return;
}
properties[propName] = prepro;
@@ -667,12 +668,12 @@ void cmExportInstallFileGenerator::PopulateLinkDirectoriesInterface(
return;
}
std::string prepro =
cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
std::string prepro = cmGeneratorExpression::Preprocess(
*input, preprocessRule, this->GetImportPrefixWithSlash());
if (!prepro.empty()) {
this->ResolveTargetsInGeneratorExpressions(prepro, gt);
if (!checkInterfaceDirs(prepro, gt, propName)) {
if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
return;
}
properties[propName] = prepro;

View File

@@ -145,6 +145,9 @@ protected:
std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
private:
bool CheckInterfaceDirs(std::string const& prepro,
cmGeneratorTarget const* target,
std::string const& prop) const;
void PopulateCompatibleInterfaceProperties(cmGeneratorTarget const* target,
ImportPropertyMap& properties);
void PopulateCustomTransitiveInterfaceProperties(

View File

@@ -7,6 +7,8 @@
#include <memory>
#include <utility>
#include <cm/string_view>
#include "cmsys/RegularExpression.hxx"
#include "cmGeneratorExpressionContext.h"
@@ -193,7 +195,7 @@ static std::string stripAllGeneratorExpressions(const std::string& input)
}
static void prefixItems(const std::string& content, std::string& result,
const std::string& prefix)
const cm::string_view& prefix)
{
std::vector<std::string> entries;
cmGeneratorExpression::Split(content, entries);
@@ -211,7 +213,7 @@ static void prefixItems(const std::string& content, std::string& result,
static std::string stripExportInterface(
const std::string& input, cmGeneratorExpression::PreprocessContext context,
bool resolveRelative)
cm::string_view importPrefix)
{
std::string result;
@@ -268,8 +270,8 @@ static std::string stripExportInterface(
} else if (context == cmGeneratorExpression::InstallInterface &&
foundGenex == FoundGenex::InstallInterface) {
const std::string content = input.substr(pos, c - cStart);
if (resolveRelative) {
prefixItems(content, result, "${_IMPORT_PREFIX}/");
if (!importPrefix.empty()) {
prefixItems(content, result, importPrefix);
} else {
result += content;
}
@@ -359,13 +361,13 @@ void cmGeneratorExpression::Split(const std::string& input,
std::string cmGeneratorExpression::Preprocess(const std::string& input,
PreprocessContext context,
bool resolveRelative)
cm::string_view importPrefix)
{
if (context == StripAllGeneratorExpressions) {
return stripAllGeneratorExpressions(input);
}
if (context == BuildInterface || context == InstallInterface) {
return stripExportInterface(input, context, resolveRelative);
return stripExportInterface(input, context, importPrefix);
}
assert(false &&

View File

@@ -11,6 +11,8 @@
#include <utility>
#include <vector>
#include <cm/string_view>
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
@@ -59,7 +61,7 @@ public:
static std::string Preprocess(const std::string& input,
PreprocessContext context,
bool resolveRelative = false);
cm::string_view importPrefix = {});
static void Split(const std::string& input,
std::vector<std::string>& output);