summaryrefslogtreecommitdiff
path: root/utils/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'utils/cmake')
-rw-r--r--utils/cmake/deploy.cmake141
-rw-r--r--utils/cmake/download.cmake47
2 files changed, 188 insertions, 0 deletions
diff --git a/utils/cmake/deploy.cmake b/utils/cmake/deploy.cmake
new file mode 100644
index 0000000000..8b1c837bcd
--- /dev/null
+++ b/utils/cmake/deploy.cmake
@@ -0,0 +1,141 @@
1#
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8#
9# All files in this archive are subject to the GNU General Public License.
10# See the file COPYING in the source tree root for full license agreement.
11#
12# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
13# KIND, either express or implied.
14#
15
16# include this file to
17# - get a new target "deploy"
18# - get a function "deploy_qt()" which will add a deploy target that creates a
19# zip / AppImage / dmg and depends on "deploy".
20
21if(NOT have_deploy)
22 add_custom_target(deploy)
23 set(have_deploy ON)
24endif()
25
26# Linux: Build AppImage
27if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
28 set(LINUXDEPLOY ${CMAKE_CURRENT_BINARY_DIR}/linuxdeploy-x86_64.AppImage)
29 add_custom_command(
30 OUTPUT ${LINUXDEPLOY}
31 COMMAND ${CMAKE_COMMAND}
32 -DOUTDIR=${CMAKE_CURRENT_BINARY_DIR}
33 -DURL=https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
34 -P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
35 COMMAND ${CMAKE_COMMAND}
36 -DOUTDIR=${CMAKE_CURRENT_BINARY_DIR}
37 -DURL=https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
38 -P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
39 )
40
41 function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
42 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
43 message(WARNING "Deploying a Debug build.")
44 endif()
45 add_custom_command(
46 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.AppImage
47 COMMENT "Creating AppImage ${target}"
48 COMMAND OUTPUT=${CMAKE_CURRENT_BINARY_DIR}/${target}.AppImage
49 ${LINUXDEPLOY}
50 --icon-file=${iconfile}
51 --desktop-file=${desktopfile}
52 --executable=$<TARGET_FILE:${target}>
53 --appdir=AppImage-${target}
54 --output=appimage
55 --verbosity=2
56 DEPENDS ${target}
57 ${LINUXDEPLOY}
58 )
59 add_custom_target(deploy_${target}
60 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}.AppImage)
61 add_dependencies(deploy deploy_${target})
62 endfunction()
63endif()
64
65# MacOS: Build dmg
66if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
67 function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
68 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
69 message(WARNING "Deploying a Debug build.")
70 endif()
71 set(DMGBUILD ${CMAKE_CURRENT_BINARY_DIR}/venv/bin/dmgbuild)
72 find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${qtbindir}")
73
74 add_custom_command(
75 COMMENT "Setting up dmgbuild virtualenv"
76 OUTPUT ${DMGBUILD}
77 COMMAND python3 -m venv ${CMAKE_CURRENT_BINARY_DIR}/venv
78 COMMAND ${CMAKE_CURRENT_BINARY_DIR}/venv/bin/python -m pip install -q dmgbuild biplist
79 )
80
81 add_custom_command(
82 # TODO: find a better way to figure the app bundle name.
83 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dmg
84 COMMENT "Running macdeployqt and creating dmg ${target}"
85 COMMAND ${MACDEPLOYQT_EXECUTABLE} ${target}.app
86 COMMAND ${DMGBUILD} -s ${dmgbuildcfg}
87 -Dappbundle=${target}.app
88 ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}.dmg
89 DEPENDS ${target}
90 ${DMGBUILD}
91 )
92 add_custom_target(deploy_${target}
93 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}.dmg)
94 add_dependencies(deploy deploy_${target})
95 endfunction()
96endif()
97
98# Windows. Copy to dist folder, run windeployqt on the binary, compress to zip.
99if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
100 function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
101 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
102 message(WARNING "Deploying a Debug build.")
103 endif()
104 set(_targetfile ${target}.exe) # TODO: Use property. OUTPUT_NAME seems to fail.
105 find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${qtbindir}")
106 set(deploydir ${CMAKE_CURRENT_BINARY_DIR}/deploy-${target})
107 if(WINDEPLOYQT_EXECUTABLE)
108 add_custom_command(
109 COMMENT "Creating deploy folder and running windeployqt"
110 OUTPUT ${deploydir}/${_targetfile}
111 COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
112 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir}
113 COMMAND ${WINDEPLOYQT_EXECUTABLE}
114 $<IF:$<CONFIG:Debug>,--debug,--release> # on MinGW, release is mistaken as debug.
115 ${deploydir}/${_targetfile}
116 DEPENDS ${target}
117 )
118 else()
119 add_custom_command(
120 COMMENT "Creating deploy folder"
121 OUTPUT ${deploydir}/${_targetfile}
122 COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
123 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir}
124 DEPENDS ${target}
125 )
126 endif()
127 add_custom_command(
128 COMMENT "Compressing to zip"
129 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.zip
130 WORKING_DIRECTORY ${deploydir}
131 COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_CURRENT_BINARY_DIR}/${target}.zip
132 --format=zip .
133 DEPENDS ${deploydir}/${_targetfile}
134 )
135
136 add_custom_target(deploy_${target}
137 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}.zip)
138 add_dependencies(deploy deploy_${target})
139 endfunction()
140endif()
141
diff --git a/utils/cmake/download.cmake b/utils/cmake/download.cmake
new file mode 100644
index 0000000000..bd3df4d83d
--- /dev/null
+++ b/utils/cmake/download.cmake
@@ -0,0 +1,47 @@
1#
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8#
9# All files in this archive are subject to the GNU General Public License.
10# See the file COPYING in the source tree root for full license agreement.
11#
12# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
13# KIND, either express or implied.
14#
15
16# This is a separate cmake script, to be invoked as
17# cmake -P -DURL=<url-to-download> -DOUTDIR=<output-folder>
18# Downloads the file and store it in OUTDIR, using the file basename as output
19# filename.
20# The downloaded file gets its executable flag set.
21
22function(gettempdir basedir tmpdir)
23 # Create a random filename in current directory.
24 # Result stored in tmpdir.
25 string(RANDOM LENGTH 24 _tmp)
26 while(EXISTS "${basedir}/${_tmp}.tmp")
27 string(RANDOM LENGTH 24 _tmp)
28 endwhile()
29 set("${tmpdir}" "${basedir}/${_tmp}.tmp" PARENT_SCOPE)
30endfunction()
31
32get_filename_component(fname "${URL}" NAME)
33
34if(EXISTS "${OUTDIR}/${fname}")
35 message("-- Found ${fname}")
36else()
37 message("-- Downloading ${URL} ...")
38 gettempdir(${OUTDIR} tmp)
39
40 # cmake CHOWN is 3.19+, thus download to a temporary folder, then copy.
41 file(DOWNLOAD "${URL}" "${tmp}/${fname}")
42 file(COPY "${tmp}/${fname}" DESTINATION "${OUTDIR}"
43 FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
44 file(REMOVE_RECURSE "${tmp}")
45endif()
46
47