Warning, /education/gcompris/android/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 #=============================================================================
0002 # SPDX-FileCopyrightText: 2014 Johnny Jazeix <jazeix@gmail.com>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 #=============================================================================
0006 #android build
0007 # copied/inspired from stellarium project (http://www.stellarium.org/wiki/index.php/Building_for_Android)
0008 
0009 list(APPEND JAVA_SRCS "src/net/gcompris/GComprisActivity.java")
0010 
0011 foreach(JavaSource ${JAVA_SRCS})
0012   add_custom_command(
0013     OUTPUT ${CMAKE_BINARY_DIR}/android-build/${JavaSource}
0014     COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${JavaSource} ${CMAKE_BINARY_DIR}/android-build/${JavaSource}
0015     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${JavaSource}
0016     )
0017   list(APPEND TARGET_JAVA_FILES ${CMAKE_BINARY_DIR}/android-build/${JavaSource})
0018 endforeach()
0019 
0020 add_custom_target(java_src DEPENDS ${TARGET_JAVA_FILES})
0021 
0022 find_program(ANDROID_DEPLOY_QT NAMES androiddeployqt PATHS ${_qt5Core_install_prefix}/bin/)
0023 
0024 # Look for androiddeployqt program
0025 if(NOT ANDROID_DEPLOY_QT)
0026   message(FATAL_ERROR "Could not find androiddeployqt. Make sure you set all the Qt5_* paths to the Qt for android compiled version.")
0027 endif()
0028 
0029 # Set version
0030 set(ANDROID_VERSION_NAME ${GCOMPRIS_VERSION})
0031 
0032 # Set a name representing the build type
0033 set(APK_SUFFIX "-")
0034 
0035 # _HOST have been removed from ECM in https://cgit.kde.org/extra-cmake-modules.git/commit/?id=731ba7036effcc430f98031e7f2a9826f6234cba
0036 set(_HOST "${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
0037 string(TOLOWER "${_HOST}" _HOST)
0038 
0039 if(WITH_DOWNLOAD)
0040   set(APK_SUFFIX "-dl${APK_SUFFIX}")
0041 endif()
0042 
0043 if(WITH_KIOSK_MODE)
0044   set(APK_SUFFIX "-kiosk${APK_SUFFIX}")
0045 endif()
0046 
0047 if(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.14.0")
0048   set(STDCPP_PATH "\"stdcpp-path\": \"${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/\"")
0049 else()
0050   set(STDCPP_PATH ",\"stdcpp-path\": \"${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libc++_shared.so\"")
0051 endif()
0052 
0053 set(ANDROID_TOOLCHAIN arm-linux-androideabi)
0054 if("${CMAKE_ANDROID_ARCH}" STREQUAL "arm64")
0055   set(ANDROID_TOOLCHAIN aarch64-linux-android)
0056 endif()
0057 
0058 # set android package source for androiddeployqt json file
0059 set(PACKAGE_SOURCE_ANDROID ${CMAKE_BINARY_DIR}/tmpAndroid)
0060 set(ANDROID_SDK_ROOT $ENV{ANDROID_SDK_ROOT})
0061 
0062 if(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.14.0")
0063   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest.xml.cmake ${PACKAGE_SOURCE_ANDROID}/AndroidManifest.xml @ONLY)
0064   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configAndroid.json.cmake ${PACKAGE_SOURCE_ANDROID}/configAndroid.json @ONLY)
0065   # TODO Remove this file as soon as we have moved to plugins instead of rcc files for activities
0066   # This way, we'll use the one provided by Qt
0067   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build_5.14.gradle ${PACKAGE_SOURCE_ANDROID}/build.gradle @ONLY)
0068 else()
0069   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest_5.12.xml.cmake ${PACKAGE_SOURCE_ANDROID}/AndroidManifest.xml @ONLY)
0070   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configAndroid_5.12.json.cmake ${PACKAGE_SOURCE_ANDROID}/configAndroid.json @ONLY)
0071 endif()
0072 
0073 # Get all po files in po/ to create the values-{locale} in order to have the locales available in android
0074 file(GLOB TRANSLATIONS_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../po/*.po")
0075 foreach(PoSource ${TRANSLATIONS_FILES})
0076   # Remove suffix ".po"
0077   string(REPLACE ".po" "" PoSource ${PoSource})
0078   # Remove prefix "../po/gcompris_"
0079   string(REPLACE "../po/gcompris_" "" locale ${PoSource})
0080   # replace _ par -r for locales with country
0081   string(REPLACE "_" "-r" locale ${locale})
0082 
0083   add_custom_command(
0084     OUTPUT ${locale}
0085     COMMAND cmake -E make_directory ${GCOMPRIS_TRANSLATIONS_DIR}
0086     COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/android-build/res/values-${locale}
0087     COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/android/strings.xml ${CMAKE_BINARY_DIR}/android-build/res/values-${locale}/strings.xml
0088     )
0089   list(APPEND ALL_LOCALES ${locale})
0090 endforeach()
0091 
0092 add_custom_command(
0093   OUTPUT createApkFromAndroidDeployQtDebug
0094   DEPENDS ${PACKAGE_SOURCE_ANDROID}/AndroidManifest.xml
0095   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${PACKAGE_SOURCE_ANDROID}
0096   COMMAND ${ANDROID_DEPLOY_QT} --output ${CMAKE_BINARY_DIR}/android-build/ --input ${PACKAGE_SOURCE_ANDROID}/configAndroid.json --debug --gradle
0097   COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_BINARY_DIR}/android-build/build/outputs/apk/debug/android-build-debug.apk ${CMAKE_BINARY_DIR}/android-build/GCompris-Android-debug-${ANDROID_ABI}${APK_SUFFIX}${GCOMPRIS_VERSION}.apk
0098 )
0099 
0100 add_custom_command(
0101   OUTPUT createApkFromAndroidDeployQtRelease
0102   DEPENDS ${PACKAGE_SOURCE_ANDROID}/AndroidManifest.xml
0103   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${PACKAGE_SOURCE_ANDROID}
0104   COMMAND ${ANDROID_DEPLOY_QT} --output ${CMAKE_BINARY_DIR}/android-build/ --input ${PACKAGE_SOURCE_ANDROID}/configAndroid.json --release --gradle
0105   COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_BINARY_DIR}/android-build/build/outputs/apk/release/android-build-release-unsigned.apk ${CMAKE_BINARY_DIR}/android-build/GCompris-Android-release-${ANDROID_ABI}${APK_SUFFIX}${GCOMPRIS_VERSION}.apk
0106 )
0107 
0108 add_custom_command(
0109   OUTPUT createApkSignedAlignedFromAndroidDeployQtRelease
0110   DEPENDS ${PACKAGE_SOURCE_ANDROID}/AndroidManifest.xml
0111   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${PACKAGE_SOURCE_ANDROID}
0112   COMMAND ${ANDROID_DEPLOY_QT} --output ${CMAKE_BINARY_DIR}/android-build/ --input ${PACKAGE_SOURCE_ANDROID}/configAndroid.json --gradle --sign $ENV{ANDROID_KEYSTORE} gcompris --storepass $ENV{ANDROID_KEYSTORE_PASSWD}
0113     COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_BINARY_DIR}/android-build/build/outputs/apk/release/android-build-release-signed.apk ${CMAKE_BINARY_DIR}/android-build/GCompris-Android-release-signed-aligned-${ANDROID_ABI}${APK_SUFFIX}${GCOMPRIS_VERSION}.apk
0114 )
0115 
0116 add_custom_command(
0117   OUTPUT createAabFromAndroidDeploy
0118   DEPENDS ${PACKAGE_SOURCE_ANDROID}/AndroidManifest.xml
0119   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${PACKAGE_SOURCE_ANDROID}
0120   COMMAND ${ANDROID_DEPLOY_QT} --output ${CMAKE_BINARY_DIR}/android-build/ --input ${PACKAGE_SOURCE_ANDROID}/configAndroid.json --aab --release --gradle
0121   COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_BINARY_DIR}/android-build/build/outputs/bundle/release/android-build-release.aab ${CMAKE_BINARY_DIR}/android-build/GCompris-Android-release${APK_SUFFIX}${GCOMPRIS_VERSION}.aab
0122   )
0123 
0124 add_custom_command(
0125   OUTPUT apkInstall
0126   DEPENDS ${CMAKE_BINARY_DIR}/android-build/GCompris-Android-release-signed-aligned-${ANDROID_ABI}${APK_SUFFIX}${GCOMPRIS_VERSION}.apk
0127   COMMAND ${ANDROID_SDK_ROOT}/platform-tools/adb install -r ${CMAKE_BINARY_DIR}/android-build/GCompris-Android-release-signed-aligned-${ANDROID_ABI}${APK_SUFFIX}${GCOMPRIS_VERSION}.apk
0128 )
0129 
0130 # Command to create apk from Makefile
0131 add_custom_target(apk_debug
0132   DEPENDS ${ALL_LOCALES} move_translations_to_assets createApkFromAndroidDeployQtDebug java_src
0133 )
0134 
0135 # Command to create apk from Makefile
0136 add_custom_target(apk_release
0137   DEPENDS ${ALL_LOCALES} move_translations_to_assets createApkFromAndroidDeployQtRelease java_src
0138 )
0139 
0140 # Command to create aligned signed apk from Makefile
0141 add_custom_target(apk_aligned_signed
0142   DEPENDS ${ALL_LOCALES} move_translations_to_assets createApkSignedAlignedFromAndroidDeployQtRelease java_src
0143 )
0144 
0145 # Command to create aab from Makefile
0146 add_custom_target(aab_release
0147   DEPENDS ${ALL_LOCALES} move_translations_to_assets createAabFromAndroidDeploy java_src
0148 )
0149 
0150 # Command to install the signed aligned apk through adb from Makefile
0151 add_custom_target(apk_install
0152   DEPENDS apkInstall
0153 )
0154 
0155 # compile openssl needed to download from https
0156 include(ExternalProject)
0157 set(OPENSSL_DIR "${CMAKE_BINARY_DIR}/external/openssl/")
0158 
0159 # For Qt 5.12.5 and above 5.13.0, it needs libcrypto_1_1.so and libssl_1_1.so
0160 set(suffix_libssl ".so")
0161 if(Qt5Core_VERSION VERSION_GREATER_EQUAL "5.12.5" AND NOT Qt5Core_VERSION MATCHES "5.13.0")
0162   set(suffix_libssl "_1_1.so")
0163 endif()
0164 
0165 find_program(LLVM_STRIP NAMES llvm-strip PATHS ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/)
0166 
0167 ExternalProject_Add(
0168   ext_openssl
0169   DOWNLOAD_DIR ${CMAKE_BINARY_DIR}
0170   SOURCE_DIR ${OPENSSL_DIR}
0171   URL https://www.openssl.org/source/openssl-1.1.1w.tar.gz
0172   URL_HASH SHA256=cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8
0173   BUILD_IN_SOURCE 1
0174   CONFIGURE_COMMAND
0175   ${CMAKE_COMMAND} -E env PATH=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin:$ENV{PATH}
0176   ./Configure --prefix=${CMAKE_BINARY_DIR}/android-build --openssldir=./ssl android-${CMAKE_ANDROID_ARCH} shared -D__ANDROID_API__=${CMAKE_ANDROID_API}
0177   BUILD_COMMAND
0178   ${CMAKE_COMMAND} -E env PATH=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin:$ENV{PATH}
0179   make SHLIB_VERSION_NUMBER= SHLIB_EXT=${suffix_libssl} build_libs &&
0180   ${LLVM_STRIP} --strip-all libcrypto${suffix_libssl} &&
0181   ${LLVM_STRIP} --strip-all libcrypto${suffix_libssl}
0182   INSTALL_COMMAND
0183   ${CMAKE_COMMAND} -E copy "${OPENSSL_DIR}/libcrypto${suffix_libssl}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/" &&
0184   ${CMAKE_COMMAND} -E copy "${OPENSSL_DIR}/libssl${suffix_libssl}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/"
0185   )
0186 
0187 #
0188 add_custom_command(
0189   OUTPUT move_translations_to_assets
0190   COMMAND ${CMAKE_COMMAND} -E copy_directory ${GCOMPRIS_TRANSLATIONS_DIR} ${CMAKE_BINARY_DIR}/android-build/assets/share/GCompris
0191   )
0192 
0193 if(TARGET create-apk)
0194   set(PACKAGE_DIR ${PACKAGE_SOURCE_ANDROID})
0195   set_target_properties(create-apk-GCompris PROPERTIES ANDROID_APK_DIR "${PACKAGE_DIR}")
0196   add_custom_target(gcompris-move-metadata ALL
0197     COMMAND cmake -E echo "Moving GCompris shared Android resources"
0198     COMMAND cmake -E make_directory ${PACKAGE_SOURCE_ANDROID}
0199     COMMAND cmake -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}" "${PACKAGE_SOURCE_ANDROID}"
0200     )
0201   add_dependencies(create-apk gcompris-move-metadata)
0202 endif()