Skip to content
Merged
9 changes: 7 additions & 2 deletions conan/tools/apple/xcodetoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class XcodeToolchain:
{cflags}
{cppflags}
{ldflags}
{extra}
""")

_agreggated_xconfig = textwrap.dedent("""\
Expand All @@ -45,6 +46,7 @@ def __init__(self, conanfile):
sharedlinkflags = self._conanfile.conf.get("tools.build:sharedlinkflags", default=[], check_type=list)
exelinkflags = self._conanfile.conf.get("tools.build:exelinkflags", default=[], check_type=list)
self._global_ldflags = sharedlinkflags + exelinkflags
self.build_settings = {}

def generate(self):
check_duplicated_generator(self, self._conanfile)
Expand Down Expand Up @@ -115,7 +117,8 @@ def _agreggated_xconfig_filename(self):

@property
def _check_if_extra_flags(self):
return self._global_cflags or self._global_cxxflags or self._global_ldflags or self._global_defines
return (self._global_cflags or self._global_cxxflags or self._global_ldflags
or self._global_defines or self.build_settings)

@property
def _flags_xcconfig_content(self):
Expand All @@ -126,7 +129,9 @@ def _flags_xcconfig_content(self):
cflags = "OTHER_CFLAGS{} = $(inherited) {}".format(condition, " ".join(self._global_cflags)) if self._global_cflags else ""
cppflags = "OTHER_CPLUSPLUSFLAGS{} = $(inherited) {}".format(condition, " ".join(self._global_cxxflags)) if self._global_cxxflags else ""
ldflags = "OTHER_LDFLAGS{} = $(inherited) {}".format(condition, " ".join(self._global_ldflags)) if self._global_ldflags else ""
ret = self._flags_xconfig.format(defines=defines, cflags=cflags, cppflags=cppflags, ldflags=ldflags)
extra = "\n".join("{}{} = {}".format(k, condition, v) for k, v in self.build_settings.items())
ret = self._flags_xconfig.format(defines=defines, cflags=cflags, cppflags=cppflags, ldflags=ldflags,
extra=extra)
return ret

@property
Expand Down
22 changes: 22 additions & 0 deletions test/integration/toolchains/apple/test_xcodetoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ def test_toolchain_flags():
assert '#include "conan_global_flags.xcconfig"' in conan_global_file


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
def test_toolchain_build_settings():
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.apple import XcodeToolchain
class Demo(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def generate(self):
tc = XcodeToolchain(self)
tc.build_settings["OTHER_SWIFT_FLAGS"] = "$(inherited) -cxx-interoperability-mode=default"
tc.generate()
""")
client.save({"conanfile.py": conanfile})
client.run("install . -s build_type=Release -s arch=x86_64")
filename = _get_filename("Release", "x86_64", None)
condition = _condition("Release", "x86_64", None)

conan_global_flags_props = client.load("conan_global_flags{}.xcconfig".format(filename))
assert "OTHER_SWIFT_FLAGS{} = $(inherited) -cxx-interoperability-mode=default".format(condition) in conan_global_flags_props


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
def test_flags_generated_if_only_defines():
# https://github.com/conan-io/conan/issues/16422
Expand Down
Loading