-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGateauQtHelpers.cmake
More file actions
86 lines (70 loc) · 2.97 KB
/
Copy pathGateauQtHelpers.cmake
File metadata and controls
86 lines (70 loc) · 2.97 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright Pierre-Antoine LACAZE 2018 - 2020.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)
# This module contains helpers that simplify working with Qt
include_guard()
# Function that queries all qmake properties and exposes them in the parent scope.
function(gateau_read_qt_properties)
# qmake executable is needed to query properties
# if (TARGET Qt5::qmake)
# get_target_property(QMAKE_LOCATION Qt5::qmake IMPORTED_LOCATION)
# else()
# message(WARNING "qmake not found, Qmake properties undefined.")
# endif()
execute_process(
COMMAND Qt5::qmake -query
OUTPUT_VARIABLE QMAKE_PROPERTIES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\n" ";" QMAKE_PROPERTIES "${QMAKE_PROPERTIES}")
foreach(property ${QMAKE_PROPERTIES})
string(REPLACE ":" ";" property ${property})
list(GET property 0 PROPERTY_NAME)
list(GET property 1 PROPERTY_VALUE)
set(${PROPERTY_NAME} "${PROPERTY_VALUE}" PARENT_SCOPE)
endforeach()
endfunction()
# Function that creates translations files and automatically updates them and
# generates their binary representation.
# Do not forget to use the ALL parameter in your add_custom_target() call if you
# use it.
function(gateau_add_qt_translations target)
set(opts_single TS_DIR QM_DIR)
set(opts_multi LOCALES TS_OPTIONS)
cmake_parse_arguments(SAQT "" "${opts_single}" "${opts_multi}" ${ARGN})
foreach(arg TS_DIR QM_DIR LOCALES)
if (NOT SAQT_${arg})
message(FATAL_ERROR "The ${arg} argument of gateau_add_translations is missing")
endif()
endforeach()
gateau_target_file_name(${target} target_file_name)
foreach(locale ${SAQT_LOCALES})
string(TOLOWER "${target_file_name}" basename)
list(APPEND ts_files "${SAQT_TS_DIR}/${basename}_${locale}.ts")
endforeach()
get_target_property(sources ${target} SOURCES)
qt5_create_translation(qm_files ${sources} ${ts_files} OPTIONS ${SAQT_TS_OPTIONS})
get_target_property(target_type ${target} TYPE)
if (target_type STREQUAL EXECUTABLE OR target_type STREQUAL LIBRARY)
target_sources(${target} PRIVATE ${qm_files})
else()
set_property(TARGET ${target} APPEND PROPERTY SOURCES ${qm_files})
endif()
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${SAQT_QM_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy ${qm_files} "${SAQT_QM_DIR}"
)
endfunction()
# Function that installs translations files for target
function(gateau_install_qt_translations target install_trdir)
get_target_property(sources ${target} SOURCES)
foreach(source ${sources})
if (source MATCHES ".+\\.qm$")
list(APPEND qm_files "${source}")
endif()
endforeach()
install(FILES ${qm_files} DESTINATION "${install_trdir}")
endfunction()