blob: b1a15fd5eae0da67f1292211d016cfd79d53da26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# Copyright 2020-2021 The Mumble Developers. All rights reserved.
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.
function(include_qt_plugin TARGET SCOPE PLUGIN)
set(PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_plugin_import.cpp")
if(NOT EXISTS ${PATH})
file(WRITE ${PATH} "#include <QtPlugin>\n")
set_property(SOURCE ${PATH} PROPERTY GENERATED TRUE SKIP_AUTOGEN TRUE)
set_property(SOURCE ${PATH} PROPERTY SKIP_UNITY_BUILD_INCLUSION TRUE)
else()
file(READ ${PATH} CONTENT)
string(FIND ${CONTENT} ${PLUGIN} INDEX)
if(NOT ${INDEX} EQUAL -1)
set(FOUND TRUE)
endif()
endif()
if(NOT FOUND)
file(APPEND ${PATH} "Q_IMPORT_PLUGIN(${PLUGIN})\n")
endif()
get_property(TARGET_SOURCES TARGET ${TARGET} PROPERTY SOURCES)
if(NOT ${PATH} IN_LIST TARGET_SOURCES)
target_sources(${TARGET} ${SCOPE} ${PATH})
endif()
endfunction()
function(create_translations_qrc TS_DIR TS_FILES QRC_FILENAME)
find_pkg(Qt5 COMPONENTS LinguistTools REQUIRED)
# Workaround for Qt bug: CMake deletes .ts files upon clean.
# @ref https://bugreports.qt.io/browse/QTBUG-41736
# @ref https://stackoverflow.com/a/24245615/1917249
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM TRUE)
# Update the translation files (e.g. add new strings) and compile them.
qt5_create_translation(QM_FILES ${TS_DIR} ${TS_FILES})
set(QRC_PATH "${CMAKE_CURRENT_BINARY_DIR}/${QRC_FILENAME}")
# Create a resource file (.qrc) containing the name of the compiled translation files (.qm).
# This is required in order to embed those files into the built executable.
# NOTE: We write the files' name instead of their path because they are in the same directory as the resource file.
file(WRITE ${QRC_PATH} "<!DOCTYPE RCC><RCC version=\"1.0\">\n<qresource>\n")
foreach(QM_FILE ${QM_FILES})
get_filename_component(FILENAME ${QM_FILE} NAME)
file(APPEND ${QRC_PATH} "\t<file>${FILENAME}</file>\n")
endforeach()
file(APPEND ${QRC_PATH} "</qresource>\n</RCC>\n")
endfunction()
|