Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion conan/tools/apple/xcodedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(self, conanfile):
self._conanfile = conanfile
self.configuration = conanfile.settings.get_safe("build_type")
arch = conanfile.settings.get_safe("arch")
self.os_version = conanfile.settings.get_safe("os.version")
self.architecture = _to_apple_arch(arch, default=arch)
self.os_version = conanfile.settings.get_safe("os.version")
self.sdk = conanfile.settings.get_safe("os.sdk")
Expand Down
18 changes: 13 additions & 5 deletions conan/tools/apple/xcodetoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class XcodeToolchain(object):

_vars_xconfig = textwrap.dedent("""\
// Definition of toolchain variables
{macosx_deployment_target}
{apple_deployment_target}
{clang_cxx_library}
{clang_cxx_language_standard}
""")
Expand Down Expand Up @@ -63,9 +63,17 @@ def _cppstd(self):
return cppstd

@property
def _macosx_deployment_target(self):
return 'MACOSX_DEPLOYMENT_TARGET{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
self.os_version) if self.os_version else ""
def _apple_deployment_target(self):
deployment_target_key = {
"Macos": "MACOSX_DEPLOYMENT_TARGET",
"iOS": "IPHONEOS_DEPLOYMENT_TARGET",
"tvOS": "TVOS_DEPLOYMENT_TARGET",
"watchOS": "WATCHOS_DEPLOYMENT_TARGET",
"visionOS": "XROS_DEPLOYMENT_TARGET",
}.get(str(self._conanfile.settings.get_safe("os")))
return '{}{}={}'.format(deployment_target_key,
_xcconfig_conditional(self._conanfile.settings, self.configuration),
self.os_version) if self.os_version else ""

@property
def _clang_cxx_library(self):
Expand All @@ -83,7 +91,7 @@ def _vars_xconfig_filename(self):

@property
def _vars_xconfig_content(self):
ret = self._vars_xconfig.format(macosx_deployment_target=self._macosx_deployment_target,
ret = self._vars_xconfig.format(apple_deployment_target=self._apple_deployment_target,
clang_cxx_library=self._clang_cxx_library,
clang_cxx_language_standard=self._clang_cxx_language_standard)
return ret
Expand Down
44 changes: 44 additions & 0 deletions test/integration/toolchains/apple/test_xcodetoolchain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import platform
import re
import textwrap

import pytest

Expand Down Expand Up @@ -83,3 +85,45 @@ def test_flags_generated_if_only_defines():
assert "GCC_PREPROCESSOR_DEFINITIONS = $(inherited) MYDEFINITION" in conan_global_flags
conan_global_file = client.load("conan_config.xcconfig")
assert '#include "conan_global_flags.xcconfig"' in conan_global_file


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
@pytest.mark.parametrize("os_name, sdk, min_version, deployment_target_flag", [
("Macos", None, "11.0", "MACOSX_DEPLOYMENT_TARGET"),
("iOS", "iphoneos", "18.0", "IPHONEOS_DEPLOYMENT_TARGET"),
("tvOS", "appletvos", "18.4", "TVOS_DEPLOYMENT_TARGET"),
("watchOS", "watchos", "9.0", "WATCHOS_DEPLOYMENT_TARGET"),
("visionOS", "xros", "2.0", "XROS_DEPLOYMENT_TARGET"),
])
def test_xcodetoolchain_xcconfig_deplyment_target(os_name, sdk, min_version, deployment_target_flag):
client = TestClient()

conanfile = textwrap.dedent(f"""
import os
from conan import ConanFile
from conan.tools.apple import XcodeToolchain
from conan.tools.files import save
class MyApplicationConan(ConanFile):
name = "myapplication"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
def generate(self):
tc = XcodeToolchain(self)
tc.generate()
# Private access to get the generated xcconfig filename
# It changes based on the settings, so this is the less fragile way to get it
save(self, os.path.join(self.generators_folder, "name.txt"), tc._vars_xconfig_filename)
""")

client.save({"conanfile.py": conanfile})

settings = f"-s os={os_name} -s os.version={min_version}"
if sdk:
settings += f" -s os.sdk={sdk}"

client.run(f"install . -s build_type=Release {settings} --build=missing")

xcconfig_name = client.load("name.txt").strip()
xcconfig = client.load(xcconfig_name)
match = re.search(f"^{deployment_target_flag}.+={min_version}$", xcconfig, re.MULTILINE)
assert match is not None
Loading