mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-13 05:20:45 +00:00
Switch android build to use NDK-provided cmake file
* The existing android cmake file doesn't work with newer NDK releases, so we have to use the provided cmake file. It should work in NDKs as far back as version 14.
This commit is contained in:
+8
-27
@@ -3,27 +3,23 @@ cmake_minimum_required(VERSION 2.8.12)
|
||||
# Configure some stuff that needs to be set really early
|
||||
if(BUILD_ANDROID)
|
||||
set(CMAKE_TOOLCHAIN_FILE
|
||||
"${CMAKE_SOURCE_DIR}/util/android.toolchain.cmake"
|
||||
"$ENV{ANDROID_NDK}/build/cmake/android.toolchain.cmake"
|
||||
CACHE STRING
|
||||
"The Android toolchain file")
|
||||
|
||||
option(STRIP_ANDROID_LIBRARY "Strip the resulting android library" OFF)
|
||||
|
||||
# Set same default API level for ANDROID_ABI=armeabi-v7a as for arm64-v8a.
|
||||
set( ANDROID_DEFAULT_NDK_API_LEVEL_arm 21 )
|
||||
# Set default API level to 21 if not configured explicitly
|
||||
if(NOT ANDROID_PLATFORM)
|
||||
set(ANDROID_PLATFORM "android-21")
|
||||
endif()
|
||||
|
||||
# Choose clang if the NDK has both gcc and clang, since gcc sometimes fails
|
||||
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang")
|
||||
|
||||
# Default to arm32 if nothing is specified on the command line.
|
||||
# Options are {armeabi-v7a,arm64-v8a}
|
||||
set(ANDROID_ABI "armeabi-v7a" CACHE STRING "The Android ABI to build for")
|
||||
|
||||
# This will be overridden later, we just need to set it now so that the
|
||||
# configuration will continue on to where the toolchain is available
|
||||
if(WIN32)
|
||||
set(CMAKE_MAKE_PROGRAM
|
||||
"android-make-not-found"
|
||||
CACHE STRING
|
||||
"The path to the NDK's make.exe to use")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# disallow in-source builds because we have a top-level wrapper Makefile
|
||||
@@ -162,21 +158,6 @@ if(ANDROID)
|
||||
|
||||
message(STATUS "Using Android ABI ${ANDROID_ABI}")
|
||||
message(STATUS "Using Android native API level ${ANDROID_NATIVE_API_LEVEL}")
|
||||
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(MAKE_SEARCH_DIRS "windows-x86_64" "windows")
|
||||
|
||||
# For windows, we need to use the make program in the NDK
|
||||
foreach(dir ${MAKE_SEARCH_DIRS})
|
||||
set(__makepath "${ANDROID_NDK}/prebuilt/${dir}/bin/make.exe")
|
||||
if( EXISTS "${__makepath}" )
|
||||
set(CMAKE_MAKE_PROGRAM "${__makepath}" CACHE STRING "" FORCE)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
message(STATUS "Using build tool ${CMAKE_MAKE_PROGRAM}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
@@ -294,7 +294,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR APPLE)
|
||||
# Need to add -Wno-unknown-warning-option since some clang versions don't have
|
||||
# -Wno-shift-negative-value available
|
||||
set_source_files_properties(3rdparty/jpeg-compressor/jpgd.cpp
|
||||
PROPERTIES COMPILE_FLAGS "-Wno-unknown-warning-option -Wno-shift-negative-value")
|
||||
PROPERTIES COMPILE_FLAGS "-Wno-unknown-warning-option -Wno-shift-negative-value -Wno-invalid-noreturn")
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set_property(SOURCE 3rdparty/jpeg-compressor/jpgd.cpp
|
||||
@@ -303,9 +303,10 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR APPLE)
|
||||
set_property(SOURCE strings/utf8printf.cpp
|
||||
APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unknown-warning -Wno-format-truncation")
|
||||
endif()
|
||||
|
||||
# Need to add -Wno-unknown-warning-option since only newer clang versions have
|
||||
# -Wno-unused-lambda-capture available
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
# Only clang has this warning. Fixing it in this file causes a compile error on windows
|
||||
set_source_files_properties(os/os_specific.cpp
|
||||
PROPERTIES COMPILE_FLAGS "-Wno-unknown-warning-option -Wno-unused-lambda-capture")
|
||||
|
||||
@@ -186,4 +186,14 @@ enum
|
||||
// this strips them completely
|
||||
#define STRIP_DEBUG_LOGS OPTION_OFF
|
||||
|
||||
#define ENABLE_UNIT_TESTS RDOC_DEVEL
|
||||
// disable unit tests on android
|
||||
#if ENABLED(RDOC_ANDROID)
|
||||
|
||||
#define ENABLE_UNIT_TESTS OPTION_OFF
|
||||
|
||||
#else
|
||||
|
||||
// otherwise, enable them in development builds
|
||||
#define ENABLE_UNIT_TESTS RDOC_DEVEL
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,9 @@ elseif(ANDROID)
|
||||
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
|
||||
list(APPEND libraries PRIVATE -llog -landroid)
|
||||
set(LINKER_FLAGS "-Wl,--no-as-needed")
|
||||
|
||||
set_source_files_properties(renderdoccmd.cpp PROPERTIES COMPILE_FLAGS "-fexceptions -frtti")
|
||||
set_source_files_properties(renderdoccmd_android.cpp PROPERTIES COMPILE_FLAGS "-fexceptions")
|
||||
elseif(UNIX)
|
||||
list(APPEND sources renderdoccmd_linux.cpp)
|
||||
|
||||
@@ -62,15 +65,58 @@ if(ANDROID)
|
||||
|
||||
set(ANDROID_BUILD_TOOLS_VERSION "" CACHE STRING "Version of Android build-tools to use instead of the default")
|
||||
if(ANDROID_BUILD_TOOLS_VERSION STREQUAL "")
|
||||
set(ANDROID_BUILD_TOOLS_VERSION "26.0.1")
|
||||
# Enumerate the build tools versions available, and pick the most recent
|
||||
file(GLOB __buildTools RELATIVE "$ENV{ANDROID_SDK}/build-tools" "$ENV{ANDROID_SDK}/build-tools/*")
|
||||
list(SORT __buildTools)
|
||||
|
||||
list(GET __buildTools -1 ANDROID_BUILD_TOOLS_VERSION)
|
||||
|
||||
unset(__buildTools)
|
||||
endif()
|
||||
message(STATUS "Using Android build-tools version ${ANDROID_BUILD_TOOLS_VERSION}")
|
||||
|
||||
set(APK_TARGET_ID "" CACHE STRING "The Target ID to build the APK for like 'android-99', use <android list targets> to choose another one.")
|
||||
if(APK_TARGET_ID STREQUAL "")
|
||||
# This seems different from the platform we're targetting,
|
||||
# default to the latest available that's greater or equal to our target platform
|
||||
file(GLOB __platforms RELATIVE "$ENV{ANDROID_SDK}/platforms" "$ENV{ANDROID_SDK}/platforms/*")
|
||||
list(SORT __platforms)
|
||||
|
||||
# In case we don't find one, target the latest platform
|
||||
list(GET __platforms -1 APK_TARGET_ID)
|
||||
|
||||
string(REPLACE "android-" "" __targetPlat "${ANDROID_PLATFORM}")
|
||||
|
||||
# We require at least android 23 for Activity.requestPermissions
|
||||
if(__targetPlat LESS 23)
|
||||
set(__targetPlat 23)
|
||||
endif()
|
||||
|
||||
foreach( __plat ${__platforms})
|
||||
string(REPLACE "android-" "" __curPlat "${__plat}")
|
||||
|
||||
if(NOT (__curPlat LESS __targetPlat) )
|
||||
set(APK_TARGET_ID "android-${__curPlat}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
unset(__platforms)
|
||||
unset(__targetPlat)
|
||||
unset(__curPlat)
|
||||
endif()
|
||||
message(STATUS "Using android.jar from platform ${APK_TARGET_ID}")
|
||||
|
||||
# Suffix for scripts rather than binaries, which is needed explicitly on windows
|
||||
set(TOOL_SCRIPT_EXTENSION "")
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(TOOL_SCRIPT_EXTENSION ".bat")
|
||||
endif()
|
||||
|
||||
set(BUILD_TOOLS "$ENV{ANDROID_SDK}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}")
|
||||
set(RT_JAR "$ENV{JAVA_HOME}/jre/lib/rt.jar")
|
||||
set(JAVA_BIN "$ENV{JAVA_HOME}/bin")
|
||||
|
||||
set(APK_TARGET_ID "android-23" CACHE STRING "The Target ID to build the APK for, use <android list targets> to choose another one.")
|
||||
set(ANDROID_JAR "$ENV{ANDROID_SDK}/platforms/${APK_TARGET_ID}/android.jar")
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(CLASS_PATH "${ANDROID_JAR}\;obj")
|
||||
@@ -118,10 +164,10 @@ if(ANDROID)
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:renderdoccmd> libs/lib/${ANDROID_ABI}/$<TARGET_FILE_NAME:renderdoccmd>
|
||||
COMMAND ${BUILD_TOOLS}/aapt package -f -m -S res -J src -M AndroidManifest.xml -I ${ANDROID_JAR}
|
||||
COMMAND ${JAVA_BIN}/javac -d ./obj -source 1.7 -target 1.7 -bootclasspath ${RT_JAR} -classpath "${CLASS_PATH}" -sourcepath src src/org/renderdoc/renderdoccmd/*.java
|
||||
COMMAND ${BUILD_TOOLS}/dx --dex --output=bin/classes.dex ./obj
|
||||
COMMAND ${BUILD_TOOLS}/dx${TOOL_SCRIPT_EXTENSION} --dex --output=bin/classes.dex ./obj
|
||||
COMMAND ${BUILD_TOOLS}/aapt package -f -M AndroidManifest.xml --version-code ${APK_VERSION_CODE} --version-name ${APK_VERSION_NAME} -S res -I ${ANDROID_JAR} -F RenderDocCmd-unaligned.apk bin libs
|
||||
COMMAND ${BUILD_TOOLS}/zipalign -f 4 RenderDocCmd-unaligned.apk RenderDocCmd.apk
|
||||
COMMAND ${BUILD_TOOLS}/apksigner sign --ks ${KEYSTORE} --ks-pass pass:android --key-pass pass:android --ks-key-alias androiddebugkey RenderDocCmd.apk
|
||||
COMMAND ${BUILD_TOOLS}/apksigner${TOOL_SCRIPT_EXTENSION} sign --ks ${KEYSTORE} --ks-pass pass:android --key-pass pass:android --ks-key-alias androiddebugkey RenderDocCmd.apk
|
||||
COMMAND ${CMAKE_COMMAND} -E copy RenderDocCmd.apk ${APK_FILE})
|
||||
|
||||
endif()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user