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

Support Android build with no toolchain #580

Merged
merged 3 commits into from
Nov 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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