Commit bd973554 authored by Ghislain MARY's avatar Ghislain MARY

Restore support of NDK < 16 for Android.

parent e11c160d
......@@ -21,18 +21,39 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(androidsupport LANGUAGES CXX)
project(androidsupport LANGUAGES C CXX)
include(GNUInstallDirs)
set(SUPPORT_SOURCES
"${CMAKE_ANDROID_NDK}/sources/android/support/src/iswblank.cpp"
)
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 16)
set(SUPPORT_SOURCES
"${CMAKE_ANDROID_NDK}/sources/android/support/src/musl-multibyte/wctomb.c"
)
else()
set(SUPPORT_SOURCES
"${CMAKE_ANDROID_NDK}/sources/android/support/src/iswblank.cpp"
)
endif()
add_library(support STATIC ${SUPPORT_SOURCES})
target_include_directories(support PUBLIC "${CMAKE_ANDROID_NDK}/sources/android/support/include")
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 16)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(support PRIVATE "-std=c99")
endif()
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
install(FILES
"${CMAKE_ANDROID_NDK}/sources/android/support/include/ctype.h"
"${CMAKE_ANDROID_NDK}/sources/android/support/include/langinfo.h"
"${CMAKE_ANDROID_NDK}/sources/android/support/include/nl_types.h"
"${CMAKE_ANDROID_NDK}/sources/android/support/include/xlocale.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif()
endif()
install(TARGETS support
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
......
......@@ -166,9 +166,15 @@ lcb_builder_install_target(x264 "install-lib-static")
# Copy c++ library to install prefix
file(COPY "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 16)
file(COPY "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_CXX_ANDROID_TOOLCHAIN_VERSION}/libs/${CMAKE_ANDROID_ARCH_ABI}/libgnustl_shared.so"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)
else()
file(COPY "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
......
......@@ -20,17 +20,29 @@
#
############################################################################
find_program(ANDROID_NDK_BUILD_PROGRAM ndk-build)
if(NOT ANDROID_NDK_BUILD_PROGRAM)
message(FATAL_ERROR "Cannot find 'ndk-build', make sure you installed the NDK and added it to your PATH")
set(CMAKE_ANDROID_NDK "$ENV{ANDROID_NDK_HOME}")
if(NOT CMAKE_ANDROID_NDK)
find_program(ANDROID_NDK_BUILD_PROGRAM ndk-build)
if(NOT ANDROID_NDK_BUILD_PROGRAM)
message(FATAL_ERROR "Cannot find 'ndk-build', make sure you installed the NDK and added it to your PATH")
endif()
get_filename_component(CMAKE_ANDROID_NDK "${ANDROID_NDK_BUILD_PROGRAM}" DIRECTORY)
endif()
get_filename_component(CMAKE_ANDROID_NDK "${ANDROID_NDK_BUILD_PROGRAM}" DIRECTORY)
file(READ "${CMAKE_ANDROID_NDK}/source.properties" SOURCE_PROPERTIES_CONTENT)
string(REGEX MATCH "Pkg\\.Revision = ([0-9]+)\\." NDK_VERSION_MATCH "${SOURCE_PROPERTIES_CONTENT}")
set(CMAKE_ANDROID_NDK_VERSION ${CMAKE_MATCH_1})
set(CMAKE_SYSTEM_NAME "Android")
if(NOT CMAKE_ANDROID_API)
set(CMAKE_ANDROID_API 16)
endif()
set(CMAKE_ANDROID_STL_TYPE "c++_shared")
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 16)
set(CMAKE_ANDROID_STL_TYPE "gnustl_shared")
else()
set(CMAKE_ANDROID_STL_TYPE "c++_shared")
endif()
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}" "${CMAKE_INSTALL_PREFIX}")
# search for programs in the build host directories
......
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