-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
165 lines (147 loc) · 4.67 KB
/
CMakeLists.txt
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
project(KDDeployQt)
# kd_generate_deploy_app_script (
# TARGET <target>
# OUTPUT_SCRIPT <output_script>
# [PROJECT_QML_PATHS <path> ...]
# [QML_IMPORT_PATHS <path> ...]
# [EXTRA_LIBS <path> ...]
# [EXTRA_PLUGINS <path> ...]
# [SYSTEM_LIBS_PATHS <path> ...]
# [WAYLAND]
# [XCB]
# [VERBOSE]
# )
#
# Usage:
#
# include(FetchContent)
# FetchContent_Declare(kddeployqt
# GIT_REPOSITORY https://github.com/KDABLabs/kddeployqt.git
# GIT_TAG main
# )
# FetchContent_MakeAvailable(kddeployqt)
#
# kd_generate_deploy_app_script(
# TARGET appuntitled13
# OUTPUT_SCRIPT deploy_script
# VERBOSE
# WAYLAND
# PROJECT_QML_PATHS
# ${CMAKE_CURRENT_SOURCE_DIR}
# )
function(kd_generate_deploy_app_script )
set(no_value_options
WAYLAND
XCB
VERBOSE
)
set(single_value_options
TARGET
OUTPUT_SCRIPT
)
set(multi_value_options
PROJECT_QML_PATHS
QML_IMPORT_PATHS
EXTRA_LIBS
EXTRA_PLUGINS
SYSTEM_LIBS_PATHS
)
cmake_parse_arguments(PARSE_ARGV 0 arg
"${no_value_options}" "${single_value_options}" "${multi_value_options}"
)
if(arg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unexpected arguments: ${arg_UNPARSED_ARGUMENTS}")
endif()
if(NOT arg_TARGET)
message(FATAL_ERROR "TARGET must be specified")
endif()
if(NOT QT_DEPLOY_PREFIX)
set(QT_DEPLOY_PREFIX \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}\")
endif()
if(QT_DEPLOY_PREFIX STREQUAL \"\")
set(QT_DEPLOY_PREFIX .)
endif()
if (arg_PROJECT_QML_PATHS)
foreach(arg IN LISTS arg_PROJECT_QML_PATHS)
list(APPEND deploy_args "--qml_root_path" "${arg}")
endforeach()
endif()
if (arg_QML_IMPORT_PATHS)
foreach(arg IN LISTS arg_QML_IMPORT_PATHS)
list(APPEND deploy_args "--qml_import_path" "${arg}")
endforeach()
endif()
if (arg_EXTRA_LIBS)
foreach(arg IN LISTS arg_EXTRA_LIBS)
list(APPEND deploy_args "--extra_libs" "${arg}")
endforeach()
endif()
if (arg_EXTRA_PLUGINS)
foreach(arg IN LISTS arg_EXTRA_PLUGINS)
list(APPEND deploy_args "--extra_plugins" "${arg}")
endforeach()
endif()
if (arg_SYSTEM_LIBS_PATHS)
foreach(arg IN LISTS arg_SYSTEM_LIBS_PATHS)
list(APPEND deploy_args "--system_libs_path" "${arg}")
endforeach()
endif()
if (arg_WAYLAND)
list(APPEND deploy_args "--wayland")
endif()
if (arg_XCB)
list(APPEND deploy_args "--xcb")
endif()
set(VERBOSE "set (VERBOSE OFF)")
if (arg_VERBOSE)
list(APPEND deploy_args "--verbose")
set(VERBOSE "set (VERBOSE ON)")
endif()
if (CMAKE_CROSSCOMPILING)
# Qt::qtpaths points to the wrong file when cross-compiling
if (NOT QT_QMAKE_EXECUTABLE)
message(NOTICE "QT_QMAKE_EXECUTABLE not set, trying to guess it from Qt6_DIR: ${Qt6_DIR}")
set(qmake_path ${Qt6_DIR}/../../../bin/qtpaths)
if (NOT EXISTS ${qmake_path})
set(qmake_path ${Qt6_DIR}/../../../bin/qtpaths6)
if (NOT EXISTS ${qmake_path})
set(qmake_path ${Qt6_DIR}/../../../bin/qmake)
if (NOT EXISTS ${qmake_path})
message(FATAL_ERROR "Could not find qtpaths executable")
endif()
endif()
endif()
else()
set(qmake_path ${QT_QMAKE_EXECUTABLE})
endif()
else()
get_target_property(qmake_path Qt::qtpaths IMPORTED_LOCATION)
endif()
list(JOIN deploy_args " " kddeployqt_args)
set(deploy_script ${CMAKE_CURRENT_BINARY_DIR}/${arg_TARGET}_kddeployqt_script.cmake)
set(script_content
"
${VERBOSE}
if (VERBOSE)
message(NOTICE Running ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/kddeployqt.py --output ${QT_DEPLOY_PREFIX} --executable $<TARGET_FILE:${arg_TARGET}> --qmake ${qmake_path} ${kddeployqt_args})
endif()
execute_process(COMMAND
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/kddeployqt.py --output ${QT_DEPLOY_PREFIX} --executable $<TARGET_FILE:${arg_TARGET}> --qmake ${qmake_path} ${kddeployqt_args}
OUTPUT_VARIABLE
output
ERROR_VARIABLE
error)
if (VERBOSE)
message(NOTICE \${output})
endif()
if (error)
message(ERROR \${error})
endif()
if (VERBOSE)
message(NOTICE \t..done)
endif()
")
file(GENERATE OUTPUT ${deploy_script} CONTENT ${script_content})
set(${arg_OUTPUT_SCRIPT} "${deploy_script}" PARENT_SCOPE)
set_property(TARGET ${arg_TARGET} PROPERTY _qt_marked_for_deployment ON)
endfunction()