diff --git a/bin/BuildSystem/CMakeBuildSystem.py b/bin/BuildSystem/CMakeBuildSystem.py --- a/bin/BuildSystem/CMakeBuildSystem.py +++ b/bin/BuildSystem/CMakeBuildSystem.py @@ -60,8 +60,9 @@ if OsUtils.isMac(): options += f" -DKDE_INSTALL_BUNDLEDIR=\"{OsUtils.toUnixPath(CraftCore.standardDirs.craftRoot())}/Applications/KDE\" -DAPPLE_SUPPRESS_X11_WARNING=ON" - # Ensure that we don't depend on SDK features only present on newer systems - options += " -DCMAKE_OSX_DEPLOYMENT_TARGET=" + CraftCore.compiler.macOSDeploymentTarget + if CraftCore.compiler.macUseSDK: + # Ensure that we don't depend on SDK features only present on newer systems + options += " -DCMAKE_OSX_DEPLOYMENT_TARGET=" + CraftCore.compiler.macOSDeploymentTarget if CraftCore.compiler.isWindows or CraftCore.compiler.isMacOS: options += " -DKDE_INSTALL_USE_QT_SYS_PATHS=ON" diff --git a/bin/CraftCompiler.py b/bin/CraftCompiler.py --- a/bin/CraftCompiler.py +++ b/bin/CraftCompiler.py @@ -151,9 +151,15 @@ @property def macOSDeploymentTarget(self) -> str: - assert self.isMacOS + assert self.macUseSDK return "10.11" + @property + def macUseSDK(self) -> bool: + assert self.isMacOS + """Whether to compile against the macOS SDK instead of the libraries in /usr (off by default)""" + return CraftCore.settings.getboolean("MacSDK", "Enabled", "False") + @property def isWindows(self) -> bool: return self.platform == CraftCompiler.Platforms.Windows @@ -306,3 +312,7 @@ print("Compiler Version: %s" % CraftCore.compiler.getGCCLikeVersion(CraftCore.compiler.compiler.name)) if CraftCore.compiler.isGCC(): print("Compiler Target: %s" % CraftCore.compiler._getGCCTarget()) + if CraftCore.compiler.isMacOS: + print("Using SDK for macOS:", CraftCore.compiler.macUseSDK) + if CraftCore.compiler.macUseSDK: + print("macOS SDK deployment target:", CraftCore.compiler.macOSDeploymentTarget) diff --git a/bin/shells.py b/bin/shells.py --- a/bin/shells.py +++ b/bin/shells.py @@ -38,12 +38,18 @@ # libraries installed by homebrew (causes errors e.g. with iconv since headers will be # found in /usr/local/include first but libraries are searched for in /usr/lib before # /usr/local/lib. See https://langui.sh/2015/07/24/osx-clang-include-lib-search-paths/ - sdkPath = CraftCore.cache.getCommandOutput("xcrun", "--show-sdk-path")[1].strip() - deploymentFlag = "-mmacosx-version-min=" + CraftCore.compiler.macOSDeploymentTarget - cflags = f" -isysroot {sdkPath} {deploymentFlag}" + cflags - # See https://github.com/Homebrew/homebrew-core/issues/2674 for the -no_weak_imports flag - ldflags = f" -isysroot {sdkPath} {deploymentFlag} -Wl,-no_weak_imports" + ldflags - # Note: MACOSX_DEPLOYMENT_TARGET is set in utils.system() so doesn't need to be set here + if CraftCore.compiler.macUseSDK: + sdkPath = CraftCore.cache.getCommandOutput("xcrun", "--show-sdk-path")[1].strip() + deploymentFlag = "-mmacosx-version-min=" + CraftCore.compiler.macOSDeploymentTarget + cflags = f" -isysroot {sdkPath} {deploymentFlag}" + cflags + # See https://github.com/Homebrew/homebrew-core/issues/2674 for the -no_weak_imports flag + ldflags = f" -isysroot {sdkPath} {deploymentFlag} -Wl,-no_weak_imports" + ldflags + # Note: MACOSX_DEPLOYMENT_TARGET is set in utils.system() so doesn't need to be set here + else: + # Ensure that /usr/include comes before /usr/local/include in the header search path to avoid + # pulling in headers from /usr/local/include (e.g. installed by homebrew) that will cause + # linker errors later. + cflags = " -isystem /usr/include " + cflags if CraftCore.compiler.isMSVC(): # based on Windows-MSVC.cmake diff --git a/bin/utils.py b/bin/utils.py --- a/bin/utils.py +++ b/bin/utils.py @@ -218,7 +218,7 @@ CraftCore.log.debug(f"executing command: {cmd!r}") CraftCore.log.debug(f"CWD: {cwd!r}") CraftCore.log.debug(f"displayProgress={displayProgress}") - if CraftCore.compiler.isMacOS: + if CraftCore.compiler.macUseSDK: environment["MACOSX_DEPLOYMENT_TARGET"] = CraftCore.compiler.macOSDeploymentTarget CraftCore.debug.logEnv(environment) if pipeProcess: