Skip to content

Commit

Permalink
Support Android build with no toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrobins committed Oct 30, 2023
1 parent b3482e1 commit 0a57288
Show file tree
Hide file tree
Showing 2 changed files with 20 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 @@ -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()

Expand Down
12 changes: 12 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,18 @@ 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"
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={os.environ['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 0a57288

Please sign in to comment.