Commit 04e0fa33 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'android-native'

c5892e48 Android: add support for native compilation, such as with the Termux app
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3917
parents 24703b11 c5892e48
Pipeline #148954 passed with stage
in 0 seconds
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment