diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index d1680ad220..b9f15b70e8 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -474,6 +474,12 @@ std::vector const& cmComputeLinkInformation::GetFrameworkPaths() return this->FrameworkPaths; } +std::set const& +cmComputeLinkInformation::GetFrameworkPathsEmitted() const +{ + return this->FrameworkPathsEmitted; +} + const std::set& cmComputeLinkInformation::GetSharedLibrariesLinked() const { diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index d8ec5635d7..9fec702065 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -55,6 +55,7 @@ public: std::vector> GetDirectoriesWithBacktraces(); std::vector const& GetDepends() const; std::vector const& GetFrameworkPaths() const; + std::set const& GetFrameworkPathsEmitted() const; std::string GetLinkLanguage() const { return this->LinkLanguage; } std::vector const& GetRuntimeSearchPath() const; std::string const& GetRuntimeFlag() const { return this->RuntimeFlag; } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index df45b35230..51a7915329 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3620,6 +3620,15 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) // now add the left-over link libraries { + // Keep track of framework search paths we've already added or that are + // part of the set of implicit search paths. We don't want to repeat + // them and we also need to avoid hard-coding any SDK-specific paths. + // This is essential for getting device-and-simulator builds to work, + // otherwise we end up hard-coding a path to the wrong SDK for + // SDK-provided frameworks that are added by their full path. + std::set emitted(cli->GetFrameworkPathsEmitted()); + const auto& fwPaths = cli->GetFrameworkPaths(); + emitted.insert(fwPaths.begin(), fwPaths.end()); BuildObjectListOrString libPaths(this, true); for (auto const& libItem : configItemMap[configName]) { auto const& libName = *libItem; @@ -3633,7 +3642,11 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) const auto fwName = cmSystemTools::GetFilenameWithoutExtension(libPath); const auto fwDir = cmSystemTools::GetParentDirectory(libPath); - libPaths.Add("-F " + this->XCodeEscapePath(fwDir)); + if (emitted.insert(fwDir).second) { + // This is a search path we had not added before and it isn't an + // implicit search path, so we need it + libPaths.Add("-F " + this->XCodeEscapePath(fwDir)); + } libPaths.Add("-framework " + fwName); } else { libPaths.Add(this->XCodeEscapePath(cleanPath));