CMakeLists.txt 14.3 KB
Newer Older
Johnny Jazeix's avatar
Johnny Jazeix committed
1
2
3
4
5
if(SAILFISHOS)
  cmake_minimum_required(VERSION 2.8.11)
else(SAILfISHOS)
  cmake_minimum_required(VERSION 2.8.12)
endif()
6

7
project(gcompris-qt C CXX)
8

Johnny Jazeix's avatar
Johnny Jazeix committed
9
10
11
12
13
14
15
16
17
18
19
20
# Set c++11 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
        set(my_cxx_flags "-std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
        set(my_cxx_flags "-std=c++0x")
else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

21
22
23
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}")

24
25
26
# enable qml debugging for DEBUG builds:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG")

27
set(GCOMPRIS_MAJOR_VERSION 0)
28
set(GCOMPRIS_MINOR_VERSION 70)
29
30
set(GCOMPRIS_PATCH_VERSION 0)

31
32
33
# Set the BUILD_DATE
string(TIMESTAMP BUILD_DATE %Y%M)

Johnny Jazeix's avatar
Johnny Jazeix committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# cmake modules setup
find_package(ECM 1.4.0 QUIET NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake/)
set(CMAKE_PREFIX_PATH "${Qt5_DIR}/lib/cmake/Qt5")

# KDE po to qm tools
if(ECM_FOUND)
  include(ECMPoQmTools)
  if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po")
    ecm_install_po_files_as_qm(po)
  endif()
endif(ECM_FOUND)

if(CMAKE_SYSTEM_NAME STREQUAL Android)
  find_package(ECM)
  set(ANDROID 1)
  # TODO: possibly should be setup by toolchain one day
  set(QT_QMAKE_EXECUTABLE "${_qt5Core_install_prefix}/bin/qmake")
  # workaround until this fix is in released ECM
  if(ECM_VERSION VERSION_LESS "5.15.0")
    add_definitions(-DANDROID)
  endif()
endif()

58
59
60
# Set executable filename
if(ANDROID)
  set(GCOMPRIS_EXECUTABLE_NAME GCompris)
Johnny Jazeix's avatar
Johnny Jazeix committed
61
  if("${ANDROID_ARCHITECTURE}" STREQUAL "x86")
62
63
64
    # We always want x86 to be a release above to arm one because the play
    # store want x86 to be pushed after arm.
    MATH(EXPR GCOMPRIS_MINOR_VERSION "${GCOMPRIS_MINOR_VERSION}+1")
Johnny Jazeix's avatar
Johnny Jazeix committed
65
  endif("${ANDROID_ARCHITECTURE}" STREQUAL "x86")
66
67
elseif(SAILFISHOS)
  set(GCOMPRIS_EXECUTABLE_NAME harbour-gcompris-qt)
68
69
70
71
else()
  set(GCOMPRIS_EXECUTABLE_NAME gcompris-qt)
endif()

72
73
74
75
set(GCOMPRIS_VERSION ${GCOMPRIS_MAJOR_VERSION}.${GCOMPRIS_MINOR_VERSION})

# An integer value that represents the version of the application
# Increase it at each release
76
math(EXPR GCOMPRIS_VERSION_CODE "${GCOMPRIS_MAJOR_VERSION}*10000 + ${GCOMPRIS_MINOR_VERSION}*100 + ${GCOMPRIS_PATCH_VERSION}")
77

78
# KDE po to qm tools
Johnny Jazeix's avatar
Johnny Jazeix committed
79
80
81
if(ECM_FOUND)
  include(ECMPoQmTools)
  if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po")
82
    ecm_install_po_files_as_qm(po)
Johnny Jazeix's avatar
Johnny Jazeix committed
83
84
  endif()
endif(ECM_FOUND)
85

Johnny Jazeix's avatar
Johnny Jazeix committed
86
87
88
89
90
91
92
# prevent build in source directory
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
    message(SEND_ERROR "Building in the source directory is not supported.")
    message(FATAL_ERROR "Please remove the created \"CMakeCache.txt\" file, the \"CMakeFiles\"
            directory and create a build directory and call \"${CMAKE_COMMAND} <path to the sources>\".")
endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")

93
94
95
96
97
98
# Sailfish does not provide a recent Qt version
if(SAILFISHOS)
  set(QT_REQUIRED_VERSION 5.2.2)
else()
  set(QT_REQUIRED_VERSION 5.3.0)
endif()
99

Thibaut ROMAIN's avatar
Thibaut ROMAIN committed
100
find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED
101
            Qml Quick Gui Multimedia Core Svg Xml XmlPatterns LinguistTools Sensors)
102

103
104
105
106
107
108
109
find_package (KF5 QUIET COMPONENTS
    DocTools
)
if(KF5_FOUND)
    include(KDEInstallDirs)
endif(KF5_FOUND)

110
FIND_PROGRAM(LCONVERT_EXECUTABLE lconvert-qt5 lconvert
111
112
113
114
115
116
  PATHS
  ${Qt5_DIR}/../../../bin/
  /usr/local/bin
  /usr/bin/
  NO_DEFAULT_PATH
)
117
FIND_PROGRAM(LRELEASE_EXECUTABLE lrelease-qt5 lrelease
118
119
120
121
122
123
124
  PATHS
  ${Qt5_DIR}/../../../bin/
  /usr/local/bin
  /usr/bin/
  NO_DEFAULT_PATH
)

Johnny Jazeix's avatar
Johnny Jazeix committed
125
126
127
128
129
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
#    message("${_variableName}=${${_variableName}}")
#endforeach()

130
set(ACTIVATION_MODE "no" CACHE STRING "Policy for activation [no|inapp|internal]")
131
option(WITH_DEMO_ONLY "Include only demo activities" OFF)
Bruno Coudoin's avatar
Bruno Coudoin committed
132

133
134
135
136
137
138
option(WITH_DOWNLOAD "Internal download" ON)
if(WITH_DOWNLOAD)
  set(ANDROID_INTERNET_PERMISSION "<uses-permission android:name=\"android.permission.INTERNET\" />")
  set(ANDROID_ACCESS_NETWORK_STATE_PERMISSION "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />")
endif(WITH_DOWNLOAD)

139
# Set output directory
140
if(CMAKE_HOST_APPLE)
141
  set(_bundle_bin gcompris-qt.app/Contents/MacOS)
142
  set(_data_dest_dir bin/${_bundle_bin}/../Resources)
143
elseif(ANDROID)
144
  set(_data_dest_dir android/assets)
145
else()
146
  set(_data_dest_dir share/${GCOMPRIS_EXECUTABLE_NAME})
147
endif()
148
149
if(ANDROID)
  # Android .so output
Johnny Jazeix's avatar
Johnny Jazeix committed
150
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/android/libs/${ANDROID_ABI}/)
151
152
  set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir} CACHE INTERNAL "" FORCE)
  set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir} CACHE INTERNAL "" FORCE)
153
  if(ACTIVATION_MODE STREQUAL "inapp")
154
    set(ANDROID_BILLING_PERMISSION "<uses-permission android:name=\"com.android.vending.BILLING\"/>")
Bruno Coudoin's avatar
Bruno Coudoin committed
155
    set(ANDROID_PACKAGE "net.gcompris")
156
  else(ACTIVATION_MODE)
Bruno Coudoin's avatar
Bruno Coudoin committed
157
158
    set(ANDROID_PACKAGE "net.gcompris.full")
  endif()
159
  add_subdirectory(android)
160
161
162
163
164
165
elseif(CMAKE_HOST_APPLE)
  # MacOSX build
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/translations CACHE INTERNAL "" FORCE)
  set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/rcc CACHE INTERNAL "" FORCE)
else()
166
167
  # Desktop build
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
168
169
  set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/translations CACHE INTERNAL "" FORCE)
  set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir}/rcc CACHE INTERNAL "" FORCE)
170
171
endif(ANDROID)

