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 4 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
31 changes: 30 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,33 @@ 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, os_name, os_version):
version_mapping = {
"Macos": {
"10.13": "17", "10.14": "18", "10.15": "19", "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"
}
}
os_version = str(Version(os_version).major) \
if os_name != "Macos" or (os_name == "Macos" and Version(os_version) >= Version("11")) \
else str(os_version)
return version_mapping.get(os_name, {}).get(os_version)

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

Expand All @@ -941,7 +969,8 @@ 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(os_host, sdk_version)
juansblanco marked this conversation as resolved.
Show resolved Hide resolved
_system_processor = to_apple_arch(self._conanfile)
elif os_host != 'Android':
system_name = self._get_generic_system_name()
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -437,7 +437,7 @@ def test_cmaketoolchain_cmake_system_processor_cross_apple():
client.run("install hello.py -pr:h=./profile_ios -pr:b=default -g CMakeToolchain")
toolchain = client.load("conan_toolchain.cmake")
assert "set(CMAKE_SYSTEM_NAME iOS)" in toolchain
assert "set(CMAKE_SYSTEM_VERSION 15.0)" in toolchain
assert "set(CMAKE_SYSTEM_VERSION 21)" in toolchain
assert "set(CMAKE_SYSTEM_PROCESSOR arm64)" in toolchain


Expand Down