Skip to content

Commit

Permalink
Add a fallback in case CMAKE_OSX_ARCHITECTURES isn't set (conan-io#611)
Browse files Browse the repository at this point in the history
* Add a fallback in case CMAKE_OSX_ARCHITECTURES isn't set

conan-io#528 introduced new behaviour to support iOS, tvOS and watchOS. This also added a reliance on CMAKE_OSX_ARCHITECTURES, which may be unset in some configurations when building for MacOS. In this case, we should still fallback to CMAKE_SYSTEM_PROCESSOR and assume we're trying to build for the current target only.

* Add test around cpu architecture detection on macos

---------

Co-authored-by: Luis Caro Campos <[email protected]>
  • Loading branch information
Cogitri and jcar87 authored Jan 22, 2024
1 parent a4d21fa commit 6e8793c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function(detect_arch ARCH)
message(WARNING "CMake-Conan: Multiple architectures detected, this will only work if Conan recipe(s) produce fat binaries.")
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS|tvOS|watchOS")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS|tvOS|watchOS" AND NOT CMAKE_OSX_ARCHITECTURES STREQUAL "")
set(host_arch ${CMAKE_OSX_ARCHITECTURES})
elseif(MSVC)
set(host_arch ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})
Expand Down
18 changes: 13 additions & 5 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,19 @@ def test_android_no_toolchain(self, capfd, basic_cmake_project):
assert "tools.android:ndk_path=" in out


class TestiOS:
class TestAppleOS:
@darwin
def test_macos_arch(self, capfd, basic_cmake_project):
"Test that when an architecture is not explicitly set, we detect the default system one"
source_dir, binary_dir = basic_cmake_project
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release")
out, _ = capfd.readouterr()
arch = platform.processor()
if 'arm' in arch:
assert "-- CMake-Conan: cmake_system_processor=armv8" in out
elif 'i386' in arch:
assert "-- CMake-Conan: cmake_system_processor=x86_64" in out

@darwin
def test_ios(self, capfd, basic_cmake_project):
source_dir, binary_dir = basic_cmake_project
Expand All @@ -569,8 +581,6 @@ def test_ios_simulator(self, capfd, basic_cmake_project):
assert "os.version=11.0" in out
assert "compiler.libcxx=libc++" in out


class TestTvOS:
@darwin
def test_tvos(self, capfd, basic_cmake_project):
source_dir, binary_dir = basic_cmake_project
Expand All @@ -597,8 +607,6 @@ def test_tvos_simulator(self, capfd, basic_cmake_project):
assert "os.version=15.0" in out
assert "compiler.libcxx=libc++" in out


class TestWatchOS:
@darwin
def test_watchos(self, capfd, basic_cmake_project):
source_dir, binary_dir = basic_cmake_project
Expand Down

0 comments on commit 6e8793c

Please sign in to comment.