Warning, /education/gcompris/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 cmake_minimum_required(VERSION 3.5)
0007 
0008 project(gcompris-qt C CXX)
0009 
0010 # get all the redist dll needed for windows when compiling with vc
0011 set(CMAKE_INSTALL_UCRT_LIBRARIES 1)
0012 include(InstallRequiredSystemLibraries)
0013 
0014 # Set c++11 support
0015 set(CMAKE_CXX_STANDARD 11)
0016 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0017 set(CMAKE_CXX_EXTENSIONS OFF)
0018 
0019 # enable qml debugging for DEBUG builds:
0020 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG")
0021 
0022 set(GCOMPRIS_MAJOR_VERSION 3)
0023 set(GCOMPRIS_MINOR_VERSION 0)
0024 set(GCOMPRIS_PATCH_VERSION 0)
0025 
0026 if("${CMAKE_ANDROID_ARCH}" STREQUAL "arm64")
0027   set(GCOMPRIS_PATCH_VERSION 1)
0028 endif()
0029 
0030 # Set the BUILD_DATE
0031 string(TIMESTAMP BUILD_DATE %Y%m)
0032 
0033 # cmake modules setup
0034 find_package(ECM 1.4.0 QUIET NO_MODULE)
0035 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake/)
0036 set(CMAKE_PREFIX_PATH "${Qt5_DIR}/")
0037 
0038 # KDE po to qm tools
0039 if(ECM_FOUND)
0040   include(kdeFetchTranslation)
0041   include(ECMAddTests)
0042   include(ECMPoQmTools)
0043   if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po")
0044     ecm_install_po_files_as_qm(po)
0045   endif()
0046 
0047   option(BUILD_TESTING "Build and enable unit tests" OFF)
0048   include(ECMCoverageOption)
0049 endif()
0050 
0051 # add tools (cppcheck, clang-tidy...) if build on testing mode only
0052 # (slower compilation)
0053 if(BUILD_TESTING)
0054   include(CodeQualityUtils)
0055 endif()
0056 
0057 set(QT_REQUIRED_VERSION 5.12.0)
0058 
0059 if(CMAKE_SYSTEM_NAME STREQUAL Android)
0060   find_package(ECM)
0061   set(ANDROID 1)
0062   # Require ndk minimum version to 21
0063   if(ANDROID_NDK_REVISION VERSION_LESS "21.0.0")
0064     message(FATAL_ERROR "android ndk 21 minimal required, actually using ${ANDROID_NDK_REVISION}")
0065   endif()
0066   # TODO: possibly should be setup by toolchain one day
0067   set(QT_QMAKE_EXECUTABLE "${_qt5Core_install_prefix}/bin/qmake")
0068   if(ECM_VERSION VERSION_GREATER "5.55.0")
0069     set(QT_REQUIRED_VERSION 5.12.0)
0070   endif()
0071 
0072   # workaround until this fix is in released ECM
0073   if(ECM_VERSION VERSION_LESS "5.15.0")
0074     add_definitions(-DANDROID)
0075   endif()
0076 endif()
0077 
0078 # Set executable filename
0079 if(ANDROID)
0080   set(GCOMPRIS_EXECUTABLE_NAME GCompris)
0081 elseif(WIN32)
0082   set(GCOMPRIS_EXECUTABLE_NAME GCompris)
0083 else()
0084   set(GCOMPRIS_EXECUTABLE_NAME gcompris-qt)
0085 endif()
0086 
0087 set(GCOMPRIS_VERSION ${GCOMPRIS_MAJOR_VERSION}.${GCOMPRIS_MINOR_VERSION})
0088 
0089 # An integer value that represents the version of the application
0090 # Increase it at each release
0091 math(EXPR GCOMPRIS_VERSION_CODE "${GCOMPRIS_MAJOR_VERSION}*10000 + ${GCOMPRIS_MINOR_VERSION}*100 + ${GCOMPRIS_PATCH_VERSION}")
0092 
0093 # prevent build in source directory
0094 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
0095     message(SEND_ERROR "Building in the source directory is not supported.")
0096     message(FATAL_ERROR "Please remove the created \"CMakeCache.txt\" file, the \"CMakeFiles\"
0097             directory and create a build directory and call \"${CMAKE_COMMAND} <path to the sources>\".")
0098 endif()
0099 
0100 find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED
0101     Qml Quick Gui Multimedia Core Svg LinguistTools Sensors QuickControls2 QuickTemplates2)
0102 
0103 if(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.15.0")
0104   find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED QmlWorkerScript QuickParticles)
0105 endif()
0106 
0107 if(ANDROID)
0108     find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED AndroidExtras)
0109 endif()
0110 
0111 ## For now we workaround CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION to clang with a command variable, so not needed
0112 # if(ANDROID AND ECM_VERSION VERSION_LESS "5.56.0" AND Qt5Core_VERSION VERSION_GREATER "5.11.99")
0113 #   message(FATAL_ERROR "ECM ${ECM_VERSION} not compatible with Qt ${Qt5Core_VERSION} version for android.")
0114 # endif()
0115 
0116 if((UNIX AND NOT APPLE AND NOT ANDROID) OR WIN32)
0117     find_package(OpenSSL REQUIRED)
0118 endif()
0119 
0120 
0121 option(COMPILE_DOC "Enable compilation of GCompris docbook" OFF)
0122 if(COMPILE_DOC)
0123   find_package(KF5 QUIET COMPONENTS DocTools)
0124 endif()
0125 
0126 if(ECM_FOUND)
0127     include(KDEInstallDirs)
0128 
0129     if(ECM_VERSION VERSION_GREATER "1.6.0")
0130         add_subdirectory(images)
0131         install(FILES org.kde.gcompris.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
0132         install(FILES org.kde.gcompris.desktop DESTINATION ${KDE_INSTALL_APPDIR})
0133     else()
0134         message(STATUS "ECM_VERSION is ${ECM_VERSION}, icons and desktop files won't be installed.")
0135     endif()
0136 endif()
0137 
0138 # Tell CMake to run moc when necessary:
0139 set(CMAKE_AUTOMOC ON)
0140 
0141 # As moc files are generated in the binary dir, tell CMake
0142 # to always look for includes there:
0143 set(CMAKE_INCLUDE_CURRENT_DIR ON)
0144 
0145 #get_cmake_property(_variableNames VARIABLES)
0146 #foreach (_variableName ${_variableNames})
0147 #    message("${_variableName}=${${_variableName}}")
0148 #endforeach()
0149 
0150 option(WITH_DOWNLOAD "Internal download" ON)
0151 # @FIXME These permissions should be removed if download is disable
0152 #        but it makes the application crash on exit (tested on Android 6)
0153 set(ANDROID_INTERNET_PERMISSION "<uses-permission android:name=\"android.permission.INTERNET\" />")
0154 set(ANDROID_ACCESS_NETWORK_STATE_PERMISSION "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />")
0155 
0156 set(GRAPHICAL_RENDERER "auto" CACHE STRING "Policy for choosing the renderer backend [opengl|software|auto]")
0157 
0158 # Set output directory
0159 if(CMAKE_HOST_APPLE)
0160   set(_bundle_bin gcompris-qt.app/Contents/MacOS)
0161   set(_data_dest_dir bin/${_bundle_bin}/../Resources)
0162 else()
0163   set(_data_dest_dir share/${GCOMPRIS_EXECUTABLE_NAME})
0164 endif()
0165 if(ANDROID)
0166   # Android .so output
0167   if(Qt5Widgets_VERSION VERSION_LESS "5.14.0")
0168     set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/android-build/libs/${ANDROID_ABI}/)
0169   endif()
0170   set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir} CACHE INTERNAL "" FORCE)
0171   set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/android-build/assets/${_data_dest_dir}/rcc CACHE INTERNAL "" FORCE)
0172   set(ANDROID_PACKAGE "net.gcompris.full")
0173   add_subdirectory(android)
0174 elseif(CMAKE_HOST_APPLE)
0175   # MacOSX build
0176   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
0177   set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/translations CACHE INTERNAL "" FORCE)
0178   set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/rcc CACHE INTERNAL "" FORCE)
0179 else()
0180   # Desktop build
0181   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
0182   set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/translations CACHE INTERNAL "" FORCE)
0183   set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/rcc CACHE INTERNAL "" FORCE)
0184 endif()
0185 
0186 # Always create these folders
0187 add_custom_command(
0188   OUTPUT shareFolders
0189   COMMAND cmake -E make_directory ${GCOMPRIS_TRANSLATIONS_DIR}
0190   COMMAND cmake -E make_directory ${GCOMPRIS_RCC_DIR}
0191   )
0192 add_custom_target(
0193   createShareFolders ALL
0194   DEPENDS shareFolders
0195   )
0196 
0197 include(cmake/rcc.cmake)
0198 
0199 # Translations handling
0200 
0201 # Simple command calling the python script
0202   add_custom_command(
0203     OUTPUT retrievePoFilesFromSvn
0204     COMMAND python3 tools/l10n-fetch-po-files.py
0205     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0206     )
0207 # Install translations
0208 add_custom_target(getSvnTranslations
0209   DEPENDS retrievePoFilesFromSvn
0210   COMMENT "Re-run cmake after this to be able to run BuildTranslations with the latest files"
0211   )
0212 
0213 # Get all po files in po/. You can get them doing: python3 tools/l10n-fetch-po-files.py
0214 file(GLOB TRANSLATIONS_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "po/*.po")
0215 # Set the output dir for the translation files to /bin
0216 foreach(PoSource ${TRANSLATIONS_FILES})
0217   # Changes the .po extension to .ts
0218   string(REPLACE ".po" ".ts" TsSource ${PoSource})
0219   # Removes the po/ folder
0220   string(REPLACE "po/" "" TsSource ${TsSource})
0221   # qm filename
0222   string(REPLACE ".ts" ".qm" QmOutput ${TsSource})
0223 
0224   set(OutTsFile ${CMAKE_BINARY_DIR}/tmp/${TsSource})
0225   add_custom_command(
0226     OUTPUT ${QmOutput}
0227     COMMAND cmake -E make_directory ${GCOMPRIS_TRANSLATIONS_DIR}
0228     COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/tmp
0229     # Remove the obsolete translations and set po in the ts output file
0230     COMMAND msgattrib --no-obsolete  ${CMAKE_CURRENT_SOURCE_DIR}/${PoSource} -o ${OutTsFile}
0231     # Convert the po into ts
0232     COMMAND Qt5::lconvert -if po -of ts -i ${OutTsFile} -o ${OutTsFile}
0233     # Convert the ts in qm removing non finished translations
0234     COMMAND Qt5::lrelease -compress -nounfinished ${OutTsFile} -qm ${GCOMPRIS_TRANSLATIONS_DIR}/${QmOutput}
0235     )
0236   list(APPEND QM_FILES ${QmOutput})
0237 endforeach()
0238 
0239 # Install translations
0240 if(WIN32)
0241     add_custom_target(BuildTranslations
0242         DEPENDS ${QM_FILES}
0243         COMMENT "If you don't have the .po, you need to run make getSvnTranslations first then re-run cmake"
0244     )
0245 else()
0246     add_custom_target(BuildTranslations ALL
0247         DEPENDS ${QM_FILES}
0248         COMMENT "If you don't have the .po, you need to run make getSvnTranslations first then re-run cmake"
0249     )
0250 endif()
0251 
0252 add_custom_command(
0253     OUTPUT doBundleTranslations
0254     COMMAND 7z a -w${CMAKE_BINARY_DIR}/share/${GCOMPRIS_EXECUTABLE_NAME}
0255                ${CMAKE_BINARY_DIR}/translations-${GCOMPRIS_VERSION}.7z
0256                ${CMAKE_BINARY_DIR}/share/${GCOMPRIS_EXECUTABLE_NAME}/translations
0257     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0258     )
0259 # Bundle translations
0260 add_custom_target(BundleTranslations
0261   DEPENDS doBundleTranslations
0262   COMMENT "If you want to provide a zip of the translations on a server (run make BuildTranslations first)"
0263   )
0264 
0265 add_custom_command(
0266     OUTPUT doDlAndInstallBundledTranslations
0267     COMMAND curl -fsS -o translations-${GCOMPRIS_VERSION}.7z
0268                https://gcompris.net/download/translations-${GCOMPRIS_VERSION}.7z
0269     COMMAND 7z x -y -o${CMAKE_BINARY_DIR}/share/${GCOMPRIS_EXECUTABLE_NAME}
0270                translations-${GCOMPRIS_VERSION}.7z
0271     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
0272     )
0273 # Download and install bundled translations
0274 add_custom_target(DlAndInstallBundledTranslations
0275   DEPENDS doDlAndInstallBundledTranslations
0276   COMMENT "Download the bundled translation and install them in the build dir"
0277   )
0278 
0279 if(CMAKE_HOST_APPLE)
0280   install(DIRECTORY ${GCOMPRIS_TRANSLATIONS_DIR} DESTINATION ${_bundle_bin})
0281 elseif(ANDROID)
0282   install(DIRECTORY ${GCOMPRIS_TRANSLATIONS_DIR} DESTINATION "share")
0283 else()
0284   install(DIRECTORY ${GCOMPRIS_TRANSLATIONS_DIR} DESTINATION ${_data_dest_dir})
0285 endif()
0286 
0287 # Build standalone package option -> if ON, we will copy the required Qt files in the build package.
0288 # If OFF, "make install" will not copy Qt files so only GCompris files will be packaged.
0289 # By default, it is true on Windows (as we deliver NSIS package), macOS (bundled), android (apk) and false on linux (to do make install)
0290 # If you want to create a STGZ package for linux (auto-extractible), override this variable by typing : cmake -DBUILD_STANDALONE=ON
0291 if(UNIX AND NOT ANDROID AND NOT APPLE)
0292   option(BUILD_STANDALONE "Build a standalone package when typing 'make package'" OFF)
0293 else()
0294   option(BUILD_STANDALONE "Build a standalone package when typing 'make package'" ON)
0295 endif()
0296 
0297 option(WITH_KIOSK_MODE "Set the kiosk mode by default" OFF)
0298 
0299 if(WIN32)
0300   set(COMPRESSED_AUDIO "mp3" CACHE STRING "Compressed Audio format [ogg|aac|mp3]")
0301 elseif(APPLE)
0302   set(COMPRESSED_AUDIO "aac" CACHE STRING "Compressed Audio format [ogg|aac|mp3]")
0303 else()
0304   set(COMPRESSED_AUDIO "ogg" CACHE STRING "Compressed Audio format [ogg|aac|mp3]")
0305 endif()
0306 
0307 file(GLOB_RECURSE OGG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/ "*.ogg")
0308 
0309 foreach(OGG_FILE ${OGG_FILES})
0310   # This should only replace the extension
0311   string(REGEX REPLACE "ogg$" "aac" AAC_FILE ${OGG_FILE})
0312   add_custom_command(
0313     OUTPUT ${AAC_FILE}
0314     # Put the good line depending on your installation
0315     COMMAND avconv -v warning -i ${OGG_FILE} -acodec libvo_aacenc ${AAC_FILE}
0316     #COMMAND ffmpeg -v warning -i ${OGG_FILE} -acodec aac -strict -2 ${AAC_FILE}
0317     )
0318   list(APPEND AAC_FILES ${AAC_FILE})
0319 
0320   # This should only replace the extension
0321   string(REGEX REPLACE "ogg$" "mp3" MP3_FILE ${OGG_FILE})
0322   add_custom_command(
0323     OUTPUT ${MP3_FILE}
0324     # Put the good line depending on your installation
0325     #COMMAND avconv -v warning -i ${OGG_FILE} -acodec mp3 ${MP3_FILE}
0326     COMMAND ffmpeg -v warning -i ${OGG_FILE} -acodec mp3 -strict -2 ${MP3_FILE}
0327     )
0328   list(APPEND MP3_FILES ${MP3_FILE})
0329 endforeach()
0330 
0331 add_custom_target(
0332   createAacFromOgg
0333   DEPENDS ${AAC_FILES}
0334   )
0335 
0336 add_custom_target(
0337   createMp3FromOgg
0338   DEPENDS ${MP3_FILES}
0339   )
0340 
0341 if(ANDROID)
0342   set(GCOMPRIS_ASSETS_DIR ${GCOMPRIS_RCC_DIR}/../../../ CACHE INTERNAL "" FORCE)
0343 else()
0344   set(GCOMPRIS_ASSETS_DIR ${GCOMPRIS_RCC_DIR} CACHE INTERNAL "" FORCE)
0345 endif()
0346 
0347 # predownload assets (voices and images) and install them in the rcc folder
0348 set(DOWNLOAD_ASSETS "" CACHE STRING "Download and packages images and voices. use a list like: words,en,fr,pt_BR,music to retrieve multiple files")
0349 add_custom_command(
0350     OUTPUT predownloadAssets
0351     COMMAND python3 tools/download-assets.py ${DOWNLOAD_ASSETS} ${COMPRESSED_AUDIO} ${GCOMPRIS_ASSETS_DIR}
0352     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0353     )
0354 
0355 add_custom_command(
0356     OUTPUT assetsFolders
0357     COMMAND cmake -E make_directory "${GCOMPRIS_ASSETS_DIR}/data2"
0358     COMMAND cmake -E make_directory "${GCOMPRIS_ASSETS_DIR}/data2/voices-${COMPRESSED_AUDIO}"
0359     COMMAND cmake -E make_directory "${GCOMPRIS_ASSETS_DIR}/data2/words"
0360     COMMAND cmake -E make_directory "${GCOMPRIS_ASSETS_DIR}/data2/backgroundMusic"
0361     )
0362 # Install assets
0363 add_custom_target(getAssets
0364   DEPENDS assetsFolders predownloadAssets
0365   )
0366 
0367 add_custom_command(
0368     OUTPUT doBundleConvertedOggs
0369     COMMAND 7z a converted_ogg_to_${COMPRESSED_AUDIO}-${GCOMPRIS_VERSION}.7z '-ir!src/*${COMPRESSED_AUDIO}'
0370     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0371     )
0372 # Bundle oggs ready to be uploaded on a server. This ease build on system without the appropriate audio
0373 # convertion tools.
0374 add_custom_target(BundleConvertedOggs
0375   DEPENDS doBundleConvertedOggs
0376   COMMENT "Bundle the converted oggs to upload them on a server. First set COMPRESSED_AUDIO appropriately."
0377   )
0378 
0379 add_custom_command(
0380     OUTPUT doDlAndInstallBundledConvertedOggs
0381     COMMAND curl -fsS -o converted_ogg_to_${COMPRESSED_AUDIO}-${GCOMPRIS_VERSION}.7z
0382             https://gcompris.net/download/converted_ogg_to_${COMPRESSED_AUDIO}-${GCOMPRIS_VERSION}.7z
0383     COMMAND 7z x -y converted_ogg_to_${COMPRESSED_AUDIO}-${GCOMPRIS_VERSION}.7z
0384     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0385     )
0386 # Download and install bundled converted oggs
0387 add_custom_target(DlAndInstallBundledConvertedOggs
0388   DEPENDS doDlAndInstallBundledConvertedOggs
0389   COMMENT "Download the bundled converted oggs and install them in the source dir"
0390   )
0391 
0392 if(${GCOMPRIS_PATCH_VERSION} STREQUAL 0)
0393   set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GCOMPRIS_VERSION})
0394 else()
0395   set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GCOMPRIS_VERSION}.${GCOMPRIS_PATCH_VERSION})
0396 endif()
0397 
0398 add_custom_target(dist
0399     COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
0400         | xz > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.xz
0401     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
0402 
0403 if(KF5_FOUND)
0404     add_subdirectory(docs/docbook)
0405 endif()
0406 
0407 # qml-box2d
0408 include(cmake/box2d.cmake)
0409 
0410 # qtquick-calendar only for Qt6.0 -> 6.2
0411 if(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "6.0" AND Qt5Widgets_VERSION VERSION_LESS "6.3.0")
0412   set(ANDROID_QT_QUICK_CALENDAR_EXTRA_PLUGIN_PATH ",${CMAKE_BINARY_DIR}/lib/qml/QtQuick")
0413   include(cmake/qtquickcalendar.cmake)
0414 endif()
0415 
0416 add_subdirectory(src)
0417 
0418 if (UBUNTU_TOUCH)
0419     add_subdirectory(platforms/ubuntutouch)
0420 endif ()
0421 
0422 # only enable unit tests for linux
0423 if(BUILD_TESTING)
0424   enable_testing()
0425   add_subdirectory(tests)
0426 endif()
0427 
0428 add_custom_target(binaries)
0429 add_dependencies(binaries ${GCOMPRIS_EXECUTABLE_NAME} rcc_core rcc_menu rcc_activities all_activities)