2012-02-03 19:26:49 +08:00
|
|
|
file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH)
|
|
|
|
file(TO_CMAKE_PATH "$ENV{ANDROID_SDK}" ANDROID_SDK_ENV_PATH)
|
2012-03-16 17:16:31 +08:00
|
|
|
file(TO_CMAKE_PATH "$ENV{HOME}" HOME_ENV_PATH)
|
2012-02-03 19:26:49 +08:00
|
|
|
|
|
|
|
#find android SDK
|
|
|
|
find_host_program(ANDROID_EXECUTABLE
|
|
|
|
NAMES android.bat android
|
|
|
|
PATHS "${ANDROID_SDK_ENV_PATH}/tools/"
|
|
|
|
"${ProgramFiles_ENV_PATH}/Android/android-sdk/tools/"
|
2012-03-03 23:49:23 +08:00
|
|
|
"${ProgramFiles_ENV_PATH}/Android/android-sdk-windows/tools/"
|
|
|
|
"/opt/android-sdk-linux/tools/"
|
2012-02-03 19:26:49 +08:00
|
|
|
"/opt/android-sdk-linux_x86/tools/"
|
|
|
|
"/opt/android-sdk-linux_86/tools/"
|
2012-03-03 23:49:23 +08:00
|
|
|
"/opt/android-sdk-mac/tools/"
|
2012-02-20 22:50:23 +08:00
|
|
|
"/opt/android-sdk-mac_x86/tools/"
|
2012-02-03 19:26:49 +08:00
|
|
|
"/opt/android-sdk-mac_86/tools/"
|
2012-03-03 23:49:23 +08:00
|
|
|
"/opt/android-sdk/tools/"
|
2012-03-16 17:16:31 +08:00
|
|
|
"${HOME_ENV_PATH}/NVPACK/android-sdk-linux_x86/tools/"
|
|
|
|
"${HOME_ENV_PATH}/NVPACK/android-sdk-linux_86/tools/"
|
|
|
|
"${HOME_ENV_PATH}/NVPACK/android-sdk-linux/tools/"
|
|
|
|
"${HOME_ENV_PATH}/NVPACK/android-sdk-mac_x86/tools/"
|
|
|
|
"${HOME_ENV_PATH}/NVPACK/android-sdk-mac_86/tools/"
|
|
|
|
"${HOME_ENV_PATH}/NVPACK/android-sdk-mac/tools/"
|
2012-02-20 22:50:23 +08:00
|
|
|
"$ENV{SystemDrive}/NVPACK/android-sdk-windows/tools/"
|
2012-02-03 19:26:49 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if(ANDROID_EXECUTABLE)
|
|
|
|
message(STATUS " Found android tool: ${ANDROID_EXECUTABLE}")
|
|
|
|
get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH)
|
|
|
|
|
|
|
|
#read source.properties
|
|
|
|
if(EXISTS "${ANDROID_SDK_TOOLS_PATH}/source.properties")
|
|
|
|
file(STRINGS "${ANDROID_SDK_TOOLS_PATH}/source.properties" ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$")
|
|
|
|
foreach(line ${ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES})
|
|
|
|
string(REPLACE "\\:" ":" line ${line})
|
|
|
|
string(REPLACE "=" ";" line ${line})
|
|
|
|
list(GET line 0 line_name)
|
|
|
|
list(GET line 1 line_value)
|
|
|
|
string(REPLACE "." "_" line_name ${line_name})
|
2012-03-16 17:16:31 +08:00
|
|
|
SET(ANDROID_TOOLS_${line_name} "${line_value}" CACHE INTERNAL "from ${ANDROID_SDK_TOOLS_PATH}/source.properties")
|
2012-02-03 19:26:49 +08:00
|
|
|
MARK_AS_ADVANCED(ANDROID_TOOLS_${line_name})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ANDROID_TOOLS_Pkg_Revision)
|
2012-03-16 17:16:31 +08:00
|
|
|
SET(ANDROID_TOOLS_Pkg_Revision "Unknown" CACHE INTERNAL "")
|
2012-02-03 19:26:49 +08:00
|
|
|
MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Revision)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ANDROID_TOOLS_Pkg_Desc)
|
2012-03-16 17:16:31 +08:00
|
|
|
SET(ANDROID_TOOLS_Pkg_Desc "Android SDK Tools, revision ${ANDROID_TOOLS_Pkg_Revision}." CACHE INTERNAL "")
|
2012-02-03 19:26:49 +08:00
|
|
|
if(NOT ANDROID_TOOLS_Pkg_Revision GREATER 11)
|
2012-03-16 17:16:31 +08:00
|
|
|
SET(ANDROID_TOOLS_Pkg_Desc "${ANDROID_TOOLS_Pkg_Desc} It is recommended to update your SDK tools to revision 12 or newer." CACHE INTERNAL "")
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
|
|
|
MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Desc)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#get installed targets
|
|
|
|
execute_process(COMMAND ${ANDROID_EXECUTABLE} list target
|
|
|
|
RESULT_VARIABLE ANDROID_PROCESS
|
|
|
|
OUTPUT_VARIABLE ANDROID_SDK_TARGETS_FULL
|
|
|
|
ERROR_VARIABLE ANDROID_PROCESS_ERRORS
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
string(REGEX MATCHALL "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" ANDROID_SDK_TARGETS_FULL "${ANDROID_SDK_TARGETS_FULL}")
|
|
|
|
|
|
|
|
SET(ANDROID_SDK_TARGETS "")
|
|
|
|
if(ANDROID_PROCESS EQUAL 0)
|
|
|
|
foreach(line ${ANDROID_SDK_TARGETS_FULL})
|
|
|
|
string(REGEX REPLACE "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" "\\2" line "${line}")
|
|
|
|
list(APPEND ANDROID_SDK_TARGETS "${line}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# detect ANDROID_SDK_TARGET if no target is provided by user
|
|
|
|
if(NOT ANDROID_SDK_TARGET)
|
|
|
|
set(desired_android_target_level ${ANDROID_NATIVE_API_LEVEL})
|
2012-02-24 17:35:59 +08:00
|
|
|
if(desired_android_target_level LESS 11)
|
|
|
|
set(desired_android_target_level 11)
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
|
|
|
if(ANDROID_PROCESS EQUAL 0)
|
|
|
|
math(EXPR desired_android_target_level_1 "${desired_android_target_level}-1")
|
|
|
|
|
|
|
|
foreach(target ${ANDROID_SDK_TARGETS})
|
|
|
|
string(REGEX MATCH "[0-9]+$" target_level "${target}")
|
|
|
|
if(target_level GREATER desired_android_target_level_1)
|
|
|
|
set(ANDROID_SDK_TARGET "${target}")
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
else()
|
|
|
|
set(ANDROID_SDK_TARGET android-${desired_android_target_level})
|
|
|
|
message(WARNING "Could not retrieve list of installed Android targets. Will try to use \"${ANDROID_SDK_TARGET}\" target")
|
|
|
|
endif()
|
|
|
|
endif(NOT ANDROID_SDK_TARGET)
|
|
|
|
|
|
|
|
SET(ANDROID_SDK_TARGET "${ANDROID_SDK_TARGET}" CACHE STRING "SDK target for Android tests and samples")
|
|
|
|
if(ANDROID_PROCESS EQUAL 0 AND CMAKE_VERSION VERSION_GREATER "2.8")
|
|
|
|
set_property( CACHE ANDROID_SDK_TARGET PROPERTY STRINGS ${ANDROID_SDK_TARGETS} )
|
|
|
|
endif()
|
|
|
|
string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}")
|
|
|
|
endif(ANDROID_EXECUTABLE)
|