···4848 find_package(Qt6 REQUIRED COMPONENTS Core Core5Compat Widgets Svg Multimedia Network LinguistTools
4949 OPTIONAL_COMPONENTS Test)
5050endif()
5151+get_target_property(_qmake_executable Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
5252+get_filename_component(QT_BINDIR "${_qmake_executable}" DIRECTORY)
5153message("-- Found Qt${QT_VERSION_MAJOR}: ${Qt${QT_VERSION_MAJOR}_DIR}")
52545355# If we're on Linux, try to find the used libs in the system.
···196198set_property(TARGET RockboxUtility PROPERTY AUTOMOC ON)
197199set_property(TARGET RockboxUtility PROPERTY AUTORCC ON)
198200set_property(TARGET RockboxUtility PROPERTY AUTOUIC ON)
201201+202202+include(${CMAKE_CURRENT_LIST_DIR}/cmake/deploy.cmake)
203203+deploy_qt(RockboxUtility
204204+ ${QT_BINDIR}
205205+ ${CMAKE_CURRENT_LIST_DIR}/../docs/logo/rockbox-clef.svg
206206+ ${CMAKE_CURRENT_LIST_DIR}/rbutilqt/RockboxUtility.desktop
207207+ ${CMAKE_CURRENT_LIST_DIR}/rbutilqt/dmgbuild.cfg)
199208200209add_library(rbbase
201210 ${CMAKE_CURRENT_LIST_DIR}/../tools/iriver.c
+141
utils/cmake/deploy.cmake
···11+#
22+# __________ __ ___.
33+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+# \/ \/ \/ \/ \/
88+#
99+# All files in this archive are subject to the GNU General Public License.
1010+# See the file COPYING in the source tree root for full license agreement.
1111+#
1212+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1313+# KIND, either express or implied.
1414+#
1515+1616+# include this file to
1717+# - get a new target "deploy"
1818+# - get a function "deploy_qt()" which will add a deploy target that creates a
1919+# zip / AppImage / dmg and depends on "deploy".
2020+2121+if(NOT have_deploy)
2222+ add_custom_target(deploy)
2323+ set(have_deploy ON)
2424+endif()
2525+2626+# Linux: Build AppImage
2727+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
2828+ set(LINUXDEPLOY ${CMAKE_CURRENT_BINARY_DIR}/linuxdeploy-x86_64.AppImage)
2929+ add_custom_command(
3030+ OUTPUT ${LINUXDEPLOY}
3131+ COMMAND ${CMAKE_COMMAND}
3232+ -DOUTDIR=${CMAKE_CURRENT_BINARY_DIR}
3333+ -DURL=https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
3434+ -P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
3535+ COMMAND ${CMAKE_COMMAND}
3636+ -DOUTDIR=${CMAKE_CURRENT_BINARY_DIR}
3737+ -DURL=https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
3838+ -P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
3939+ )
4040+4141+ function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
4242+ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
4343+ message(WARNING "Deploying a Debug build.")
4444+ endif()
4545+ add_custom_command(
4646+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.AppImage
4747+ COMMENT "Creating AppImage ${target}"
4848+ COMMAND OUTPUT=${CMAKE_CURRENT_BINARY_DIR}/${target}.AppImage
4949+ ${LINUXDEPLOY}
5050+ --icon-file=${iconfile}
5151+ --desktop-file=${desktopfile}
5252+ --executable=$<TARGET_FILE:${target}>
5353+ --appdir=AppImage-${target}
5454+ --output=appimage
5555+ --verbosity=2
5656+ DEPENDS ${target}
5757+ ${LINUXDEPLOY}
5858+ )
5959+ add_custom_target(deploy_${target}
6060+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}.AppImage)
6161+ add_dependencies(deploy deploy_${target})
6262+ endfunction()
6363+endif()
6464+6565+# MacOS: Build dmg
6666+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
6767+ function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
6868+ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
6969+ message(WARNING "Deploying a Debug build.")
7070+ endif()
7171+ set(DMGBUILD ${CMAKE_CURRENT_BINARY_DIR}/venv/bin/dmgbuild)
7272+ find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${qtbindir}")
7373+7474+ add_custom_command(
7575+ COMMENT "Setting up dmgbuild virtualenv"
7676+ OUTPUT ${DMGBUILD}
7777+ COMMAND python3 -m venv ${CMAKE_CURRENT_BINARY_DIR}/venv
7878+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/venv/bin/python -m pip install -q dmgbuild biplist
7979+ )
8080+8181+ add_custom_command(
8282+ # TODO: find a better way to figure the app bundle name.
8383+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dmg
8484+ COMMENT "Running macdeployqt and creating dmg ${target}"
8585+ COMMAND ${MACDEPLOYQT_EXECUTABLE} ${target}.app
8686+ COMMAND ${DMGBUILD} -s ${dmgbuildcfg}
8787+ -Dappbundle=${target}.app
8888+ ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}.dmg
8989+ DEPENDS ${target}
9090+ ${DMGBUILD}
9191+ )
9292+ add_custom_target(deploy_${target}
9393+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}.dmg)
9494+ add_dependencies(deploy deploy_${target})
9595+ endfunction()
9696+endif()
9797+9898+# Windows. Copy to dist folder, run windeployqt on the binary, compress to zip.
9999+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
100100+ function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
101101+ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
102102+ message(WARNING "Deploying a Debug build.")
103103+ endif()
104104+ set(_targetfile ${target}.exe) # TODO: Use property. OUTPUT_NAME seems to fail.
105105+ find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${qtbindir}")
106106+ set(deploydir ${CMAKE_CURRENT_BINARY_DIR}/deploy-${target})
107107+ if(WINDEPLOYQT_EXECUTABLE)
108108+ add_custom_command(
109109+ COMMENT "Creating deploy folder and running windeployqt"
110110+ OUTPUT ${deploydir}/${_targetfile}
111111+ COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
112112+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir}
113113+ COMMAND ${WINDEPLOYQT_EXECUTABLE}
114114+ $<IF:$<CONFIG:Debug>,--debug,--release> # on MinGW, release is mistaken as debug.
115115+ ${deploydir}/${_targetfile}
116116+ DEPENDS ${target}
117117+ )
118118+ else()
119119+ add_custom_command(
120120+ COMMENT "Creating deploy folder"
121121+ OUTPUT ${deploydir}/${_targetfile}
122122+ COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
123123+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir}
124124+ DEPENDS ${target}
125125+ )
126126+ endif()
127127+ add_custom_command(
128128+ COMMENT "Compressing to zip"
129129+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.zip
130130+ WORKING_DIRECTORY ${deploydir}
131131+ COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_CURRENT_BINARY_DIR}/${target}.zip
132132+ --format=zip .
133133+ DEPENDS ${deploydir}/${_targetfile}
134134+ )
135135+136136+ add_custom_target(deploy_${target}
137137+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}.zip)
138138+ add_dependencies(deploy deploy_${target})
139139+ endfunction()
140140+endif()
141141+
+47
utils/cmake/download.cmake
···11+#
22+# __________ __ ___.
33+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+# \/ \/ \/ \/ \/
88+#
99+# All files in this archive are subject to the GNU General Public License.
1010+# See the file COPYING in the source tree root for full license agreement.
1111+#
1212+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1313+# KIND, either express or implied.
1414+#
1515+1616+# This is a separate cmake script, to be invoked as
1717+# cmake -P -DURL=<url-to-download> -DOUTDIR=<output-folder>
1818+# Downloads the file and store it in OUTDIR, using the file basename as output
1919+# filename.
2020+# The downloaded file gets its executable flag set.
2121+2222+function(gettempdir basedir tmpdir)
2323+ # Create a random filename in current directory.
2424+ # Result stored in tmpdir.
2525+ string(RANDOM LENGTH 24 _tmp)
2626+ while(EXISTS "${basedir}/${_tmp}.tmp")
2727+ string(RANDOM LENGTH 24 _tmp)
2828+ endwhile()
2929+ set("${tmpdir}" "${basedir}/${_tmp}.tmp" PARENT_SCOPE)
3030+endfunction()
3131+3232+get_filename_component(fname "${URL}" NAME)
3333+3434+if(EXISTS "${OUTDIR}/${fname}")
3535+ message("-- Found ${fname}")
3636+else()
3737+ message("-- Downloading ${URL} ...")
3838+ gettempdir(${OUTDIR} tmp)
3939+4040+ # cmake CHOWN is 3.19+, thus download to a temporary folder, then copy.
4141+ file(DOWNLOAD "${URL}" "${tmp}/${fname}")
4242+ file(COPY "${tmp}/${fname}" DESTINATION "${OUTDIR}"
4343+ FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
4444+ file(REMOVE_RECURSE "${tmp}")
4545+endif()
4646+4747+