summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2023-05-21 12:26:08 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2023-05-21 12:26:08 (GMT)
commit5884303e692b342ad444c5ab01caf7c219e735af (patch)
tree4d788ac62da34442b8085eda62a99a533f0a65f7
parentf32e275f2993f13e7a9c59bdcc5e1942b23a228d (diff)
downloadCMake-5884303e692b342ad444c5ab01caf7c219e735af.zip
CMake-5884303e692b342ad444c5ab01caf7c219e735af.tar.gz
CMake-5884303e692b342ad444c5ab01caf7c219e735af.tar.bz2
Apple Framework: enhance path parsing
-rw-r--r--Source/cmGeneratorTarget.cxx22
-rw-r--r--Source/cmGlobalGenerator.cxx11
-rw-r--r--Source/cmGlobalGenerator.h26
3 files changed, 38 insertions, 21 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 32f0cbd..f8455c8 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -59,8 +59,6 @@
namespace {
using LinkInterfaceFor = cmGeneratorTarget::LinkInterfaceFor;
-const cmsys::RegularExpression FrameworkRegularExpression(
- "^(.*/)?([^/]*)\\.framework/(.*)$");
const std::string kINTERFACE_LINK_LIBRARIES = "INTERFACE_LINK_LIBRARIES";
const std::string kINTERFACE_LINK_LIBRARIES_DIRECT =
"INTERFACE_LINK_LIBRARIES_DIRECT";
@@ -2434,11 +2432,10 @@ std::string cmGeneratorTarget::GetSOName(
}
// Use the soname given if any.
if (this->IsFrameworkOnApple()) {
- cmsys::RegularExpressionMatch match;
- if (FrameworkRegularExpression.find(info->SOName.c_str(), match)) {
- auto frameworkName = match.match(2);
- auto fileName = match.match(3);
- return cmStrCat(frameworkName, ".framework/", fileName);
+ auto fwDescriptor = this->GetGlobalGenerator()->SplitFrameworkPath(
+ info->SOName, cmGlobalGenerator::FrameworkFormat::Strict);
+ if (fwDescriptor) {
+ return fwDescriptor->GetVersionedName();
}
}
if (cmHasLiteralPrefix(info->SOName, "@rpath/")) {
@@ -7036,13 +7033,10 @@ std::string cmGeneratorTarget::GetDirectory(
if (this->IsImported()) {
auto fullPath = this->Target->ImportedGetFullPath(config, artifact);
if (this->IsFrameworkOnApple()) {
- cmsys::RegularExpressionMatch match;
- if (FrameworkRegularExpression.find(fullPath.c_str(), match)) {
- auto path = match.match(1);
- if (!path.empty()) {
- path.erase(path.length() - 1);
- }
- return path;
+ auto fwDescriptor = this->GetGlobalGenerator()->SplitFrameworkPath(
+ fullPath, cmGlobalGenerator::FrameworkFormat::Strict);
+ if (fwDescriptor) {
+ return fwDescriptor->Directory;
}
}
// Return the directory from which the target is imported.
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 040f500..5d0f8b2 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -2598,14 +2598,14 @@ cmGlobalGenerator::SplitFrameworkPath(const std::string& path,
// or (/path/to/)?FwName.framework/FwName(.tbd)?
// or (/path/to/)?FwName.framework/Versions/*/FwName(.tbd)?
static cmsys::RegularExpression frameworkPath(
- "((.+)/)?(.+)\\.framework(/Versions/[^/]+)?(/(.+))?$");
+ "((.+)/)?([^/]+)\\.framework(/Versions/([^/]+))?(/(.+))?$");
auto ext = cmSystemTools::GetFilenameLastExtension(path);
if ((ext.empty() || ext == ".tbd" || ext == ".framework") &&
frameworkPath.find(path)) {
auto name = frameworkPath.match(3);
auto libname =
- cmSystemTools::GetFilenameWithoutExtension(frameworkPath.match(6));
+ cmSystemTools::GetFilenameWithoutExtension(frameworkPath.match(7));
if (format == FrameworkFormat::Strict && libname.empty()) {
return cm::nullopt;
}
@@ -2614,11 +2614,12 @@ cmGlobalGenerator::SplitFrameworkPath(const std::string& path,
}
if (libname.empty() || name.size() == libname.size()) {
- return FrameworkDescriptor{ frameworkPath.match(2), name };
+ return FrameworkDescriptor{ frameworkPath.match(2),
+ frameworkPath.match(5), name };
}
- return FrameworkDescriptor{ frameworkPath.match(2), name,
- libname.substr(name.size()) };
+ return FrameworkDescriptor{ frameworkPath.match(2), frameworkPath.match(5),
+ name, libname.substr(name.size()) };
}
if (format == FrameworkFormat::Extended) {
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 79fe52c..d657fc8 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -384,9 +384,17 @@ public:
, Name(std::move(name))
{
}
- FrameworkDescriptor(std::string directory, std::string name,
- std::string suffix)
+ FrameworkDescriptor(std::string directory, std::string version,
+ std::string name)
: Directory(std::move(directory))
+ , Version(std::move(version))
+ , Name(std::move(name))
+ {
+ }
+ FrameworkDescriptor(std::string directory, std::string version,
+ std::string name, std::string suffix)
+ : Directory(std::move(directory))
+ , Version(std::move(version))
, Name(std::move(name))
, Suffix(std::move(suffix))
{
@@ -400,6 +408,13 @@ public:
{
return cmStrCat(this->Name, ".framework/"_s, this->Name, this->Suffix);
}
+ std::string GetVersionedName() const
+ {
+ return this->Version.empty()
+ ? this->GetFullName()
+ : cmStrCat(this->Name, ".framework/Versions/"_s, this->Version, '/',
+ this->Name, this->Suffix);
+ }
std::string GetFrameworkPath() const
{
return this->Directory.empty()
@@ -412,8 +427,15 @@ public:
? this->GetFullName()
: cmStrCat(this->Directory, '/', this->GetFullName());
}
+ std::string GetVersionedPath() const
+ {
+ return this->Directory.empty()
+ ? this->GetVersionedName()
+ : cmStrCat(this->Directory, '/', this->GetVersionedName());
+ }
const std::string Directory;
+ const std::string Version;
const std::string Name;
const std::string Suffix;
};