172
173
174
175
176
177
178
179
180
181
182
# Always create these folders
add_custom_command(
  OUTPUT shareFolders
  COMMAND cmake -E make_directory ${GCOMPRIS_TRANSLATIONS_DIR}
  COMMAND cmake -E make_directory ${GCOMPRIS_RCC_DIR}
  )
add_custom_target(
  createShareFolders ALL
  DEPENDS shareFolders
  )

183
184
include(cmake/rcc.cmake)

185
186
187
188
189
190
191
192
193
# Translations handling

# Simple command calling the python script
  add_custom_command(
    OUTPUT retrievePoFilesFromSvn
    COMMAND python2 tools/l10n-fetch-po-files.py
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )
# Install translations
194
add_custom_target(getSvnTranslations
195
  DEPENDS retrievePoFilesFromSvn
196
  COMMENT "Re-run cmake after this to be able to run BuildTranslations with the latest files"
197
198
  )

199
# Get all po files in po/. You can get them doing: python2 tools/l10n-fetch-po-files.py
200
201
202
203
204
205
206
207
208
209
file(GLOB TRANSLATIONS_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "po/*.po")
# Set the output dir for the translation files to /bin
foreach(PoSource ${TRANSLATIONS_FILES})
  # Changes the .po extension to .ts
  string(REPLACE ".po" ".ts" TsSource ${PoSource})
  # Removes the po/ folder
  string(REPLACE "po/" "" TsSource ${TsSource})
  # qm filename
  string(REPLACE ".ts" ".qm" QmOutput ${TsSource})

Johnny Jazeix's avatar
Johnny Jazeix committed
210
  set(OutTsFile ${CMAKE_BINARY_DIR}/tmp/${TsSource})
211
212
213
214
  add_custom_command(
    OUTPUT ${QmOutput}
    COMMAND cmake -E make_directory ${GCOMPRIS_TRANSLATIONS_DIR}
    COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/tmp
Johnny Jazeix's avatar
Johnny Jazeix committed
215
216
217
    # Remove the obsolete translations and set po in the ts output file
    COMMAND msgattrib --no-obsolete  ${CMAKE_CURRENT_SOURCE_DIR}/${PoSource} -o ${OutTsFile}
    # Convert the po into ts
218
    COMMAND ${LCONVERT_EXECUTABLE} -if po -of ts -i ${OutTsFile} -o ${OutTsFile}
Johnny Jazeix's avatar
Johnny Jazeix committed
219
    # Convert the ts in qm removing non finished translations
220
    COMMAND ${LRELEASE_EXECUTABLE} -compress -nounfinished ${OutTsFile} -qm ${GCOMPRIS_TRANSLATIONS_DIR}/${QmOutput}
221
222
223
224
225
    )
  list(APPEND QM_FILES ${QmOutput})
endforeach()

# Install translations
226
add_custom_target(BuildTranslations
227
  DEPENDS ${QM_FILES}
228
  COMMENT "If you don't have the .po, you need to run make getSvnTranslations first then re-run cmake"
229
230
231
232
233
234
235
236
  )

if(CMAKE_HOST_APPLE)
  install(DIRECTORY ${GCOMPRIS_TRANSLATIONS_DIR} DESTINATION ${_bundle_bin})
else()
  install(DIRECTORY ${GCOMPRIS_TRANSLATIONS_DIR} DESTINATION ${_data_dest_dir})
endif()

237
238
239
240
# Build standalone package option -> if ON, we will copy the required Qt files in the build package.
# If OFF, "make install" will not copy Qt files so only GCompris files will be packaged.
# By default, it is true on Windows (as we deliver NSIS package), macOS (bundled), android (apk) and false on linux (to do make install)
# If you want to create a STGZ package for linux (auto-extractible), override this variable by typing : cmake -DBUILD_STANDALONE=ON
241
if(UNIX AND NOT ANDROID AND NOT APPLE)
242
243
244
245
  option(BUILD_STANDALONE "Build a standalone package when typing 'make package'" OFF)
else()
  option(BUILD_STANDALONE "Build a standalone package when typing 'make package'" ON)
endif()
246

247
option(WITH_KIOSK_MODE "Set the kiosk mode by default" OFF)
248

