From 026c498a62e379eaaebee87790a525b823ce73e2 Mon Sep 17 00:00:00 2001 From: Steve Robinson Date: Sun, 29 Oct 2023 21:20:31 -0700 Subject: [PATCH 1/2] Support Android build with no toolchain --- conan_provider.cmake | 12 ++++++++---- tests/test_smoke.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index 91d4e043..d822cf25 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -19,8 +19,12 @@ function(detect_os OS OS_API_LEVEL OS_SDK OS_SUBSYSTEM OS_VERSION) set(${OS} ${CMAKE_SYSTEM_NAME} PARENT_SCOPE) endif() if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") - string(REGEX MATCH "[0-9]+" _OS_API_LEVEL ${ANDROID_PLATFORM}) - message(STATUS "CMake-Conan: android_platform=${ANDROID_PLATFORM}") + if(DEFINED ANDROID_PLATFORM) + string(REGEX MATCH "[0-9]+" _OS_API_LEVEL ${ANDROID_PLATFORM}) + elseif(DEFINED CMAKE_SYSTEM_VERSION) + set(_OS_API_LEVEL ${CMAKE_SYSTEM_VERSION}) + endif() + message(STATUS "CMake-Conan: android api level=${_OS_API_LEVEL}") set(${OS_API_LEVEL} ${_OS_API_LEVEL} PARENT_SCOPE) endif() if(CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS|tvOS|watchOS") @@ -131,8 +135,8 @@ endmacro() function(detect_lib_cxx OS LIB_CXX) if(${OS} STREQUAL "Android") - message(STATUS "CMake-Conan: android_stl=${ANDROID_STL}") - set(${LIB_CXX} ${ANDROID_STL} PARENT_SCOPE) + message(STATUS "CMake-Conan: android_stl=${CMAKE_ANDROID_STL_TYPE}") + set(${LIB_CXX} ${CMAKE_ANDROID_STL_TYPE} PARENT_SCOPE) return() endif() diff --git a/tests/test_smoke.py b/tests/test_smoke.py index a915130d..5f5801e7 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -464,6 +464,19 @@ def test_android_x86(self, capfd, chdir_build): assert "os.api_level=19" in out assert "tools.android:ndk_path=" in out + def test_android_no_toolchain(self, capfd, chdir_build): + "Building for Android without toolchain" + android_ndk_root = os.environ['ANDROID_NDK_ROOT'].replace("\\", "/") + run("cmake .. --fresh -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -DCMAKE_BUILD_TYPE=Release " + f"-DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK={android_ndk_root} " + "-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_STL_TYPE=c++_static") + out, _ = capfd.readouterr() + assert "arch=armv8" in out + assert "compiler.libcxx=c++_static" in out + assert "os=Android" in out + assert "os.api_level=28" in out + assert "tools.android:ndk_path=" in out + class TestiOS: @darwin From 5fa2a698d8d151d873cf7b6bb6c5c38c4003ea22 Mon Sep 17 00:00:00 2001 From: Luis Caro Campos <3535649+jcar87@users.noreply.github.com> Date: Thu, 9 Nov 2023 14:53:00 +0000 Subject: [PATCH 2/2] test_android_no_toolchain: use new fixture --- tests/test_smoke.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index ee2caf01..a682fc9a 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -485,10 +485,11 @@ def test_android_x86(self, capfd, basic_cmake_project): assert "os.api_level=22" in out assert "tools.android:ndk_path=" in out - def test_android_no_toolchain(self, capfd, chdir_build): + def test_android_no_toolchain(self, capfd, basic_cmake_project): "Building for Android without toolchain" + source_dir, binary_dir = basic_cmake_project android_ndk_root = os.environ['ANDROID_NDK_ROOT'].replace("\\", "/") - run("cmake .. --fresh -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -DCMAKE_BUILD_TYPE=Release " + run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -G Ninja -DCMAKE_BUILD_TYPE=Release " f"-DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK={android_ndk_root} " "-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_STL_TYPE=c++_static") out, _ = capfd.readouterr()