Skip to content

Commit

Permalink
allow confs in CMakeToolchain for user_toolchain (#14556)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Aug 24, 2023
1 parent 7e18e68 commit 492323f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
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

0 comments on commit 492323f

Please sign in to comment.