rockbox/utils/cmake/deploy.cmake
Dominik Riebeling bbd1056afb themeeditor: Fix dmg deploy steps.
- Fix binary name in Info.plist.
- Run dmgbuild as Python module, in some cases it isn't available directly.
- Add missing dmgbuild configuration for themeeditor.

Change-Id: I2db50959b88283f43e2203cf71b130cdb33103dd
2021-12-28 19:53:54 +01:00

147 lines
6.2 KiB
CMake

#
# __________ __ ___.
# 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 target qtbindir iconfile desktopfile dmgbuildcfg)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.")
endif()
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${target}.AppImage
COMMENT "Creating AppImage ${target}"
COMMAND OUTPUT=${CMAKE_BINARY_DIR}/${target}.AppImage
${LINUXDEPLOY}
--plugin qt
--icon-file=${iconfile}
--desktop-file=${desktopfile}
--executable=$<TARGET_FILE:${target}>
--appdir=AppImage-${target}
--output=appimage
--verbosity=2
DEPENDS ${target} linuxdeploy
)
add_custom_target(deploy_${target}
DEPENDS ${CMAKE_BINARY_DIR}/${target}.AppImage)
add_dependencies(deploy deploy_${target})
endfunction()
endif()
# MacOS: Build dmg
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
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}")
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}/${target}.dmg
COMMENT "Running macdeployqt and creating dmg ${target}"
COMMAND ${MACDEPLOYQT_EXECUTABLE} ${target}.app
COMMAND ${DMGBUILD} -s ${dmgbuildcfg}
-Dappbundle=${target}.app
${target} ${CMAKE_BINARY_DIR}/${target}.dmg
DEPENDS ${target}
${DMGBUILD_STAMP}
)
add_custom_target(deploy_${target}
DEPENDS ${CMAKE_BINARY_DIR}/${target}.dmg)
add_dependencies(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 target qtbindir iconfile desktopfile dmgbuildcfg)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.")
endif()
set(_targetfile ${target}.exe) # TODO: Use property. OUTPUT_NAME seems to fail.
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${qtbindir}")
set(deploydir ${CMAKE_BINARY_DIR}/deploy-${target})
if(WINDEPLOYQT_EXECUTABLE)
add_custom_command(
COMMENT "Creating deploy folder and running windeployqt"
OUTPUT ${deploydir}/${_targetfile}
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir}
COMMAND ${WINDEPLOYQT_EXECUTABLE}
$<IF:$<CONFIG:Debug>,--debug,--release> # on MinGW, release is mistaken as debug.
${deploydir}/${_targetfile}
DEPENDS ${target}
)
else()
add_custom_command(
COMMENT "Creating deploy folder"
OUTPUT ${deploydir}/${_targetfile}
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir}
DEPENDS ${target}
)
endif()
add_custom_command(
COMMENT "Compressing to zip"
OUTPUT ${CMAKE_BINARY_DIR}/${target}.zip
WORKING_DIRECTORY ${deploydir}
COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${target}.zip
--format=zip .
DEPENDS ${deploydir}/${_targetfile}
)
add_custom_target(deploy_${target}
DEPENDS ${CMAKE_BINARY_DIR}/${target}.zip)
add_dependencies(deploy deploy_${target})
endfunction()
endif()