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

allow confs in CMakeToolchain for user_toolchain #14556

Merged
merged 1 commit into from
Aug 24, 2023
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
6 changes: 1 addition & 5 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,12 @@ def _is_apple_cross_building(self):

def _get_cross_build(self):
user_toolchain = self._conanfile.conf.get("tools.cmake.cmaketoolchain:user_toolchain")
if user_toolchain is not None:
return None, None, None # Will be provided by user_toolchain

system_name = self._conanfile.conf.get("tools.cmake.cmaketoolchain:system_name")
system_version = self._conanfile.conf.get("tools.cmake.cmaketoolchain:system_version")
system_processor = self._conanfile.conf.get("tools.cmake.cmaketoolchain:system_processor")

assert hasattr(self._conanfile, "settings_build")
# TODO: Remove unused if
if hasattr(self._conanfile, "settings_build"):
if not user_toolchain: # try to detect automatically
os_host = self._conanfile.settings.get_safe("os")
arch_host = self._conanfile.settings.get_safe("arch")
if arch_host == "armv8":
Expand Down
35 changes: 35 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,41 @@ def test_cross_build_user_toolchain():
assert "CMAKE_SYSTEM_PROCESSOR" not in toolchain


def test_cross_build_user_toolchain_confs():
# When a user_toolchain is defined in [conf], but other confs are defined, they will be used
windows_profile = textwrap.dedent("""
[settings]
os=Windows
arch=x86_64
""")
rpi_profile = textwrap.dedent("""
[settings]
os=Linux
compiler=gcc
compiler.version=6
compiler.libcxx=libstdc++11
arch=armv8
build_type=Release
[conf]
tools.cmake.cmaketoolchain:user_toolchain+=rpi_toolchain.cmake
tools.cmake.cmaketoolchain:system_name=Linux
tools.cmake.cmaketoolchain:system_processor=aarch64
""")

client = TestClient(path_with_spaces=False)

conanfile = GenConanfile().with_settings("os", "arch", "compiler", "build_type")\
.with_generator("CMakeToolchain")
client.save({"conanfile.py": conanfile,
"rpi": rpi_profile,
"windows": windows_profile})
client.run("install . --profile:build=windows --profile:host=rpi")
toolchain = client.load("conan_toolchain.cmake")

assert "set(CMAKE_SYSTEM_NAME Linux)" in toolchain
assert "set(CMAKE_SYSTEM_PROCESSOR aarch64)" in toolchain


def test_no_cross_build():
windows_profile = textwrap.dedent("""
[settings]
Expand Down