mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 10:50:16 -06:00
Android: add support for native compilation, such as with the Termux app
The CMake support for Android assumes cross-compilation using the NDK, so stub out that Android NDK support and use the Linux support that's already invoked. Set CMAKE_HOST_SYSTEM_NAME to "Android", rather than "Linux". Issue: #19840
This commit is contained in:
@@ -43,7 +43,7 @@ if(CMAKE_HOST_UNIX)
|
||||
else()
|
||||
exec_program(${CMAKE_UNAME} ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
|
||||
endif()
|
||||
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$")
|
||||
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$|Android")
|
||||
exec_program(${CMAKE_UNAME} ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
|
||||
RETURN_VALUE val)
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND
|
||||
|
||||
@@ -24,6 +24,14 @@ if(CMAKE_SYSTEM_VERSION EQUAL 1)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Natively compiling on an Android host doesn't use the NDK cross-compilation
|
||||
# tools.
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
||||
macro(__android_compiler_clang lang)
|
||||
endmacro()
|
||||
return()
|
||||
endif()
|
||||
|
||||
include(Platform/Android-Common)
|
||||
|
||||
# The NDK toolchain configuration files at:
|
||||
|
||||
@@ -18,6 +18,12 @@ if(CMAKE_SYSTEM_VERSION EQUAL 1)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Natively compiling on an Android host doesn't use the NDK cross-compilation
|
||||
# tools.
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0057 NEW) # if IN_LIST
|
||||
|
||||
|
||||
@@ -24,6 +24,12 @@ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Natively compiling on an Android host doesn't use the NDK cross-compilation
|
||||
# tools.
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SYSROOT)
|
||||
if(CMAKE_ANDROID_NDK)
|
||||
set(CMAKE_SYSROOT "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}/arch-${CMAKE_ANDROID_ARCH}")
|
||||
|
||||
@@ -2,6 +2,11 @@ include(Platform/Linux)
|
||||
|
||||
set(ANDROID 1)
|
||||
|
||||
# Natively compiling on an Android host doesn't need these flags to be reset.
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Conventionally Android does not use versioned soname
|
||||
# But in modern versions it is acceptable
|
||||
if(NOT DEFINED CMAKE_PLATFORM_NO_VERSIONED_SONAME)
|
||||
|
||||
@@ -31,6 +31,16 @@ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(_ANDROID_HOST_EXT "")
|
||||
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(_ANDROID_HOST_EXT ".exe")
|
||||
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
||||
# Natively compiling on an Android host doesn't use the NDK cross-compilation
|
||||
# tools.
|
||||
macro(__android_determine_compiler lang)
|
||||
# Do nothing
|
||||
endmacro()
|
||||
if(NOT CMAKE_CXX_COMPILER_NAMES)
|
||||
set(CMAKE_CXX_COMPILER_NAMES c++)
|
||||
endif()
|
||||
return()
|
||||
else()
|
||||
message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.")
|
||||
endif()
|
||||
|
||||
@@ -315,10 +315,14 @@ void cmStateSnapshot::SetDefaultDefinitions()
|
||||
this->SetDefinition("UNIX", "1");
|
||||
this->SetDefinition("CMAKE_HOST_UNIX", "1");
|
||||
|
||||
# if defined(__ANDROID__)
|
||||
this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", "Android");
|
||||
# else
|
||||
struct utsname uts_name;
|
||||
if (uname(&uts_name) >= 0) {
|
||||
this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", uts_name.sysname);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
std::string legacy;
|
||||
|
||||
Reference in New Issue
Block a user