From 5884303e692b342ad444c5ab01caf7c219e735af Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Sun, 21 May 2023 14:26:08 +0200 Subject: Apple Framework: enhance path parsing --- Source/cmGeneratorTarget.cxx | 22 ++++++++-------------- Source/cmGlobalGenerator.cxx | 11 ++++++----- Source/cmGlobalGenerator.h | 26 ++++++++++++++++++++++++-- 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; }; -- cgit v0.12