# HG changeset patch # User simmax@googlemail.com # Date 1332458494 -3600 # Node ID f4816282ba01380fe6eb9bf532c2aa16bfaabc98 # Parent cdfb6c7099e515fc56be31e70711566282d3f82c Improved cmake build script for Android: - Error out when Ant or android can't be found - Attempt to find the NDK toolchain binaries on Windows and Linux instead of assuming Linux - Use find_program instead of find_path to find some binaries - ANDROID_SDK now refers to the Android SDK base directory - Fixed detection of android.bat on Windows - Output of the android tool is now shown so that success/failure is visible diff -r cdfb6c7099e5 -r f4816282ba01 project_files/Android-build/CMakeLists.txt --- a/project_files/Android-build/CMakeLists.txt Fri Mar 23 14:14:43 2012 +0100 +++ b/project_files/Android-build/CMakeLists.txt Fri Mar 23 00:21:34 2012 +0100 @@ -17,6 +17,9 @@ ################################################################################### find_program(ANT ant) +if(NOT EXISTS ${ANT}) + MESSAGE(FATAL_ERROR "Couldn't detect the Ant build tool") +endif() if(NOT ANDROID_NDK) find_path(ANDROID_NDK ndk-build) @@ -28,8 +31,24 @@ MESSAGE(FATAL_ERROR "Couldn't detect the Android NDK directory") endif() +if(NOT ANDROID_NDK_TOOLCHAINDIR) + set(toolchainbase "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt") + find_program(ANDROID_NDK_TOOLCHAINDIR arm-linux-androideabi-as + "${toolchainbase}/linux-x86/bin" + "${toolchainbase}/windows/bin") + get_filename_component(ANDROID_NDK_TOOLCHAINDIR "${ANDROID_NDK_TOOLCHAINDIR}" PATH) + get_filename_component(ANDROID_NDK_TOOLCHAINDIR "${ANDROID_NDK_TOOLCHAINDIR}" PATH) +endif() + +if(IS_DIRECTORY "${ANDROID_NDK_TOOLCHAINDIR}") + MESSAGE(STATUS "Detected the Android NDK toolchain at: " ${ANDROID_NDK_TOOLCHAINDIR}) +else () + MESSAGE(FATAL_ERROR "Couldn't detect the Android NDK toolchain directory") +endif() + if(NOT ANDROID_SDK)#Check if its defined at the cmdline - find_path(ANDROID_SDK adb ) #assume they've added platform-tools to their path + find_program(ANDROID_SDK adb) #assume they've added platform-tools to their path + get_filename_component(ANDROID_SDK "${ANDROID_SDK}" PATH) get_filename_component(ANDROID_SDK "${ANDROID_SDK}" PATH) set(ANDROID_SDK "${ANDROID_SDK}" CACHE PATH "Path to the android sdk" FORCE) endif() @@ -41,7 +60,7 @@ endif() if( NOT FPC_DIR) - find_path(FPC_DIR ppcrossarm) + find_program(FPC_DIR ppcrossarm) get_filename_component(FPC_DIR "${FPC_DIR}" PATH) set(FPC_DIR "${FPC_DIR}" CACHE PATH "Path to fpc dir used in the android port" FORCE) endif() @@ -62,15 +81,18 @@ configure_file(Templates/Makefile.android .) -find_program(ANDROID android "${ANDROID_SDK}" "${ANDROID_SDK}/tools") +find_program(ANDROID NAMES android android.bat PATHS "${ANDROID_SDK}/platform-tools" "${ANDROID_SDK}/tools") if(ANDROID) exec_program(${ANDROID} ARGS "update project" "--path ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project" "--target android-${ANDROID_SDK_API_LVL}" - OUTPUT_VARIABLE dontcare - ) -endif(ANDROID) + OUTPUT_VARIABLE androidoutput + ) + MESSAGE(STATUS "Updating android project config...\n" ${androidoutput}) +else() + MESSAGE(FATAL_ERROR "Couldn't find the android executable in ${ANDROID_SDK}/platform-tools or ${ANDROID_SDK}/tools.") +endif() exec_program(${HGCOMMAND} ARGS revert ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp diff -r cdfb6c7099e5 -r f4816282ba01 project_files/Android-build/Templates/Makefile.android --- a/project_files/Android-build/Templates/Makefile.android Fri Mar 23 14:14:43 2012 +0100 +++ b/project_files/Android-build/Templates/Makefile.android Fri Mar 23 00:21:34 2012 +0100 @@ -1,13 +1,13 @@ SDL_ANDROID_DIR=./SDL-android-project -PPCROSSARM=${FPC_DIR}/compiler/ppcrossarm +PPCROSSARM=${FPC_DIR}/ppcrossarm PPCROSSARM_FLAGS= -Xd -O2 -g -Tlinux -XParm-linux-androideabi- -B -vwnh PPCROSSARM_INCLUDES= \ - -FD${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin \ + -FD${ANDROID_NDK_TOOLCHAINDIR}/bin \ -Fu${FPC_DIR}/rtl/units/arm-linux \ -Fl${ANDROID_NDK}/platforms/android-${ANDROID_NDK_API_LVL}/arch-arm/usr/lib \ -Fl$(SDL_ANDROID_DIR)/libs/armeabi \ - -Fl${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux/arm-linux-androideabi/4.4.3/ \ + -Fl${ANDROID_NDK_TOOLCHAINDIR}/lib/gcc/arm-linux/arm-linux-androideabi/4.4.3/ \ #LINKERFLAGS= -k"--static" FPC_DEFINES=-dandroid -darm