diff options
author | Sven Gothel <[email protected]> | 2019-12-24 16:27:06 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-24 16:27:06 +0100 |
commit | f344ef3aa3a42c4e81376c3d8ad6507ad2b8a20c (patch) | |
tree | 87f383f827bf23fc56a7687376ea52eb88c6ebdd | |
parent | 866acb84a73e3294876c6cdcee3d4b6b74cf259f (diff) |
Bug 1417 - Android: OpenAL-Soft toolchain.android.cmake cleanup and NDK r20 adoption llvm: clang libc++
All properties are now aligned with gluegen/make/scripts/setenv-android-tools.sh.
User must set ANDROID_NDK, ANDROID_HOST_TAG, ANDROID_API_LEVEL and one of
NDK_CPU_X86_64, NDK_CPU_X86, NDK_CPU_ARM64, NDK_CPU_ARM_V7A, NDK_CPU_ARM.
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmake/toolchain.android.cmake | 269 |
2 files changed, 137 insertions, 134 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cdd7e18..824659b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # CMake build file list for OpenAL -CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2.0) PROJECT(OpenAL) diff --git a/cmake/toolchain.android.cmake b/cmake/toolchain.android.cmake index 37474a7e..5e5a7124 100644 --- a/cmake/toolchain.android.cmake +++ b/cmake/toolchain.android.cmake @@ -1,4 +1,25 @@ -# Adapted from http://code.google.com/p/android-cmake/ +# +# Aligned with NDK r19 using LLVM's clang and C++ STL +# + +# +# Required variables to be set by user: +# (gluegen/make/scripts/setenv-android-tools.sh env var) +# - ANDROID_NDK := ${env.ANDROID_NDK} [/opt/android-sdk/ndk/20.00] +# - ANDROID_HOST_TAG := ${env.ANDROID_HOST_TAG} [linux-x86_64, ..] +# - ANDROID_API_LEVEL := ${env.ANDROID_API_LEVEL} [24] +# +# and one of the following CPU target flags: +# +# - NDK_CPU_X86_64 +# - NDK_CPU_X86 +# - NDK_CPU_ARM64 +# - NDK_CPU_ARM_V7A +# - NDK_CPU_ARM +# +# (Will be preserved for try_compile() via CMAKE_TRY_COMPILE_PLATFORM_VARIABLES) + +set(CMAKE_CROSSCOMPILING true) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_VERSION 1) @@ -12,166 +33,144 @@ endif() set(APPLE false) set(UNIX true) -set(ANDROID_NDK_DEFAULT_SEARCH_PATH /opt/android-ndk) -set(ANDROID_NDK_SUPPORTED_VERSIONS -r8d -r8 -r7 -r6 -r5c -r5b -r5 "") -set(ANDROID_NDK_TOOLCHAIN_DEFAULT_SEARCH_PATH /opt/android-toolchain) set(TOOL_OS_SUFFIX "") -if(NOT DEFINED ANDROID_NDK) - set(ANDROID_NDK "$ENV{ANDROID_NDK}") -endif() +unset(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES) -if(NOT DEFINED ANDROID_NDK_TOOLCHAIN_ROOT) - set(ANDROID_NDK_TOOLCHAIN_ROOT $ENV{ANDROID_NDK_TOOLCHAIN_ROOT}) +if(NOT DEFINED ANDROID_NDK) + message(FATAL_ERROR "Undefined ANDROID_NDK") + #set(ANDROID_NDK "$ENV{ANDROID_NDK}") +else() + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} ANDROID_NDK) endif() if(NOT EXISTS "${ANDROID_NDK}") - foreach(ndk_version ${ANDROID_NDK_SUPPORTED_VERSIONS}) - if(EXISTS ${ANDROID_NDK_DEFAULT_SEARCH_PATH}${ndk_version}) - set(ANDROID_NDK "${ANDROID_NDK_DEFAULT_SEARCH_PATH}${ndk_version}") - message(STATUS "Using default path for android NDK ${ANDROID_NDK}") - message(STATUS " If you prefer to use a different location, please define the variable: ANDROID_NDK") - break() - endif() - endforeach() + message(FATAL_ERROR "Not existing ANDROID_NDK ${ANDROID_NDK}") endif() -if(EXISTS "${ANDROID_NDK}") - if(NOT DEFINED ANDROID_TOOLCHAIN_SYSTEM) - if(APPLE) - set(ANDROID_TOOLCHAIN_SYSTEM "darwin-x86") - elseif(WIN32) - set(ANDROID_TOOLCHAIN_SYSTEM "windows") - set(TOOL_OS_SUFFIX ".exe") - elseif(UNIX) - set(ANDROID_TOOLCHAIN_SYSTEM "linux-x86") - else() - message(FATAL_ERROR "Your platform is not supported") - endif() - endif() - - if(NOT ANDROID_API_LEVEL GREATER 2) - if(NDK_CPU_ARM64) - set(ANDROID_API_LEVEL 21) - elseif(NDK_CPU_X86) - set(ANDROID_API_LEVEL 9) - else() - set(ANDROID_API_LEVEL 5) - endif() - message(STATUS "Using default android API level android-${ANDROID_API_LEVEL}") - message(STATUS " If you prefer to use a different API level, please define the variable: ANDROID_API_LEVEL") - endif() - - if (NDK_CPU_X86) - set(ANDROID_TOOLCHAIN_PREFIX "i686-android-linux") - set(ANDROID_TOOLCHAIN_NAME "x86") - set(ANDROID_TOOLCHAIN_PLATFORM_NAME "x86") - elseif(NDK_CPU_ARM64) - set(ANDROID_TOOLCHAIN_PREFIX "aarch64-linux-android") - set(ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_PREFIX}") - set(ANDROID_TOOLCHAIN_PLATFORM_NAME "arm64") - else() - set(ANDROID_TOOLCHAIN_PREFIX "arm-linux-androideabi") - set(ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_PREFIX}") - set(ANDROID_TOOLCHAIN_PLATFORM_NAME "arm") - endif() - - if (NOT DEFINED ANDROID_TOOLCHAIN_VERSION) - set(SUPPORTED_TOOLCHAIN_VERSIONS 4.4.0 4.4.3 4.6.0 4.6.1 4.6.2 4.6.3 4.7 4.8 4.9) - foreach(gcc_version ${SUPPORTED_TOOLCHAIN_VERSIONS}) - if (EXISTS "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}-${gcc_version}") - set(ANDROID_TOOLCHAIN_VERSION ${gcc_version}) - endif() - endforeach() - if(NOT DEFINED ANDROID_TOOLCHAIN_VERSION) - message(FATAL_ERROR "Unable to find toolchain") - else() - message(STATUS "Using auto-detected toolchain ${ANDROID_TOOLCHAIN_NAME}-${ANDROID_TOOLCHAIN_VERSION}") - endif() - endif() - if (EXISTS "${ANDROID_NDK}/toolchains/clang-android-${ANDROID_TOOLCHAIN_VERSION}") - set (ANDROID_TOOLCHAIN_NAME "clang-android") - message(STATUS "Found clang toolchain ${ANDROID_TOOLCHAIN_NAME}-${ANDROID_TOOLCHAIN_VERSION}") - endif() - - set(ANDROID_NDK_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_TOOLCHAIN_PLATFORM_NAME}") - set(ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}-${ANDROID_TOOLCHAIN_VERSION}/prebuilt/${ANDROID_TOOLCHAIN_SYSTEM}") +if(NOT DEFINED ANDROID_HOST_TAG) + message(FATAL_ERROR "Undefined ANDROID_HOST_TAG") +else() + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} ANDROID_HOST_TAG) +endif() +if(NOT ANDROID_API_LEVEL GREATER 2) + set(ANDROID_API_LEVEL 24) + message(STATUS "Using default android API level android-${ANDROID_API_LEVEL}") +else() + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} ANDROID_API_LEVEL) endif() -set(CMAKE_C_COMPILER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" FORCE) -set(CMAKE_CXX_COMPILER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" FORCE) -set(CMAKE_AR "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" FORCE) -set(CMAKE_LINKER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" FORCE) -set(CMAKE_NM "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" FORCE) -set(CMAKE_OBJCOPY "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" FORCE) -set(CMAKE_OBJDUMP "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" FORCE) -set(CMAKE_STRIP "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" FORCE) -set(CMAKE_RANLIB "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_PREFIX}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" FORCE) - -if(NDK_CPU_X86) - set(ANDROID_NDK_CPU_NAME "x86") +# +# Aligned with gluegen/make/scripts/setenv-android-tools.sh +# +if(NDK_CPU_X86_64) + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} NDK_CPU_X86_64) + set(ANDROID_SYSROOT_ABI "x86_64") + set(CMAKE_SYSTEM_PROCESSOR "x86_64") + set(ANDROID_TOOLCHAIN_NAME "x86_64-linux-android") + set(ANDROID_CLANG_PREFIX ${ANDROID_TOOLCHAIN_NAME}) + set(ANDROID_LLVM_TRIPLE "x86_64-none-linux-android") + message(STATUS "Using NDK_CPU_x86_64, ANDROID_TOOLCHAIN_NAME = ${ANDROID_TOOLCHAIN_NAME}") +elseif(NDK_CPU_X86) + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} NDK_CPU_X86) + set(ANDROID_SYSROOT_ABI "x86") set(CMAKE_SYSTEM_PROCESSOR "x86") + set(ANDROID_TOOLCHAIN_NAME "i686-linux-android") + set(ANDROID_CLANG_PREFIX ${ANDROID_TOOLCHAIN_NAME}) + set(ANDROID_LLVM_TRIPLE "i686-none-linux-android") + message(STATUS "Using NDK_CPU_X86, ANDROID_TOOLCHAIN_NAME = ${ANDROID_TOOLCHAIN_NAME}") elseif(NDK_CPU_ARM64) - set(NDK_CPU_ARM true) - set(ANDROID_NDK_CPU_NAME "arm64-v8a") - set(NDK_CPU_ARM_NEON false) + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} NDK_CPU_ARM64) + set(ANDROID_SYSROOT_ABI "arm64") set(CMAKE_SYSTEM_PROCESSOR "armv8-a") + set(ANDROID_TOOLCHAIN_NAME "aarch64-linux-android") + set(ANDROID_CLANG_PREFIX ${ANDROID_TOOLCHAIN_NAME}) + set(ANDROID_LLVM_TRIPLE "aarch64-none-linux-android") + message(STATUS "Using NDK_CPU_ARM64, ANDROID_TOOLCHAIN_NAME = ${ANDROID_TOOLCHAIN_NAME}") elseif(NDK_CPU_ARM_V7A) - set(NDK_CPU_ARM_NEON false) + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} NDK_CPU_ARM_V7A) + set(NDK_CPU_ARM_NEON true) set(NDK_CPU_ARM_VFPV3 false) set(NDK_CPU_ARM true) - set(ANDROID_NDK_CPU_NAME "armeabi-v7a") + set(ANDROID_SYSROOT_ABI "arm") set(CMAKE_SYSTEM_PROCESSOR "armv7-a") -else() - set(NDK_CPU_ARM true) - set(ANDROID_NDK_CPU_NAME "armeabi") + set(ANDROID_TOOLCHAIN_NAME "arm-linux-androideabi") + set(ANDROID_CLANG_PREFIX "armv7a-linux-androideabi") + set(ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi") + message(STATUS "Using NDK_CPU_ARM, ANDROID_TOOLCHAIN_NAME = ${ANDROID_TOOLCHAIN_NAME}") +elseif(NDK_CPU_ARM) + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} NDK_CPU_ARM) set(NDK_CPU_ARM_NEON false) + set(NDK_CPU_ARM true) + set(ANDROID_SYSROOT_ABI "arm") set(CMAKE_SYSTEM_PROCESSOR "armv5te") + set(ANDROID_TOOLCHAIN_NAME "arm-linux-androideabi") + set(ANDROID_CLANG_PREFIX "armv7a-linux-androideabi") + set(ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi") + message(STATUS "Using NDK_CPU_ARM, ANDROID_TOOLCHAIN_NAME = ${ANDROID_TOOLCHAIN_NAME}") +else() + message(FATAL_ERROR "You must define one of NDK_CPU_* [X86_64 X86 ARM64 ARM_V7A ARM]") endif() -set(CMAKE_FIND_ROOT_PATH "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin" "${ANDROID_NDK_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_PREFIX}" "${ANDROID_NDK_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share") +set(ANDROID_NDK_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}") +set(ANDROID_NDK_SYSROOT0 "${ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_SYSROOT_ABI}") +set(ANDROID_NDK_SYSROOT1 "${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot") +set(ANDROID_NDK_SYSROOT1_LIB1 "${ANDROID_NDK_SYSROOT1}/usr/lib/${ANDROID_TOOLCHAIN_NAME}/${ANDROID_API_LEVEL}") +set(ANDROID_NDK_SYSROOT1_LIB2 "${ANDROID_NDK_SYSROOT1}/usr/lib/${ANDROID_TOOLCHAIN_NAME}") -set(STL_PATH "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_TOOLCHAIN_VERSION}") -set(STL_LIBRARIES_PATH "${STL_PATH}/libs/${ANDROID_NDK_CPU_NAME}") -include_directories(SYSTEM "${STL_PATH}/include" "${STL_LIBRARIES_PATH}/include") -link_directories("${ANDROID_NDK_SYSROOT}/usr/lib") +set(CMAKE_C_COMPILER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_CLANG_PREFIX}${ANDROID_API_LEVEL}-clang${TOOL_OS_SUFFIX}" CACHE PATH "clang" FORCE) +set(CMAKE_CXX_COMPILER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_CLANG_PREFIX}${ANDROID_API_LEVEL}-clang++${TOOL_OS_SUFFIX}" CACHE PATH "clang++" FORCE) +set(CMAKE_AR "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" FORCE) +set(CMAKE_LINKER "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" FORCE) +set(CMAKE_NM "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" FORCE) +set(CMAKE_OBJCOPY "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" FORCE) +set(CMAKE_OBJDUMP "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" FORCE) +set(CMAKE_STRIP "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" FORCE) +set(CMAKE_RANLIB "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" FORCE) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH "${ANDROID_NDK_TOOLCHAIN_ROOT}/bin" "${ANDROID_NDK_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_NAME}" "${ANDROID_NDK_SYSROOT0}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share") -set(CMAKE_C_FLAGS "-fPIC -DANDROID -Wno-psabi -fsigned-char -I${ANDROID_NDK_SYSROOT}/usr/include") -set(CMAKE_CXX_FLAGS "-fPIC -DANDROID -Wno-psabi -fsigned-char -I${ANDROID_NDK_SYSROOT}/usr/include") +# Using llvm's c++_shared as of NDK r18: https://developer.android.com/ndk/guides/cpp-support.html +# Also see https://github.com/android/ndk/issues/452 and https://gitlab.kitware.com/cmake/cmake/issues/17059 +set(ANDROID_STL "c++_shared") +set(STL_INCLUDE_PATH0 "${ANDROID_NDK_SYSROOT1}/usr/include/c++/v1") +include_directories(BEFORE SYSTEM "${STL_INCLUDE_PATH0}") -set(FORCE_ARM OFF CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1") -if(NDK_CPU_X86) -elseif(NDK_CPU_ARM64) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a -std=c99") -elseif(NOT FORCE_ARM) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb") -else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm") -endif() +set(OPENSL_INCLUDE_DIR "${ANDROID_NDK_SYSROOT1}/usr/include") +set(OPENSL_ANDROID_INCLUDE_DIR "${ANDROID_NDK_SYSROOT1}/usr/include") +set(OPENSL_LIBRARY "${ANDROID_NDK_SYSROOT0}/usr/lib/libOpenSLES.so") -set(CMAKE_C_FLAGS "--sysroot=${ANDROID_NDK_SYSROOT} ${CMAKE_C_FLAGS}") +link_directories("${ANDROID_NDK_SYSROOT0}/usr/lib") -include(CMakeForceCompiler) -CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" GNU) -CMAKE_FORCE_CXX_COMPILER("${CMAKE_CXX_COMPILER}" GNU) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -if(NDK_CPU_ARM_V7A) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfloat-abi=softfp") - if(NDK_CPU_ARM_NEON) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") - elseif(NDK_CPU_ARM_VFPV3) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3") - endif() -elseif(NDK_CPU_ARM64) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mabi=lp64 -mlittle-endian -march=armv8-a -std=c99") +set(CMAKE_C_FLAGS "-nostdinc++ -fPIC -DANDROID -fsigned-char") +#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -v") + +# from sdk cmake start +# <compilerarg value="-fdata-sections" /> +# <compilerarg value="-ffunction-sections" /> +# <compilerarg value="-funwind-tables" /> +# <compilerarg value="-fstack-protector-strong" /> +# <compilerarg value="-no-canonical-prefixes" /> + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target ${ANDROID_LLVM_TRIPLE}") +if(NDK_CPU_ARM_NEON) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") +elseif(NDK_CPU_ARM_VFPV3) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c++ flags") +# Using llvm's c++_shared as of NDK r18: https://developer.android.com/ndk/guides/cpp-support.html +# Also see https://github.com/android/ndk/issues/452 and https://gitlab.kitware.com/cmake/cmake/issues/17059 +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -isystem ${STL_INCLUDE_PATH0} -isystem ${ANDROID_NDK_SYSROOT1}/usr/include -isystem ${ANDROID_NDK_SYSROOT1}/usr/include/${ANDROID_TOOLCHAIN_NAME}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") + +#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${ANDROID_NDK_SYSROOT1} -isysroot ${ANDROID_NDK_SYSROOT1} -isystem ${ANDROID_NDK_SYSROOT1}/usr/include -isystem ${ANDROID_NDK_SYSROOT1}/usr/include/${ANDROID_TOOLCHAIN_NAME}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${ANDROID_NDK_SYSROOT1}/usr/include -isystem ${ANDROID_NDK_SYSROOT1}/usr/include/${ANDROID_TOOLCHAIN_NAME}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") message(STATUS "CMAKE_C_COMPILER : ${CMAKE_C_COMPILER}") @@ -181,7 +180,8 @@ message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") message(STATUS "NDK_CPU_ARM: ${NDK_CPU_ARM}") message(STATUS "NDK_CPU_ARM64: ${NDK_CPU_ARM64}") -set(LINKER_FLAGS "-L\"${STL_LIBRARIES_PATH}\" -L\"${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_CPU_NAME}\"") +set(LINKER_FLAGS "--sysroot=${ANDROID_NDK_SYSROOT0} -L\"${ANDROID_NDK_SYSROOT1_LIB1}\" -Wl,-rpath-link=\"${ANDROID_NDK_SYSROOT1_LIB1}\" -L\"${ANDROID_NDK_SYSROOT1_LIB2}\" -target ${ANDROID_LLVM_TRIPLE}") +#set(LINKER_FLAGS "${LINKER_FLAGS} -v") message(STATUS "ARM32_LINKER_OPTS: ${ARM32_LINKER_OPTS}") message(STATUS "ARM64_LINKER_OPTS: ${ARM64_LINKER_OPTS}") @@ -198,6 +198,7 @@ endif() message(STATUS "LINKER_FLAGS: ${LINKER_FLAGS}") +# Requires CMake >= 3.2.0 to have these flags being honored by try_compile() set(CMAKE_SHARED_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "shared linker flags" FORCE) set(CMAKE_MODULE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "module linker flags" FORCE) set(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "exe linker flags" FORCE) @@ -206,8 +207,10 @@ message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "CMAKE_MODULE_LINKER_FLAGS: ${CMAKE_MODULE_LINKER_FLAGS}") message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "CMAKE_STATIC_LINKER_FLAGS: ${CMAKE_STATIC_LINKER_FLAGS}") +message(STATUS "CMAKE_CXX_LINK_EXECUTABLE: ${CMAKE_CXX_LINK_EXECUTABLE}") +message(STATUS "CMAKE_C_LINK_EXECUTABLE: ${CMAKE_C_LINK_EXECUTABLE}") +message(STATUS "CMAKE_LINK_EXECUTABLE: ${CMAKE_LINK_EXECUTABLE}") +message(STATUS "CMAKE_TRY_COMPILE_PLATFORM_VARIABLES: ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}") set(ANDROID true) set(BUILD_ANDROID true) - -MARK_AS_ADVANCED(FORCE_ARM NO_UNDEFINED) |