summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-09-21 18:04:54 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-11-15 14:10:58 (GMT)
commit256bb0cc40a9f9f20452f0c0b2480886a577e7cb (patch)
treecc07534f951465698ace7fefc0bebfc12a456029 /Source
parenta90968e044d04839e610da9a1adf7b6f390e144a (diff)
downloadCMake-256bb0cc40a9f9f20452f0c0b2480886a577e7cb.zip
CMake-256bb0cc40a9f9f20452f0c0b2480886a577e7cb.tar.gz
CMake-256bb0cc40a9f9f20452f0c0b2480886a577e7cb.tar.bz2
install(EXPORT): Add ability to point to .xcframework file
Issue: #25262
Diffstat (limited to 'Source')
-rw-r--r--Source/cmExportBuildAndroidMKGenerator.cxx4
-rw-r--r--Source/cmExportBuildAndroidMKGenerator.h6
-rw-r--r--Source/cmExportBuildFileGenerator.cxx22
-rw-r--r--Source/cmExportBuildFileGenerator.h9
-rw-r--r--Source/cmExportCommand.cxx30
-rw-r--r--Source/cmExportFileGenerator.cxx64
-rw-r--r--Source/cmExportFileGenerator.h11
-rw-r--r--Source/cmExportInstallAndroidMKGenerator.cxx6
-rw-r--r--Source/cmExportInstallAndroidMKGenerator.h9
-rw-r--r--Source/cmExportInstallFileGenerator.cxx23
-rw-r--r--Source/cmExportSet.cxx10
-rw-r--r--Source/cmExportSet.h3
-rw-r--r--Source/cmTargetExport.h1
13 files changed, 155 insertions, 43 deletions
diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx
index c54e6ac..34bda1b 100644
--- a/Source/cmExportBuildAndroidMKGenerator.cxx
+++ b/Source/cmExportBuildAndroidMKGenerator.cxx
@@ -57,8 +57,8 @@ void cmExportBuildAndroidMKGenerator::GenerateImportTargetCode(
}
void cmExportBuildAndroidMKGenerator::GenerateImportPropertyCode(
- std::ostream&, const std::string&, cmGeneratorTarget const*,
- ImportPropertyMap const&)
+ std::ostream&, const std::string&, const std::string&,
+ cmGeneratorTarget const*, ImportPropertyMap const&, const std::string&)
{
}
diff --git a/Source/cmExportBuildAndroidMKGenerator.h b/Source/cmExportBuildAndroidMKGenerator.h
index 8918ce1..9562cee 100644
--- a/Source/cmExportBuildAndroidMKGenerator.h
+++ b/Source/cmExportBuildAndroidMKGenerator.h
@@ -51,9 +51,9 @@ protected:
void GenerateExpectedTargetsCode(
std::ostream& os, const std::string& expectedTargets) override;
void GenerateImportPropertyCode(
- std::ostream& os, const std::string& config,
- cmGeneratorTarget const* target,
- ImportPropertyMap const& properties) override;
+ std::ostream& os, const std::string& config, const std::string& suffix,
+ cmGeneratorTarget const* target, ImportPropertyMap const& properties,
+ const std::string& importedXcFrameworkLocation) override;
void GenerateMissingTargetsCheckCode(std::ostream& os) override;
void GenerateFindDependencyCalls(std::ostream&) override {}
void GenerateInterfaceProperties(
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index 291619f..8ba8d97 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -61,7 +61,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
expectedTargets += sep + this->Namespace + te->GetExportName();
sep = " ";
if (this->ExportedTargets.insert(te).second) {
- this->Exports.emplace_back(te);
+ this->Exports.emplace_back(te, tei.XcFrameworkLocation);
} else {
std::ostringstream e;
e << "given target \"" << te->GetName() << "\" more than once.";
@@ -202,7 +202,23 @@ void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
// properties);
// Generate code in the export file.
- this->GenerateImportPropertyCode(os, config, target, properties);
+ std::string importedXcFrameworkLocation = exp.XcFrameworkLocation;
+ if (!importedXcFrameworkLocation.empty()) {
+ importedXcFrameworkLocation = cmGeneratorExpression::Preprocess(
+ importedXcFrameworkLocation,
+ cmGeneratorExpression::PreprocessContext::BuildInterface);
+ importedXcFrameworkLocation = cmGeneratorExpression::Evaluate(
+ importedXcFrameworkLocation, exp.Target->GetLocalGenerator(), config,
+ exp.Target, nullptr, exp.Target);
+ if (!importedXcFrameworkLocation.empty() &&
+ !cmSystemTools::FileIsFullPath(importedXcFrameworkLocation)) {
+ importedXcFrameworkLocation =
+ cmStrCat(this->LG->GetCurrentBinaryDirectory(), '/',
+ importedXcFrameworkLocation);
+ }
+ }
+ this->GenerateImportPropertyCode(os, config, suffix, target, properties,
+ importedXcFrameworkLocation);
}
}
}
@@ -318,7 +334,7 @@ void cmExportBuildFileGenerator::GetTargets(
if (te->NamelinkOnly) {
continue;
}
- targets.emplace_back(te->TargetName);
+ targets.emplace_back(te->TargetName, te->XcFrameworkLocation);
}
return;
}
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index 2ac8fba..9f11d13 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -35,12 +35,14 @@ class cmExportBuildFileGenerator : public cmExportFileGenerator
public:
struct TargetExport
{
- TargetExport(std::string name)
+ TargetExport(std::string name, std::string xcFrameworkLocation)
: Name(std::move(name))
+ , XcFrameworkLocation(std::move(xcFrameworkLocation))
{
}
std::string Name;
+ std::string XcFrameworkLocation;
};
cmExportBuildFileGenerator();
@@ -111,12 +113,15 @@ protected:
struct TargetExportPrivate
{
- TargetExportPrivate(cmGeneratorTarget* target)
+ TargetExportPrivate(cmGeneratorTarget* target,
+ std::string xcFrameworkLocation)
: Target(target)
+ , XcFrameworkLocation(std::move(xcFrameworkLocation))
{
}
cmGeneratorTarget* Target;
+ std::string XcFrameworkLocation;
};
std::vector<TargetExport> Targets;
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index e7a69b0..9c3bc61 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -72,6 +72,8 @@ bool cmExportCommand(std::vector<std::string> const& args,
std::vector<std::vector<std::string>> PackageDependencyArgs;
bool ExportPackageDependencies = false;
+
+ std::vector<std::vector<std::string>> TargetArgs;
};
auto parser =
@@ -87,6 +89,7 @@ bool cmExportCommand(std::vector<std::string> const& args,
} else if (args[0] == "SETUP") {
parser.Bind("SETUP"_s, &Arguments::ExportSetName);
parser.Bind("PACKAGE_DEPENDENCY"_s, &Arguments::PackageDependencyArgs);
+ parser.Bind("TARGET"_s, &Arguments::TargetArgs);
} else {
parser.Bind("TARGETS"_s, &Arguments::Targets);
parser.Bind("ANDROID_MK"_s, &Arguments::AndroidMKFile);
@@ -159,6 +162,31 @@ bool cmExportCommand(std::vector<std::string> const& args,
packageDependencyArguments.ExtraArgs);
}
+ struct TargetArguments
+ {
+ std::string XcFrameworkLocation;
+ };
+
+ auto targetParser = cmArgumentParser<TargetArguments>{}.Bind(
+ "XCFRAMEWORK_LOCATION"_s, &TargetArguments::XcFrameworkLocation);
+
+ for (auto const& targetArgs : arguments.TargetArgs) {
+ if (targetArgs.empty()) {
+ continue;
+ }
+
+ TargetArguments const targetArguments =
+ targetParser.Parse(cmMakeRange(targetArgs).advance(1), &unknownArgs);
+
+ if (!unknownArgs.empty()) {
+ status.SetError("Unknown argument: \"" + unknownArgs.front() + "\".");
+ return false;
+ }
+
+ exportSet.SetXcFrameworkLocation(targetArgs.front(),
+ targetArguments.XcFrameworkLocation);
+ }
+
return true;
}
@@ -242,7 +270,7 @@ bool cmExportCommand(std::vector<std::string> const& args,
status.SetError(e.str());
return false;
}
- targets.emplace_back(currentTarget);
+ targets.emplace_back(currentTarget, std::string{});
}
if (arguments.Append) {
if (cmExportBuildFileGenerator* ebfg =
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 205bf08..e2c3edd 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -1154,8 +1154,9 @@ void cmExportFileGenerator::GenerateImportTargetCode(
}
void cmExportFileGenerator::GenerateImportPropertyCode(
- std::ostream& os, const std::string& config, cmGeneratorTarget const* target,
- ImportPropertyMap const& properties)
+ std::ostream& os, const std::string& config, const std::string& suffix,
+ cmGeneratorTarget const* target, ImportPropertyMap const& properties,
+ const std::string& importedXcFrameworkLocation)
{
// Construct the imported target name.
std::string targetName = this->Namespace;
@@ -1174,12 +1175,31 @@ void cmExportFileGenerator::GenerateImportPropertyCode(
}
os << ")\n";
os << "set_target_properties(" << targetName << " PROPERTIES\n";
+ std::string importedLocationProp = cmStrCat("IMPORTED_LOCATION", suffix);
for (auto const& property : properties) {
- os << " " << property.first << " "
- << cmExportFileGeneratorEscape(property.second) << "\n";
+ if (importedXcFrameworkLocation.empty() ||
+ property.first != importedLocationProp) {
+ os << " " << property.first << " "
+ << cmExportFileGeneratorEscape(property.second) << "\n";
+ }
}
- os << " )\n"
- << "\n";
+ os << " )\n";
+ if (!importedXcFrameworkLocation.empty()) {
+ auto importedLocationIt = properties.find(importedLocationProp);
+ if (importedLocationIt != properties.end()) {
+ os << "if(NOT CMAKE_VERSION VERSION_LESS \"3.28\" AND IS_DIRECTORY "
+ << cmExportFileGeneratorEscape(importedXcFrameworkLocation)
+ << ")\n"
+ " set_property(TARGET "
+ << targetName << " PROPERTY " << importedLocationProp << " "
+ << cmExportFileGeneratorEscape(importedXcFrameworkLocation)
+ << ")\nelse()\n set_property(TARGET " << targetName << " PROPERTY "
+ << importedLocationProp << " "
+ << cmExportFileGeneratorEscape(importedLocationIt->second)
+ << ")\nendif()\n";
+ }
+ }
+ os << "\n";
}
void cmExportFileGenerator::GenerateFindDependencyCalls(std::ostream& os)
@@ -1310,10 +1330,16 @@ void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
/* clang-format off */
os << "# Loop over all imported files and verify that they actually exist\n"
"foreach(_cmake_target IN LISTS _cmake_import_check_targets)\n"
- " foreach(_cmake_file IN LISTS \"_cmake_import_check_files_for_${_cmake_target}\")\n"
- " if(NOT EXISTS \"${_cmake_file}\")\n"
- " message(FATAL_ERROR \"The imported target \\\"${_cmake_target}\\\""
- " references the file\n"
+ " if(CMAKE_VERSION VERSION_LESS \"3.28\"\n"
+ " OR NOT DEFINED "
+ "_cmake_import_check_xcframework_for_${_cmake_target}\n"
+ " OR NOT IS_DIRECTORY "
+ "\"${_cmake_import_check_xcframework_for_${_cmake_target}}\")\n"
+ " foreach(_cmake_file IN LISTS "
+ "\"_cmake_import_check_files_for_${_cmake_target}\")\n"
+ " if(NOT EXISTS \"${_cmake_file}\")\n"
+ " message(FATAL_ERROR \"The imported target "
+ "\\\"${_cmake_target}\\\" references the file\n"
" \\\"${_cmake_file}\\\"\n"
"but this file does not exist. Possible reasons include:\n"
"* The file was deleted, renamed, or moved to another location.\n"
@@ -1322,8 +1348,9 @@ void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
" \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
"but not all the files it references.\n"
"\")\n"
- " endif()\n"
- " endforeach()\n"
+ " endif()\n"
+ " endforeach()\n"
+ " endif()\n"
" unset(_cmake_file)\n"
" unset(\"_cmake_import_check_files_for_${_cmake_target}\")\n"
"endforeach()\n"
@@ -1336,15 +1363,18 @@ void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
void cmExportFileGenerator::GenerateImportedFileChecksCode(
std::ostream& os, cmGeneratorTarget* target,
ImportPropertyMap const& properties,
- const std::set<std::string>& importedLocations)
+ const std::set<std::string>& importedLocations,
+ const std::string& importedXcFrameworkLocation)
{
// Construct the imported target name.
std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
- os << "list(APPEND _cmake_import_check_targets " << targetName
- << " )\n"
- "list(APPEND _cmake_import_check_files_for_"
- << targetName << " ";
+ os << "list(APPEND _cmake_import_check_targets " << targetName << " )\n";
+ if (!importedXcFrameworkLocation.empty()) {
+ os << "set(_cmake_import_check_xcframework_for_" << targetName << ' '
+ << cmExportFileGeneratorEscape(importedXcFrameworkLocation) << ")\n";
+ }
+ os << "list(APPEND _cmake_import_check_files_for_" << targetName << " ";
for (std::string const& li : importedLocations) {
auto pi = properties.find(li);
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index ccc10d8..554dd4a 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -84,14 +84,15 @@ protected:
virtual void GenerateImportTargetCode(std::ostream& os,
cmGeneratorTarget const* target,
cmStateEnums::TargetType targetType);
- virtual void GenerateImportPropertyCode(std::ostream& os,
- const std::string& config,
- cmGeneratorTarget const* target,
- ImportPropertyMap const& properties);
+ virtual void GenerateImportPropertyCode(
+ std::ostream& os, const std::string& config, const std::string& suffix,
+ cmGeneratorTarget const* target, ImportPropertyMap const& properties,
+ const std::string& importedXcFrameworkLocation);
virtual void GenerateImportedFileChecksCode(
std::ostream& os, cmGeneratorTarget* target,
ImportPropertyMap const& properties,
- const std::set<std::string>& importedLocations);
+ const std::set<std::string>& importedLocations,
+ const std::string& importedXcFrameworkLocation);
virtual void GenerateImportedFileCheckLoop(std::ostream& os);
virtual void GenerateMissingTargetsCheckCode(std::ostream& os);
virtual void GenerateFindDependencyCalls(std::ostream& os);
diff --git a/Source/cmExportInstallAndroidMKGenerator.cxx b/Source/cmExportInstallAndroidMKGenerator.cxx
index 7dfdc0e..eaa85f3 100644
--- a/Source/cmExportInstallAndroidMKGenerator.cxx
+++ b/Source/cmExportInstallAndroidMKGenerator.cxx
@@ -80,8 +80,8 @@ void cmExportInstallAndroidMKGenerator::GenerateExpectedTargetsCode(
}
void cmExportInstallAndroidMKGenerator::GenerateImportPropertyCode(
- std::ostream&, const std::string&, cmGeneratorTarget const*,
- ImportPropertyMap const&)
+ std::ostream&, const std::string&, const std::string&,
+ cmGeneratorTarget const*, ImportPropertyMap const&, const std::string&)
{
}
@@ -122,7 +122,7 @@ void cmExportInstallAndroidMKGenerator::GenerateImportedFileCheckLoop(
void cmExportInstallAndroidMKGenerator::GenerateImportedFileChecksCode(
std::ostream&, cmGeneratorTarget*, ImportPropertyMap const&,
- const std::set<std::string>&)
+ const std::set<std::string>&, const std::string&)
{
}
diff --git a/Source/cmExportInstallAndroidMKGenerator.h b/Source/cmExportInstallAndroidMKGenerator.h
index 9454cdf..b1778ef 100644
--- a/Source/cmExportInstallAndroidMKGenerator.h
+++ b/Source/cmExportInstallAndroidMKGenerator.h
@@ -45,9 +45,9 @@ protected:
void GenerateExpectedTargetsCode(
std::ostream& os, const std::string& expectedTargets) override;
void GenerateImportPropertyCode(
- std::ostream& os, const std::string& config,
- cmGeneratorTarget const* target,
- ImportPropertyMap const& properties) override;
+ std::ostream& os, const std::string& config, const std::string& suffix,
+ cmGeneratorTarget const* target, ImportPropertyMap const& properties,
+ const std::string& importedXcFrameworkLocation) override;
void GenerateMissingTargetsCheckCode(std::ostream& os) override;
void GenerateFindDependencyCalls(std::ostream&) override {}
void GenerateInterfaceProperties(
@@ -60,6 +60,7 @@ protected:
void GenerateImportedFileChecksCode(
std::ostream& os, cmGeneratorTarget* target,
ImportPropertyMap const& properties,
- const std::set<std::string>& importedLocations) override;
+ const std::set<std::string>& importedLocations,
+ const std::string& importedXcFrameworkLocation) override;
bool GenerateImportFileConfig(const std::string& config) override;
};
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index b829edd..64e694c 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -375,9 +375,26 @@ void cmExportInstallFileGenerator::GenerateImportTargetsConfig(
// properties);
// Generate code in the export file.
- this->GenerateImportPropertyCode(os, config, gtgt, properties);
- this->GenerateImportedFileChecksCode(os, gtgt, properties,
- importedLocations);
+ std::string importedXcFrameworkLocation = te->XcFrameworkLocation;
+ if (!importedXcFrameworkLocation.empty()) {
+ importedXcFrameworkLocation = cmGeneratorExpression::Preprocess(
+ importedXcFrameworkLocation,
+ cmGeneratorExpression::PreprocessContext::InstallInterface, true);
+ importedXcFrameworkLocation = cmGeneratorExpression::Evaluate(
+ importedXcFrameworkLocation, te->Target->GetLocalGenerator(), config,
+ te->Target, nullptr, te->Target);
+ if (!importedXcFrameworkLocation.empty() &&
+ !cmSystemTools::FileIsFullPath(importedXcFrameworkLocation) &&
+ !cmHasLiteralPrefix(importedXcFrameworkLocation,
+ "${_IMPORT_PREFIX}/")) {
+ importedXcFrameworkLocation =
+ cmStrCat("${_IMPORT_PREFIX}/", importedXcFrameworkLocation);
+ }
+ }
+ this->GenerateImportPropertyCode(os, config, suffix, gtgt, properties,
+ importedXcFrameworkLocation);
+ this->GenerateImportedFileChecksCode(
+ os, gtgt, properties, importedLocations, importedXcFrameworkLocation);
}
}
}
diff --git a/Source/cmExportSet.cxx b/Source/cmExportSet.cxx
index aa32394..b32bb8d 100644
--- a/Source/cmExportSet.cxx
+++ b/Source/cmExportSet.cxx
@@ -72,6 +72,16 @@ void cmExportSet::AddInstallation(cmInstallExportGenerator const* installation)
this->Installations.push_back(installation);
}
+void cmExportSet::SetXcFrameworkLocation(const std::string& name,
+ const std::string& location)
+{
+ for (auto& te : this->TargetExports) {
+ if (name == te->TargetName) {
+ te->XcFrameworkLocation = location;
+ }
+ }
+}
+
cmExportSet& cmExportSetMap::operator[](const std::string& name)
{
auto it = this->find(name);
diff --git a/Source/cmExportSet.h b/Source/cmExportSet.h
index c5fc91f..f2fc4a7 100644
--- a/Source/cmExportSet.h
+++ b/Source/cmExportSet.h
@@ -33,6 +33,9 @@ public:
void AddInstallation(cmInstallExportGenerator const* installation);
+ void SetXcFrameworkLocation(const std::string& name,
+ const std::string& location);
+
std::string const& GetName() const { return this->Name; }
std::vector<std::unique_ptr<cmTargetExport>> const& GetTargetExports() const
diff --git a/Source/cmTargetExport.h b/Source/cmTargetExport.h
index 0dac5ca..caeb54d 100644
--- a/Source/cmTargetExport.h
+++ b/Source/cmTargetExport.h
@@ -38,4 +38,5 @@ public:
///@}
bool NamelinkOnly = false;
+ std::string XcFrameworkLocation;
};