Xcode: Clean library paths to avoid linker duplicate symbol definitions

This commit is contained in:
Gusts Kaksis
2020-11-15 11:08:21 +02:00
committed by Craig Scott
parent c35c4ae85c
commit b1ef2fffe7
+20 -10
View File
@@ -3442,10 +3442,16 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
if (!libTarget) { if (!libTarget) {
if (libItem->IsPath) { if (libItem->IsPath) {
// Get or create a direct file ref in the root project // Get or create a direct file ref in the root project
auto it = this->ExternalLibRefs.find(libItem->Value.Value); auto cleanPath = libItem->Value.Value;
if (cmSystemTools::FileIsFullPath(cleanPath)) {
// Some arguments are reported as paths, but they are actually not,
// so we can't collapse them, and neither can we collapse relative
// paths
cleanPath = cmSystemTools::CollapseFullPath(cleanPath);
}
auto it = this->ExternalLibRefs.find(cleanPath);
if (it == this->ExternalLibRefs.end()) { if (it == this->ExternalLibRefs.end()) {
buildFile = CreateXCodeBuildFileFromPath(libItem->Value.Value, gt, buildFile = CreateXCodeBuildFileFromPath(cleanPath, gt, "", nullptr);
"", nullptr);
if (!buildFile) { if (!buildFile) {
// Add this library item back to a regular linker flag list // Add this library item back to a regular linker flag list
for (const auto& conf : configItemMap) { for (const auto& conf : configItemMap) {
@@ -3453,7 +3459,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
} }
continue; continue;
} }
this->ExternalLibRefs.emplace(libItem->Value.Value, buildFile); this->ExternalLibRefs.emplace(cleanPath, buildFile);
} else { } else {
buildFile = it->second; buildFile = it->second;
} }
@@ -3585,7 +3591,11 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
for (auto const& libItem : configItemMap[configName]) { for (auto const& libItem : configItemMap[configName]) {
auto const& libName = *libItem; auto const& libName = *libItem;
if (libName.IsPath) { if (libName.IsPath) {
const auto libPath = GetLibraryOrFrameworkPath(libName.Value.Value); auto cleanPath = libName.Value.Value;
if (cmSystemTools::FileIsFullPath(cleanPath)) {
cleanPath = cmSystemTools::CollapseFullPath(cleanPath);
}
const auto libPath = GetLibraryOrFrameworkPath(cleanPath);
if (cmSystemTools::StringEndsWith(libPath.c_str(), ".framework")) { if (cmSystemTools::StringEndsWith(libPath.c_str(), ".framework")) {
const auto fwName = const auto fwName =
cmSystemTools::GetFilenameWithoutExtension(libPath); cmSystemTools::GetFilenameWithoutExtension(libPath);
@@ -3593,17 +3603,17 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
libPaths.Add("-F " + this->XCodeEscapePath(fwDir)); libPaths.Add("-F " + this->XCodeEscapePath(fwDir));
libPaths.Add("-framework " + fwName); libPaths.Add("-framework " + fwName);
} else { } else {
libPaths.Add(this->XCodeEscapePath(libName.Value.Value)); libPaths.Add(this->XCodeEscapePath(cleanPath));
} }
if ((!libName.Target || libName.Target->IsImported()) && if ((!libName.Target || libName.Target->IsImported()) &&
IsLinkPhaseLibraryExtension(libPath)) { IsLinkPhaseLibraryExtension(libPath)) {
// Create file reference for embedding // Create file reference for embedding
auto it = this->ExternalLibRefs.find(libName.Value.Value); auto it = this->ExternalLibRefs.find(cleanPath);
if (it == this->ExternalLibRefs.end()) { if (it == this->ExternalLibRefs.end()) {
auto* buildFile = this->CreateXCodeBuildFileFromPath( auto* buildFile =
libName.Value.Value, gt, "", nullptr); this->CreateXCodeBuildFileFromPath(cleanPath, gt, "", nullptr);
if (buildFile) { if (buildFile) {
this->ExternalLibRefs.emplace(libName.Value.Value, buildFile); this->ExternalLibRefs.emplace(cleanPath, buildFile);
} }
} }
} }