249
if(WIN32)
Johnny Jazeix's avatar
Johnny Jazeix committed
250
  set(COMPRESSED_AUDIO "mp3" CACHE STRING "Compressed Audio format [ogg|aac|mp3]")
251
elseif(APPLE)
Johnny Jazeix's avatar
Johnny Jazeix committed
252
  set(COMPRESSED_AUDIO "aac" CACHE STRING "Compressed Audio format [ogg|aac|mp3]")
253
else()
Johnny Jazeix's avatar
Johnny Jazeix committed
254
  set(COMPRESSED_AUDIO "ogg" CACHE STRING "Compressed Audio format [ogg|aac|mp3]")
255
endif()
Bruno Coudoin's avatar
Bruno Coudoin committed
256

257
258
259
260
261
262
263
264
265
266
267
268
file(GLOB_RECURSE OGG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/ "*.ogg")

foreach(OGG_FILE ${OGG_FILES})
  # This should only replace the extension
  string(REGEX REPLACE "ogg$" "aac" AAC_FILE ${OGG_FILE})
  add_custom_command(
    OUTPUT ${AAC_FILE}
    # Put the good line depending on your installation
    COMMAND avconv -v warning -i ${OGG_FILE} -acodec libvo_aacenc ${AAC_FILE}
    #COMMAND ffmpeg -v warning -i ${OGG_FILE} -acodec aac -strict -2 ${AAC_FILE}
    )
  list(APPEND AAC_FILES ${AAC_FILE})
Johnny Jazeix's avatar
Johnny Jazeix committed
269
270
271
272
273
274
275

  # This should only replace the extension
  string(REGEX REPLACE "ogg$" "mp3" MP3_FILE ${OGG_FILE})
  add_custom_command(
    OUTPUT ${MP3_FILE}
    # Put the good line depending on your installation
    #COMMAND avconv -v warning -i ${OGG_FILE} -acodec mp3 ${MP3_FILE}
276
    COMMAND ffmpeg -v warning -i ${OGG_FILE} -acodec mp3 -strict -2 ${MP3_FILE}
Johnny Jazeix's avatar
Johnny Jazeix committed
277
278
    )
  list(APPEND MP3_FILES ${MP3_FILE})
279
280
281
282
283
284
285
endforeach()

add_custom_target(
  createAacFromOgg
  DEPENDS ${AAC_FILES}
  )

Johnny Jazeix's avatar
Johnny Jazeix committed
286
287
288
289
290
add_custom_target(
  createMp3FromOgg
  DEPENDS ${MP3_FILES}
  )

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# predownload assets (voices and images) and install them in the rcc folder
set(DOWNLOAD_ASSETS "" CACHE STRING "Download and packages images and voices. use a list like: words,en,fr,pt_BR to retrieve multiple files")
add_custom_command(
    OUTPUT predownloadAssets
    COMMAND python2 tools/download-assets.py ${DOWNLOAD_ASSETS} ${COMPRESSED_AUDIO} ${GCOMPRIS_RCC_DIR}
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )

add_custom_command(
  OUTPUT assetsFolders
  COMMAND cmake -E make_directory "${GCOMPRIS_RCC_DIR}/data2"
  COMMAND cmake -E make_directory "${GCOMPRIS_RCC_DIR}/data2/voices-${COMPRESSED_AUDIO}"
  COMMAND cmake -E make_directory "${GCOMPRIS_RCC_DIR}/data2/words"
  )
# Install assets
add_custom_target(getAssets
  DEPENDS assetsFolders predownloadAssets
  )



