Skip to content

Commit

Permalink
Support Android build with no toolchain (#580)
Browse files Browse the repository at this point in the history
* Support Android build with no toolchain

* test_android_no_toolchain: use new fixture

---------

Co-authored-by: Luis Caro Campos <[email protected]>
  • Loading branch information
ssrobins and jcar87 authored Nov 9, 2023
1 parent 5b550a0 commit 4e1e811
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -133,8 +137,8 @@ endmacro()

function(detect_lib_cxx LIB_CXX)
if(CMAKE_SYSTEM_NAME 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()

Expand Down
14 changes: 14 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,20 @@ 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, 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(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()
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
Expand Down

0 comments on commit 4e1e811

Please sign in to comment.