CMakeLists.txt 1.96 KB
Newer Older
1
# ==============================================================================
2
# assets/languages/CMakeLists.txt
3
# ==============================================================================
4 5 6 7

# This line prevent `.ts` files deletion.
# See: https://bugreports.qt.io/browse/QTBUG-31860
#
8
# On October 17, 2016, this issue was marked `invalid` but it's a
9
# bullshit. It's not tolerated to remove source files.
10 11
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM true)

12 13 14 15
# Build languages resource file.
set(TS_FILES)
set(I18N_CONTENT "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n  <qresource prefix=\"/\">\n")
foreach (lang ${LANGUAGES})
16
  list(APPEND TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.ts")
17 18 19 20 21 22 23 24

  # Note: the below `languages/` path is not the same as the `${LANGUAGES_DIRECTORY}` value.
  # It's the symbolic path used by the linphone binary in the qrc model.
  # This path is used in `app.cpp`.
  set(I18N_CONTENT "${I18N_CONTENT}    <file alias=\"languages/${lang}\">${lang}.qm</file>\n")
endforeach ()
set(I18N_CONTENT "${I18N_CONTENT}  </qresource>\n</RCC>\n")

25
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${I18N_FILENAME}" "${I18N_CONTENT}")
26 27

# Create `qm` files from `ts` files.
28
qt5_create_translation(QM_FILES ${TS_FILES} ${SOURCES} ${HEADERS} ${QML_SOURCES} OPTIONS -no-obsolete)
29

30 31 32 33 34 35 36
# Workaround: Create empty files for some cmake versions. Otherwise, the qm rules can't be used.
foreach (qm ${QM_FILES})
  if (NOT EXISTS "${qm}")
    file(GENERATE OUTPUT "${qm}" CONTENT "")
  endif ()
endforeach ()

37 38 39 40 41 42
# Update translations.
add_custom_target(update_translations
  COMMAND ${CMAKE_COMMAND} "-DLANGUAGES=\"${LANGUAGES}\"" -P "${CMAKE_CURRENT_SOURCE_DIR}/clean_translations.cmake"
  DEPENDS ${QM_FILES}
  WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
43

44
# Remove `*.qm` when `clean` is called.
45
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${QM_FILES}")
46 47

# Command to just remove `.qm` files.
48
add_custom_target(remove_qm_files
49
  COMMAND ${CMAKE_COMMAND} -E remove ${QM_FILES}
50
)