blob: 95c384bcef5799948acd9c0ee7a6a8dcdaaec9ff (
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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#
# __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/
#
# All files in this archive are subject to the GNU General Public License.
# See the file COPYING in the source tree root for full license agreement.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# include this file to
# - get a new target "deploy"
# - get a function "deploy_qt()" which will add a deploy target that creates a
# zip / AppImage / dmg and depends on "deploy".
if(NOT have_deploy)
add_custom_target(deploy)
set(have_deploy ON)
endif()
# Linux: Build AppImage
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LINUXDEPLOY ${CMAKE_BINARY_DIR}/linuxdeploy-x86_64.AppImage)
set(LINUXDEPLOYQT ${CMAKE_BINARY_DIR}/linuxdeploy-plugin-qt-x86_64.AppImage)
add_custom_command(
COMMENT "Downloading linuxdeploy"
OUTPUT ${LINUXDEPLOY}
${LINUXDEPLOYQT}
COMMAND ${CMAKE_COMMAND}
-DOUTDIR=${CMAKE_BINARY_DIR}
-DURL=https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
-P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
COMMAND ${CMAKE_COMMAND}
-DOUTDIR=${CMAKE_BINARY_DIR}
-DURL=https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
-P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
)
# intermediate target needed to be able to get back to the actual file dependency.
add_custom_target(linuxdeploy DEPENDS ${LINUXDEPLOY})
function(deploy_qt)
cmake_parse_arguments(deploy ""
"TARGET;DESKTOPFILE;ICONFILE;QTBINDIR;DMGBUILDCFG"
"EXECUTABLES"
${ARGN})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.")
endif()
add_custom_target(deploy_${deploy_TARGET}
DEPENDS ${CMAKE_BINARY_DIR}/${deploy_TARGET}.AppImage)
# need extra rules so we can use generator expressions
# (using get_target_property() doesn't know neede values during generation)
set(_deploy_deps "")
foreach(_deploy_exe_tgt ${deploy_EXECUTABLES})
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${_deploy_exe_tgt}.appimage.stamp
COMMENT "Copying ${_deploy_exe_tgt} to AppImage"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/AppImage-${deploy_TARGET}/usr/bin
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${_deploy_exe_tgt}>
${CMAKE_BINARY_DIR}/AppImage-${deploy_TARGET}/usr/bin
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${_deploy_exe_tgt}.appimage.stamp
DEPENDS ${_deploy_exe_tgt}
)
add_custom_target(deploy_${deploy_TARGET}_${_deploy_exe_tgt}
DEPENDS ${CMAKE_BINARY_DIR}/${_deploy_exe_tgt}.appimage.stamp)
set(_deploy_deps "${_deploy_deps};deploy_${deploy_TARGET}_${_deploy_exe_tgt}")
endforeach()
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${deploy_TARGET}.AppImage
COMMENT "Creating AppImage ${deploy_TARGET}"
COMMAND OUTPUT=${CMAKE_BINARY_DIR}/${deploy_TARGET}.AppImage
${LINUXDEPLOY}
--plugin qt
--icon-file=${deploy_ICONFILE}
--desktop-file=${deploy_DESKTOPFILE}
--executable=$<TARGET_FILE:${deploy_TARGET}>
--appdir=${CMAKE_BINARY_DIR}/AppImage-${deploy_TARGET}
--output=appimage
--verbosity=2
DEPENDS ${deploy_TARGET} ${_deploy_deps} linuxdeploy
)
add_dependencies(deploy deploy_${deploy_TARGET})
endfunction()
endif()
# MacOS: Build dmg
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
function(deploy_qt)
cmake_parse_arguments(deploy ""
"TARGET;DESKTOPFILE;ICONFILE;QTBINDIR;DMGBUILDCFG"
"EXECUTABLES"
${ARGN})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.")
endif()
set(DMGBUILD ${CMAKE_BINARY_DIR}/venv/bin/python3 -m dmgbuild)
set(DMGBUILD_STAMP ${CMAKE_BINARY_DIR}/dmgbuild.stamp)
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${qtbindir}")
# need extra rules so we can use generator expressions
# (using get_target_property() doesn't know neede values during generation)
set(_deploy_deps "")
foreach(_deploy_exe_tgt ${deploy_EXECUTABLES})
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${_deploy_exe_tgt}.app.stamp
COMMENT "Copying ${_deploy_exe_tgt} to App"
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_BUNDLE_CONTENT_DIR:${deploy_TARGET}>/bin
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${_deploy_exe_tgt}>
$<TARGET_BUNDLE_CONTENT_DIR:${deploy_TARGET}>/bin
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${_deploy_exe_tgt}.app.stamp
DEPENDS ${_deploy_exe_tgt}
)
add_custom_target(deploy_${deploy_TARGET}_${_deploy_exe_tgt}
DEPENDS ${CMAKE_BINARY_DIR}/${_deploy_exe_tgt}.app.stamp)
set(_deploy_deps "${_deploy_deps};deploy_${deploy_TARGET}_${_deploy_exe_tgt}")
endforeach()
add_custom_command(
COMMENT "Setting up dmgbuild virtualenv"
OUTPUT ${DMGBUILD_STAMP}
COMMAND python3 -m venv ${CMAKE_BINARY_DIR}/venv
COMMAND ${CMAKE_BINARY_DIR}/venv/bin/python -m pip install -q dmgbuild
)
add_custom_command(
# TODO: find a better way to figure the app bundle name.
OUTPUT ${CMAKE_BINARY_DIR}/${deploy_TARGET}.dmg
COMMENT "Running macdeployqt and creating dmg ${deploy_TARGET}"
COMMAND ${MACDEPLOYQT_EXECUTABLE} ${deploy_TARGET}.app
COMMAND ${DMGBUILD} -s ${deploy_DMGBUILDCFG}
-Dappbundle=${deploy_TARGET}.app
${deploy_TARGET} ${CMAKE_BINARY_DIR}/${deploy_TARGET}.dmg
DEPENDS ${deploy_TARGET}
${DMGBUILD_STAMP}
${_deploy_deps}
)
add_custom_target(deploy_${deploy_TARGET}
DEPENDS ${CMAKE_BINARY_DIR}/${deploy_TARGET}.dmg)
add_dependencies(deploy deploy_${deploy_TARGET})
endfunction()
endif()
# Windows. Copy to dist folder, run windeployqt on the binary, compress to zip.
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
function(deploy_qt)
cmake_parse_arguments(deploy ""
"TARGET;DESKTOPFILE;ICONFILE;QTBINDIR;DMGBUILDCFG"
"EXECUTABLES"
${ARGN})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.")
endif()
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${qtbindir}")
set(deploydir ${CMAKE_BINARY_DIR}/deploy-${deploy_TARGET})
if(WINDEPLOYQT_EXECUTABLE)
add_custom_command(
COMMENT "Creating deploy folder and running windeployqt"
OUTPUT ${deploydir}/${deploy_TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${deploy_TARGET}> ${deploydir}
COMMAND ${WINDEPLOYQT_EXECUTABLE}
$<IF:$<CONFIG:Debug>,--debug,--release> # on MinGW, release is mistaken as debug.
${deploydir}/$<TARGET_FILE:${deploy_TARGET}>
DEPENDS ${deploy_TARGET}
)
else()
add_custom_command(
COMMENT "Creating deploy folder"
OUTPUT ${deploydir}/${deploy_TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${deploy_TARGET}> ${deploydir}
DEPENDS ${deploy_TARGET}
)
endif()
# need extra rules so we can use generator expressions
# (using get_target_property() doesn't know neede values during generation)
set(_deploy_deps "")
foreach(_deploy_exe_tgt ${deploy_EXECUTABLES})
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${_deploy_exe_tgt}.app.stamp
COMMENT "Copying ${_deploy_exe_tgt} to deploy folder"
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${_deploy_exe_tgt}> ${deploydir}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${_deploy_exe_tgt}.app.stamp
DEPENDS ${_deploy_exe_tgt}
)
add_custom_target(deploy_${deploy_TARGET}_${_deploy_exe_tgt}
DEPENDS ${CMAKE_BINARY_DIR}/${_deploy_exe_tgt}.app.stamp)
set(_deploy_deps "${_deploy_deps};deploy_${deploy_TARGET}_${_deploy_exe_tgt}")
endforeach()
add_custom_command(
COMMENT "Compressing to zip"
OUTPUT ${CMAKE_BINARY_DIR}/${deploy_TARGET}.zip
WORKING_DIRECTORY ${deploydir}
COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${deploy_TARGET}.zip
--format=zip .
DEPENDS ${deploydir}/${deploy_TARGET} ${_deploy_deps}
)
add_custom_target(deploy_${deploy_TARGET}
DEPENDS ${CMAKE_BINARY_DIR}/${deploy_TARGET}.zip)
add_dependencies(deploy deploy_${deploy_TARGET})
endfunction()
endif()
|