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

[feature] Mandatory os.sdk for CMakeToolchain (only AppleSystemBlock block) #10300

Merged
merged 4 commits into from Jan 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions conan/tools/cmake/toolchain.py
Expand Up @@ -350,22 +350,21 @@ def _get_architecture(self):
"armv8": "arm64",
"armv8_32": "arm64_32"}.get(arch, arch)

# TODO: refactor, comes from conans.client.tools.apple.py
def _apple_sdk_name(self):
"""returns proper SDK name suitable for OS and architecture
we're building for (considering simulators)"""
arch = self._conanfile.settings.get_safe('arch')
"""
Returns the 'os.sdk' (SDK name) field value. Every user should specify it because
there could be several ones depending on the OS architecture.

Note: In case of MacOS it'll be the same for all the architectures.
"""
os_ = self._conanfile.settings.get_safe('os')
if arch.startswith('x86'):
return {'Macos': 'macosx',
'iOS': 'iphonesimulator',
'watchOS': 'watchsimulator',
'tvOS': 'appletvsimulator'}.get(os_)
os_sdk = self._conanfile.settings.get_safe('os.sdk')
if os_sdk:
return os_sdk
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
elif os_ == "Macos": # it has only a single value for all the architectures for now
return "macosx"
else:
return {'Macos': 'macosx',
'iOS': 'iphoneos',
'watchOS': 'watchos',
'tvOS': 'appletvos'}.get(os_)
raise ConanException("Please, specify a suitable value for os.sdk.")

def context(self):
os_ = self._conanfile.settings.get_safe("os")
Expand Down
Expand Up @@ -191,8 +191,8 @@ class HELLO_EXPORT Hello
@pytest.mark.skipif(platform.system() != "Darwin", reason="Only OSX")
@pytest.mark.parametrize("settings",
[('',),
('-s os=iOS -s os.version=10.0 -s arch=armv8',),
("-s os=tvOS -s os.version=11.0 -s arch=armv8",)])
('-s os=iOS -s os.sdk=iphoneos -s os.version=10.0 -s arch=armv8',),
("-s os=tvOS -s os.sdk=appletvos -s os.version=11.0 -s arch=armv8",)])
def test_apple_own_framework_cross_build(settings):
client = TestClient()

Expand Down
Expand Up @@ -13,13 +13,15 @@
@pytest.mark.parametrize("op_system", ["Macos", "iOS"])
def test_m1(op_system):
os_version = "os.version=12.0" if op_system == "iOS" else ""
os_sdk = "" if op_system == "Macos" else "os.sdk=iphoneos"
profile = textwrap.dedent("""
include(default)
[settings]
os={}
{}
{}
arch=armv8
""".format(op_system, os_version))
""".format(op_system, os_sdk, os_version))

client = TestClient(path_with_spaces=False)
client.save({"m1": profile}, clean_first=True)
Expand Down
Expand Up @@ -23,6 +23,7 @@ def test_ios():
include(default)
[settings]
os=iOS
os.sdk=iphoneos
os.version=12.0
arch=armv8
[env]
Expand Down
1 change: 1 addition & 0 deletions conans/test/functional/toolchains/ios/test_using_cmake.py
Expand Up @@ -46,6 +46,7 @@ def package(self):
'ios_profile': textwrap.dedent("""
[settings]
os=iOS
os.sdk=iphoneos
os.version=12.0
arch=armv8
compiler=apple-clang
Expand Down
64 changes: 64 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmaketoolchain.py
Expand Up @@ -7,6 +7,7 @@
from conan.tools.cmake.toolchain import Block, GenericSystemBlock
from conans import ConanFile, Settings
from conans.client.conf import get_default_settings_yml
from conans.errors import ConanException
from conans.model.conf import Conf
from conans.model.env_info import EnvValues

Expand Down Expand Up @@ -351,3 +352,66 @@ def test_libcxx_abi_flag():
toolchain = CMakeToolchain(c)
content = toolchain.content
assert '-D_GLIBCXX_USE_CXX11_ABI=1' in content


@pytest.mark.parametrize("os,os_sdk,arch,expected_sdk", [
("Macos", None, "x86_64", "macosx"),
("Macos", None, "armv7", "macosx"),
("iOS", "iphonesimulator", "armv8", "iphonesimulator"),
("watchOS", "watchsimulator", "armv8", "watchsimulator")
])
def test_apple_cmake_osx_sysroot(os, os_sdk, arch, expected_sdk):
"""
Testing if CMAKE_OSX_SYSROOT is correctly set.
Issue related: https://github.com/conan-io/conan/issues/10275
"""
c = ConanFile(Mock(), None)
c.settings = "os", "compiler", "build_type", "arch"
c.initialize(Settings.loads(get_default_settings_yml()), EnvValues())
c.settings.os = os
c.settings.os.sdk = os_sdk
c.settings.build_type = "Release"
c.settings.arch = arch
c.settings.compiler = "apple-clang"
c.settings.compiler.version = "13.0"
c.settings.compiler.libcxx = "libc++"
c.settings.compiler.cppstd = "17"
c.conf = Conf()
c.folders.set_base_generators(".")
c._conan_node = Mock()
c._conan_node.dependencies = []

toolchain = CMakeToolchain(c)
content = toolchain.content
assert 'set(CMAKE_OSX_SYSROOT %s CACHE STRING "" FORCE)' % expected_sdk in content


@pytest.mark.parametrize("os,os_sdk,arch,expected_sdk", [
("iOS", None, "x86_64", ""),
("watchOS", None, "armv8", ""),
("tvOS", None, "x86_64", "")
])
def test_apple_cmake_osx_sysroot_sdk_mandatory(os, os_sdk, arch, expected_sdk):
"""
Testing if CMAKE_OSX_SYSROOT is correctly set.
Issue related: https://github.com/conan-io/conan/issues/10275
"""
c = ConanFile(Mock(), None)
c.settings = "os", "compiler", "build_type", "arch"
c.initialize(Settings.loads(get_default_settings_yml()), EnvValues())
c.settings.os = os
c.settings.os.sdk = os_sdk
c.settings.build_type = "Release"
c.settings.arch = arch
c.settings.compiler = "apple-clang"
c.settings.compiler.version = "13.0"
c.settings.compiler.libcxx = "libc++"
c.settings.compiler.cppstd = "17"
c.conf = Conf()
c.folders.set_base_generators(".")
c._conan_node = Mock()
c._conan_node.dependencies = []

with pytest.raises(ConanException) as excinfo:
CMakeToolchain(c).content()
assert "Please, specify a suitable value for os.sdk." % expected_sdk in str(excinfo.value)