Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/XcodeDeps enable custom configurations (#14149) #14168

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions conan/tools/apple/xcodedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def _xcconfig_settings_filename(settings):
return _format_name(name)


def _xcconfig_conditional(settings):
def _xcconfig_conditional(settings, configuration):
sdk_condition = "*"
arch = settings.get_safe("arch")
architecture = _to_apple_arch(arch) or arch
sdk = settings.get_safe("os.sdk") if settings.get_safe("os") != "Macos" else "macosx"
if sdk:
sdk_condition = "{}{}".format(sdk, settings.get_safe("os.sdk_version") or "*")

return "[config={}][arch={}][sdk={}]".format(settings.get_safe("build_type"), architecture, sdk_condition)
return "[config={}][arch={}][sdk={}]".format(configuration, architecture, sdk_condition)


def _add_includes_to_file_or_create(filename, template, files_to_include):
Expand Down Expand Up @@ -149,7 +149,7 @@ def _merged_vars(name):
'cxx_compiler_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("cxxflags")),
'linker_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("sharedlinkflags")),
'exe_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("exelinkflags")),
'condition': _xcconfig_conditional(self._conanfile.settings)
'condition': _xcconfig_conditional(self._conanfile.settings, self.configuration)
}

if not require.headers:
Expand Down
6 changes: 3 additions & 3 deletions conan/tools/apple/xcodetoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ def _cppstd(self):

@property
def _macosx_deployment_target(self):
return 'MACOSX_DEPLOYMENT_TARGET{}={}'.format(_xcconfig_conditional(self._conanfile.settings),
return 'MACOSX_DEPLOYMENT_TARGET{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
self.os_version) if self.os_version else ""

@property
def _clang_cxx_library(self):
return 'CLANG_CXX_LIBRARY{}={}'.format(_xcconfig_conditional(self._conanfile.settings),
return 'CLANG_CXX_LIBRARY{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
self.libcxx) if self.libcxx else ""

@property
def _clang_cxx_language_standard(self):
return 'CLANG_CXX_LANGUAGE_STANDARD{}={}'.format(_xcconfig_conditional(self._conanfile.settings),
return 'CLANG_CXX_LANGUAGE_STANDARD{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
self._cppstd) if self._cppstd else ""
@property
def _vars_xconfig_filename(self):
Expand Down
63 changes: 60 additions & 3 deletions conans/test/integration/toolchains/apple/test_xcodedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def expected_files(current_folder, configuration, architecture, sdk_version):
return files


def check_contents(client, deps, configuration, architecture, sdk_version):
def check_contents(client, deps, build_type, architecture, sdk_version, custom_config_name=None):
for dep_name in deps:
dep_xconfig = client.load("conan_{dep}_{dep}.xcconfig".format(dep=dep_name))
conf_name = "conan_{}_{}{}.xcconfig".format(dep_name, dep_name,
_get_filename(configuration, architecture, sdk_version))
_get_filename(build_type, architecture, sdk_version))
wAuner marked this conversation as resolved.
Show resolved Hide resolved

assert '#include "{}"'.format(conf_name) in dep_xconfig
for var in _expected_dep_xconfig:
Expand All @@ -53,7 +53,8 @@ def check_contents(client, deps, configuration, architecture, sdk_version):

conan_conf = client.load(conf_name)
for var in _expected_conf_xconfig:
assert var.format(name=dep_name, configuration=configuration, architecture=architecture,
xcode_config_name = custom_config_name if custom_config_name else build_type
assert var.format(name=dep_name, configuration=xcode_config_name, architecture=architecture,
sdk="macosx", sdk_version=sdk_version) in conan_conf


Expand Down Expand Up @@ -89,6 +90,62 @@ def test_generator_files():
check_contents(client, ["hello", "goodbye"], build_type, "x86_64", "12.1")


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
def test_generator_files_with_custom_config():
client = TestClient()

client.save({"hello.py": GenConanfile().with_settings("os", "arch", "compiler", "build_type")
.with_package_info(cpp_info={"libs": ["hello"]},
env_info={})})
client.run("export hello.py --name=hello --version=0.1")

client.save({"goodbye.py": GenConanfile().with_settings("os", "arch", "compiler", "build_type")
.with_package_info(cpp_info={"libs": ["goodbye"]},
env_info={})})
client.run("export goodbye.py --name=goodbye --version=0.1")

conanfile_py = textwrap.dedent("""
from conan import ConanFile
from conan.tools.apple import XcodeDeps
class LibConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {"XcodeConfigName": [None, "ANY"]}
default_options = {"XcodeConfigName": None}
requires = "hello/0.1", "goodbye/0.1"

def generate(self):
xcode = XcodeDeps(self)
if self.options.get_safe("XcodeConfigName"):
xcode.configuration = str(self.options.get_safe("XcodeConfigName"))
xcode.generate()
""")

client.save({"conanfile.py": conanfile_py})
custom_config_name = "CustomConfig"

for use_custom_config in [True, False]:
for build_type in ["Release", "Debug"]:
cli_command = "install . -s build_type={} -s arch=x86_64 -s os.sdk_version=12.1 --build missing".format(build_type)
if use_custom_config:
cli_command += " -o XcodeConfigName={}".format(custom_config_name)

client.run(cli_command)

for config_file in expected_files(client.current_folder, build_type, "x86_64", "12.1"):
assert os.path.isfile(config_file)

conandeps = client.load("conandeps.xcconfig")
assert '#include "conan_hello.xcconfig"' in conandeps
assert '#include "conan_goodbye.xcconfig"' in conandeps

conan_config = client.load("conan_config.xcconfig")
assert '#include "conandeps.xcconfig"' in conan_config

if use_custom_config:
check_contents(client, ["hello", "goodbye"], build_type, "x86_64", "12.1", custom_config_name)
else:
check_contents(client, ["hello", "goodbye"], build_type, "x86_64", "12.1")

@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
def test_xcodedeps_aggregate_components():
client = TestClient()
Expand Down