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 autodetect CMAKE_SYSTEM_VERSION to convert to Darwin version #16335

Merged
merged 8 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
68 changes: 67 additions & 1 deletion conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from conan.tools.microsoft.visual import msvc_version_to_toolset_version
from conans.client.subsystems import deduce_subsystem, WINDOWS
from conan.errors import ConanException
from conans.model.version import Version
from conans.util.files import load


Expand Down Expand Up @@ -919,6 +920,65 @@ def _is_apple_cross_building(self):
return os_host in ('iOS', 'watchOS', 'tvOS', 'visionOS') or (
os_host == 'Macos' and (arch_host != arch_build or os_build != os_host))

def _get_darwin_version(self, system_name, os_version):
juansblanco marked this conversation as resolved.
Show resolved Hide resolved
juansblanco marked this conversation as resolved.
Show resolved Hide resolved
darwin_versions = {
"macos_old": {
"10.13": "17",
"10.14": "18",
"10.15": "19"
},
"macos_new": {
"11": "20",
"12": "21",
"13": "22",
"14": "23",
},
"iOS": {
czoido marked this conversation as resolved.
Show resolved Hide resolved
"11": "17",
"12": "18",
"13": "19",
"14": "20",
"15": "21",
"16": "22",
"17": "23"
},
"watchOS": {
"4": "17",
"5": "18",
"6": "19",
"7": "20",
"8": "21",
"9": "22",
"10": "23"
},
"tvOS": {
"11": "17",
"12": "18",
"13": "19",
"14": "20",
"15": "21",
"16": "22",
"17": "23"
},
"visionOS": {
"1": "23"
}
}
if os_version is None:
return None
major_os_version = str(Version(os_version).major)
if system_name == "Darwin":
if Version(os_version) < 11:
if os_version in darwin_versions.get("macos_old"):
return darwin_versions.get("macos_old").get(os_version)
else:
if major_os_version in darwin_versions.get("macos_new"):
return darwin_versions.get("macos_new").get(major_os_version)
elif system_name in darwin_versions:
if major_os_version in darwin_versions.get(system_name):
return darwin_versions.get(system_name).get(major_os_version)
raise ConanException("Unsupported macOS version: %s" % os_version)
juansblanco marked this conversation as resolved.
Show resolved Hide resolved

def _get_cross_build(self):
user_toolchain = self._conanfile.conf.get("tools.cmake.cmaketoolchain:user_toolchain")

Expand All @@ -941,8 +1001,14 @@ def _get_cross_build(self):
# cross-build in Macos also for M1
system_name = {'Macos': 'Darwin'}.get(os_host, os_host)
# CMAKE_SYSTEM_VERSION for Apple sets the sdk version, not the os version
_system_version = self._conanfile.settings.get_safe("os.sdk_version")
sdk_version = self._conanfile.settings.get_safe("os.sdk_version")
_system_version = self._get_darwin_version(system_name, sdk_version)
_system_processor = to_apple_arch(self._conanfile)
elif os_host in ('Macos', 'iOS', 'watchOS', 'tvOS', 'visionOS'):
system_name = self._get_generic_system_name()
os_version = self._conanfile.settings.get_safe("os.version")
_system_version = self._get_darwin_version(system_name, os_version)
_system_processor = arch_host
elif os_host != 'Android':
system_name = self._get_generic_system_name()
_system_version = self._conanfile.settings.get_safe("os.version")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_cross_build_linux_to_macos():
toolchain = client.load("conan_toolchain.cmake")

assert "set(CMAKE_SYSTEM_NAME Darwin)" in toolchain
assert "set(CMAKE_SYSTEM_VERSION 13.1)" in toolchain
assert "set(CMAKE_SYSTEM_VERSION 22)" in toolchain
assert "set(CMAKE_SYSTEM_PROCESSOR x86_64)" in toolchain


Expand Down