1set( _MY_DIR ${CMAKE_CURRENT_LIST_DIR}) 2 3# This function will create a static library target called 'gamesdk'. 4# The location of the library is set according to your ANDROID_NDK_REVISION 5# and ANDROID_PLATFORM, unless you explicitly set GAMESDK_NDK_VERSION 6# GAMESDK_ANDROID_SDK_VERSION or pass these as 4th and 5th arguments. 7# Optional arguments, in order: 8# PACKAGE_DIR: where the packaged version of the library is, relative to the gamesdk root dir 9# default value: package/localtf 10# GAMESDK_GEN_TASK: the gradle task to build the package 11# default value: localTfBuild 12# GAMESDK_DO_BUILD: whether to add a custom build command to build the gamesdk (ON/OFF) 13# default value: ON 14# GAMESDK_NDK_VERSION: version number for the NDK (major.minor) 15# default value: derived from ANDROID_NDK_REVISION 16# GAMESDK_ANDROID_SDK_VERSION: android min SDK level 17# default value: derived from ANDROID_PLATFORM 18# Each argument can be specified using a variable instead of being passed in. 19function(add_gamesdk_target) 20 if(ARGC GREATER 0) 21 if(NOT ${ARGV0} STREQUAL "") 22 set(GAMESDK_PACKAGE_DIR ${ARGV0}) 23 endif() 24 endif() 25 if(ARGC GREATER 1) 26 if(NOT ${ARGV1} STREQUAL "") 27 set(GAMESDK_GEN_TASK ${ARGV1}) 28 endif() 29 endif() 30 if(ARGC GREATER 2) 31 if(NOT ${ARGV2} STREQUAL "") 32 set(GAMESDK_DO_BUILD ${ARGV2}) 33 endif() 34 endif() 35 if(ARGC GREATER 3) 36 if(NOT ${ARGV3} STREQUAL "") 37 set(GAMESDK_NDK_VERSION "${ARGV3}") 38 endif() 39 endif() 40 if(ARGC GREATER 4) 41 set(GAMESDK_ANDROID_SDK_VERSION "${ARGV4}") 42 endif() 43 if(NOT DEFINED GAMESDK_DO_BUILD) 44 set(GAMESDK_DO_BUILD ON) 45 endif() 46 if(NOT DEFINED GAMESDK_PACKAGE_DIR) 47 set(GAMESDK_PACKAGE_DIR "package/localtf") 48 endif() 49 if(NOT DEFINED GAMESDK_GEN_TASK) 50 set(GAMESDK_GEN_TASK "localTfBuild") 51 endif() 52 if (NOT DEFINED GAMESDK_NDK_VERSION) 53 string(REGEX REPLACE "^([^.]+)[.]([^.]+).*" "\\1.\\2" GAMESDK_NDK_VERSION ${ANDROID_NDK_REVISION} ) 54 endif() 55 if (NOT DEFINED GAMESDK_ANDROID_SDK_VERSION) 56 string(REGEX REPLACE "^android-([^.]+)" "\\1" GAMESDK_ANDROID_SDK_VERSION ${ANDROID_PLATFORM} ) 57 endif() 58 set(GAMESDK_PACKAGE_DIR "${_MY_DIR}/../../${GAMESDK_PACKAGE_DIR}") 59 set(BUILD_NAME ${ANDROID_ABI}_SDK${GAMESDK_ANDROID_SDK_VERSION}_NDK${GAMESDK_NDK_VERSION}_${ANDROID_STL}) 60 set(GAMESDK_LIB_DIR "${GAMESDK_PACKAGE_DIR}/libs/${BUILD_NAME}") 61 62 include_directories( "${GAMESDK_PACKAGE_DIR}/include" ) # Games SDK Public Includes 63 get_filename_component(DEP_LIB "${GAMESDK_LIB_DIR}/libgamesdk.a" REALPATH) 64 get_directory_property(hasParent PARENT_DIRECTORY) 65 if(hasParent) 66 set(GAMESDK_LIB ${DEP_LIB} PARENT_SCOPE) 67 endif() 68 69 add_library( gamesdk STATIC IMPORTED GLOBAL) 70 if(GAMESDK_DO_BUILD) 71 add_custom_command(OUTPUT ${DEP_LIB} 72 COMMAND ./gradlew ${GAMESDK_GEN_TASK} -PGAMESDK_ANDROID_SDK_VERSION=${GAMESDK_ANDROID_SDK_VERSION} VERBATIM 73 WORKING_DIRECTORY "${_MY_DIR}/.." ) 74 add_custom_target(gamesdk_lib DEPENDS ${DEP_LIB}) 75 add_dependencies(gamesdk gamesdk_lib) 76 endif() 77 set_target_properties(gamesdk PROPERTIES IMPORTED_LOCATION ${DEP_LIB}) 78 79endfunction() 80