diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py index 9a76bbb9ded..f8ed3a83e2d 100644 --- a/conans/client/build/cmake_flags.py +++ b/conans/client/build/cmake_flags.py @@ -1,4 +1,5 @@ import os +import platform from collections import OrderedDict from conans.client import tools @@ -294,9 +295,12 @@ def get_definitions(self): definitions.update(build_type_definition(self._forced_build_type, build_type, self._generator, self._output)) - if str(os_) == "Macos": - if arch == "x86": - definitions["CMAKE_OSX_ARCHITECTURES"] = "i386" + if tools.is_apple_os(os_): + definitions["CMAKE_OSX_ARCHITECTURES"] = tools.to_apple_arch(arch) + # xcrun is only available on macOS, otherwise it's cross-compiling and it needs to be + # set within CMake toolchain + if platform.system() == "Darwin": + definitions["CMAKE_OSX_SYSROOT"] = tools.XCRun(self._conanfile.settings).sdk_path definitions.update(self._cmake_cross_build_defines()) definitions.update(self._get_cpp_standard_vars()) diff --git a/conans/test/unittests/client/build/cmake_test.py b/conans/test/unittests/client/build/cmake_test.py index dc2fc6acba3..9c8a961b75a 100644 --- a/conans/test/unittests/client/build/cmake_test.py +++ b/conans/test/unittests/client/build/cmake_test.py @@ -1307,8 +1307,9 @@ def install_definitions_test(self): ("iOS", "7.0",), ("watchOS", "4.0",), ("tvOS", "11.0",)]) - @mock.patch('platform.system', return_value="Macos") - def test_cmake_system_version_osx(self, the_os, os_version, _): + @mock.patch("platform.system", return_value="Darwin") + @mock.patch("conans.client.tools.apple.XCRun.sdk_path", return_value='/opt') + def test_cmake_system_version_osx(self, the_os, os_version, _, __): settings = Settings.loads(get_default_settings_yml()) settings.os = the_os