312
313
314
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GCOMPRIS_VERSION})
add_custom_target(dist
    COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
315
        | xz > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.xz
316
317
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

318
319
320
if(KF5_FOUND)
    add_subdirectory(docs/docbook)
endif(KF5_FOUND)
321
322
323
324
325
326

if(SAILFISHOS)
  # Need to be done at the end, after src
  add_subdirectory(platforms/sailfishOS)
endif()

327
#
328
# qml-box2d
329
#
330

331
set(QML_BOX2D_MODULE "auto" CACHE STRING "Policy for qml-box2d module [auto|submodule|system|disabled]")
332

333
334
if (${QML_BOX2D_MODULE} STREQUAL "disabled")
  # disable all activities depending on qml-box2d
335
  set(_disabled_activities "balancebox,land_safe")
336
337
338
  message(STATUS "Disabling qml-box2d module and depending activities: ${_disabled_activities}")
else()
  include(qt_helper)
339

340
341
  getQtQmlPath(_qt_qml_system_path)
  set (_box2d_system_dir "${_qt_qml_system_path}/Box2D.2.0")
342

343
344
345
  if (${QML_BOX2D_MODULE} STREQUAL "submodule")
    message(STATUS "Building qml-box2d module from submodule")
    set(_need_box2d_submodule "TRUE")
346
  else()
347
348
349
350
351
352
353
354
355
356
357
    # try to find module in system scope
    find_library(QML_BOX2D_LIBRARY NAMES Box2D libBox2D PATHS ${_box2d_system_dir} NO_DEFAULT_PATH)
    if (QML_BOX2D_LIBRARY)
      message(STATUS "Using system qml-box2d plugin at ${QML_BOX2D_LIBRARY}")
      # for packaging builds, copy the module manually to the correct location
      if(SAILFISHOS)
        file(COPY ${_box2d_system_dir}/qmldir ${QML_BOX2D_LIBRARY} DESTINATION share/harbour-gcompris-qt/lib/qml/Box2D.2.0)
      elseif(ANDROID)
        file(COPY ${_box2d_system_dir}/qmldir ${QML_BOX2D_LIBRARY} DESTINATION lib/qml/Box2D.2.0)
      endif()
      # FIXME: add others as needed
358
    else()
359
360
361
362
363
364
      if (${QML_BOX2D_MODULE} STREQUAL "auto")
        message(STATUS "Did not find the qml-box2d module in system scope, falling back to submodule build ...")
        set (_need_box2d_submodule "TRUE")
      else()
        message(FATAL_ERROR "Did not find the qml-box2d module in system scope and submodule build was not requested. Can't continue!")
      endif()
365
366
367
    endif()
  endif()

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  if (_need_box2d_submodule)
    # build qml-box2d ourselves from submodule
    include(ExternalProject)
    get_property(_qmake_program TARGET ${Qt5Core_QMAKE_EXECUTABLE} PROPERTY IMPORT_LOCATION)
    set (_box2d_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/external/qml-box2d)
    if(WIN32)
      set (_box2d_library_dir "release/")
      set (_box2d_library_file "Box2D.dll")
    else()
      set (_box2d_library_dir "")
      set (_box2d_library_file "libBox2D.so")
    endif()
    set (_box2d_install_dir ${CMAKE_CURRENT_BINARY_DIR}/lib/qml/Box2D.2.0)
    # make sure submodule is up2date
    find_package(Git)
    if(GIT_FOUND)
      execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init)
    endif()
386

387
388
389
390
391
392
393
394
    ExternalProject_Add(qml_box2d
      DOWNLOAD_COMMAND ""
      SOURCE_DIR ${_box2d_source_dir}
      CONFIGURE_COMMAND ${_qmake_program} ${_box2d_source_dir}/box2d.pro
      BUILD_COMMAND ${CMAKE_MAKE_PROGRAM}
      INSTALL_DIR ${_box2d_install_dir}
      INSTALL_COMMAND cp ${_box2d_library_dir}${_box2d_library_file} ${_box2d_source_dir}/qmldir ${_box2d_install_dir}
      )
395

396
397
    add_library(qml-box2d SHARED IMPORTED)
    set_target_properties(qml-box2d PROPERTIES IMPORTED_LOCATION ${_box2d_install_dir}/${_box2d_library_file})
398

399
400
401
402
403
    if(SAILFISHOS)
      install(DIRECTORY ${_box2d_install_dir} DESTINATION share/harbour-gcompris-qt/lib/qml)
    else()
      install(DIRECTORY ${_box2d_install_dir} DESTINATION lib/qml)
    endif()
404
  endif()
405
endif()
406
407

add_subdirectory(src)