From 40be88a92e65eb237a3b455255514f9a98274467 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 8 Feb 2024 19:50:41 -0500 Subject: visionOS: Update deployment-target flag for Xcode 15.1 beta Use the same flags Xcode adds for `XROS_DEPLOYMENT_TARGET`. They are `-target arm64-apple-xros1.0` and `-target arm64-apple-xros1.0-simulator`, where `1.0` is the deployment target version. Fixes: #25188 --- Modules/Platform/Apple-Clang.cmake | 6 +++--- Source/cmLocalGenerator.cxx | 39 +++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Modules/Platform/Apple-Clang.cmake b/Modules/Platform/Apple-Clang.cmake index 57b3910..61a6cd2 100644 --- a/Modules/Platform/Apple-Clang.cmake +++ b/Modules/Platform/Apple-Clang.cmake @@ -26,10 +26,10 @@ macro(__apple_compiler_clang lang) set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtvos-version-min=") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/AppleTVSimulator") set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtvos-simulator-version-min=") - elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XROS") - set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtargetos=xros") + elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XROS") + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "--target=-apple-xros") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XRSimulator") - set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtargetos=xros") + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "--target=-apple-xros-simulator") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/WatchOS") set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mwatchos-version-min=") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/WatchSimulator") diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 04d2f50..86c55f5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1983,10 +1983,43 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, "CMAKE_" + lang + "_OSX_DEPLOYMENT_TARGET_FLAG"; cmValue deploymentTargetFlag = this->Makefile->GetDefinition(deploymentTargetFlagVar); - if (cmNonempty(deploymentTargetFlag)) { + if (cmNonempty(deploymentTargetFlag) && + // CMAKE__COMPILER_TARGET overrides a --target= for + // CMAKE_OSX_DEPLOYMENT_TARGET, e.g., for visionOS. + (!cmHasLiteralPrefix(*deploymentTarget, "--target=") || + this->Makefile + ->GetDefinition(cmStrCat("CMAKE_", lang, "_COMPILER_TARGET")) + .IsEmpty())) { + std::string flag = *deploymentTargetFlag; + + // Add the deployment target architecture to the flag, if needed. + static const std::string kARCH = ""; + std::string::size_type archPos = flag.find(kARCH); + if (archPos != std::string::npos) { + // This placeholder is meant for visionOS, so default to arm64 + // unless only non-arm64 archs are given. + std::string const arch = + (archs.empty() || cm::contains(archs, "arm64")) ? "arm64" + : archs[0]; + // Replace the placeholder with its value. + flag = cmStrCat(flag.substr(0, archPos), arch, + flag.substr(archPos + kARCH.size())); + } + + // Add the deployment target version to the flag. + static const std::string kVERSION_MIN = ""; + std::string::size_type verPos = flag.find(kVERSION_MIN); + if (verPos != std::string::npos) { + // Replace the placeholder with its value. + flag = cmStrCat(flag.substr(0, verPos), *deploymentTarget, + flag.substr(verPos + kVERSION_MIN.size())); + } else { + // There is no placeholder, so append the value. + flag = cmStrCat(flag, *deploymentTarget); + } + flags += " "; - flags += *deploymentTargetFlag; - flags += *deploymentTarget; + flags += flag; } } } -- cgit v0.12