utils: rework cmake deploy function.

Use named arguments for function and allow passing additional executable
targets to be copied to the deploy tree.

Update current uses and add ipodpatcher and sansapatcher to Rockbox
Utility deployment.

This is in preparation for moving ipodpatcher / sansapatcher
functionality out of Rockbox Utility so we eventually can avoid
elevation / sudo of the whole installer. Currently this only results in
Rockbox Utility releases shipping ipodpatcher / sansapatcher
executables.

Change-Id: Ibb6601b7e437648135059c580e2ce2532574835a
This commit is contained in:
Dominik Riebeling 2022-03-11 20:37:06 +01:00
parent 7319356dfd
commit 0de2d3a0b6
3 changed files with 124 additions and 52 deletions

View file

@ -39,37 +39,66 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
-DOUTDIR=${CMAKE_BINARY_DIR} -DOUTDIR=${CMAKE_BINARY_DIR}
-DURL=https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage -DURL=https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
-P ${CMAKE_CURRENT_LIST_DIR}/download.cmake -P ${CMAKE_CURRENT_LIST_DIR}/download.cmake
) )
# intermediate target needed to be able to get back to the actual file dependency. # intermediate target needed to be able to get back to the actual file dependency.
add_custom_target(linuxdeploy DEPENDS ${LINUXDEPLOY}) add_custom_target(linuxdeploy DEPENDS ${LINUXDEPLOY})
function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg)
function(deploy_qt)
cmake_parse_arguments(deploy ""
"TARGET;DESKTOPFILE;ICONFILE;QTBINDIR;DMGBUILDCFG"
"EXECUTABLES"
${ARGN})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.") message(WARNING "Deploying a Debug build.")
endif() 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( add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${target}.AppImage OUTPUT ${CMAKE_BINARY_DIR}/${deploy_TARGET}.AppImage
COMMENT "Creating AppImage ${target}" COMMENT "Creating AppImage ${deploy_TARGET}"
COMMAND OUTPUT=${CMAKE_BINARY_DIR}/${target}.AppImage COMMAND OUTPUT=${CMAKE_BINARY_DIR}/${deploy_TARGET}.AppImage
${LINUXDEPLOY} ${LINUXDEPLOY}
--plugin qt --plugin qt
--icon-file=${iconfile} --icon-file=${deploy_ICONFILE}
--desktop-file=${desktopfile} --desktop-file=${deploy_DESKTOPFILE}
--executable=$<TARGET_FILE:${target}> --executable=$<TARGET_FILE:${deploy_TARGET}>
--appdir=AppImage-${target} --appdir=${CMAKE_BINARY_DIR}/AppImage-${deploy_TARGET}
--output=appimage --output=appimage
--verbosity=2 --verbosity=2
DEPENDS ${target} linuxdeploy DEPENDS ${deploy_TARGET} ${_deploy_deps} linuxdeploy
) )
add_custom_target(deploy_${target} add_dependencies(deploy deploy_${deploy_TARGET})
DEPENDS ${CMAKE_BINARY_DIR}/${target}.AppImage)
add_dependencies(deploy deploy_${target})
endfunction() endfunction()
endif() endif()
# MacOS: Build dmg # MacOS: Build dmg
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg) function(deploy_qt)
cmake_parse_arguments(deploy ""
"TARGET;DESKTOPFILE;ICONFILE;QTBINDIR;DMGBUILDCFG"
"EXECUTABLES"
${ARGN})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.") message(WARNING "Deploying a Debug build.")
endif() endif()
@ -77,6 +106,25 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(DMGBUILD_STAMP ${CMAKE_BINARY_DIR}/dmgbuild.stamp) set(DMGBUILD_STAMP ${CMAKE_BINARY_DIR}/dmgbuild.stamp)
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${qtbindir}") 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( add_custom_command(
COMMENT "Setting up dmgbuild virtualenv" COMMENT "Setting up dmgbuild virtualenv"
OUTPUT ${DMGBUILD_STAMP} OUTPUT ${DMGBUILD_STAMP}
@ -86,62 +134,83 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_custom_command( add_custom_command(
# TODO: find a better way to figure the app bundle name. # TODO: find a better way to figure the app bundle name.
OUTPUT ${CMAKE_BINARY_DIR}/${target}.dmg OUTPUT ${CMAKE_BINARY_DIR}/${deploy_TARGET}.dmg
COMMENT "Running macdeployqt and creating dmg ${target}" COMMENT "Running macdeployqt and creating dmg ${deploy_TARGET}"
COMMAND ${MACDEPLOYQT_EXECUTABLE} ${target}.app COMMAND ${MACDEPLOYQT_EXECUTABLE} ${deploy_TARGET}.app
COMMAND ${DMGBUILD} -s ${dmgbuildcfg} COMMAND ${DMGBUILD} -s ${deploy_DMGBUILDCFG}
-Dappbundle=${target}.app -Dappbundle=${deploy_TARGET}.app
${target} ${CMAKE_BINARY_DIR}/${target}.dmg ${deploy_TARGET} ${CMAKE_BINARY_DIR}/${deploy_TARGET}.dmg
DEPENDS ${target} DEPENDS ${deploy_TARGET}
${DMGBUILD_STAMP} ${DMGBUILD_STAMP}
${_deploy_deps}
) )
add_custom_target(deploy_${target} add_custom_target(deploy_${deploy_TARGET}
DEPENDS ${CMAKE_BINARY_DIR}/${target}.dmg) DEPENDS ${CMAKE_BINARY_DIR}/${deploy_TARGET}.dmg)
add_dependencies(deploy deploy_${target}) add_dependencies(deploy deploy_${deploy_TARGET})
endfunction() endfunction()
endif() endif()
# Windows. Copy to dist folder, run windeployqt on the binary, compress to zip. # Windows. Copy to dist folder, run windeployqt on the binary, compress to zip.
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
function(deploy_qt target qtbindir iconfile desktopfile dmgbuildcfg) function(deploy_qt)
cmake_parse_arguments(deploy ""
"TARGET;DESKTOPFILE;ICONFILE;QTBINDIR;DMGBUILDCFG"
"EXECUTABLES"
${ARGN})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(WARNING "Deploying a Debug build.") message(WARNING "Deploying a Debug build.")
endif() endif()
set(_targetfile ${target}.exe) # TODO: Use property. OUTPUT_NAME seems to fail.
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${qtbindir}") find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${qtbindir}")
set(deploydir ${CMAKE_BINARY_DIR}/deploy-${target}) set(deploydir ${CMAKE_BINARY_DIR}/deploy-${deploy_TARGET})
if(WINDEPLOYQT_EXECUTABLE) if(WINDEPLOYQT_EXECUTABLE)
add_custom_command( add_custom_command(
COMMENT "Creating deploy folder and running windeployqt" COMMENT "Creating deploy folder and running windeployqt"
OUTPUT ${deploydir}/${_targetfile} OUTPUT ${deploydir}/${deploy_TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir} COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir} COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${deploy_TARGET}> ${deploydir}
COMMAND ${WINDEPLOYQT_EXECUTABLE} COMMAND ${WINDEPLOYQT_EXECUTABLE}
$<IF:$<CONFIG:Debug>,--debug,--release> # on MinGW, release is mistaken as debug. $<IF:$<CONFIG:Debug>,--debug,--release> # on MinGW, release is mistaken as debug.
${deploydir}/${_targetfile} ${deploydir}/$<TARGET_FILE:${deploy_TARGET}>
DEPENDS ${target} DEPENDS ${deploy_TARGET}
) )
else() else()
add_custom_command( add_custom_command(
COMMENT "Creating deploy folder" COMMENT "Creating deploy folder"
OUTPUT ${deploydir}/${_targetfile} OUTPUT ${deploydir}/${deploy_TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir} COMMAND ${CMAKE_COMMAND} -E make_directory ${deploydir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_targetfile} ${deploydir} COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${deploy_TARGET}> ${deploydir}
DEPENDS ${target} DEPENDS ${deploy_TARGET}
) )
endif() 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( add_custom_command(
COMMENT "Compressing to zip" COMMENT "Compressing to zip"
OUTPUT ${CMAKE_BINARY_DIR}/${target}.zip OUTPUT ${CMAKE_BINARY_DIR}/${deploy_TARGET}.zip
WORKING_DIRECTORY ${deploydir} WORKING_DIRECTORY ${deploydir}
COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${target}.zip COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${deploy_TARGET}.zip
--format=zip . --format=zip .
DEPENDS ${deploydir}/${_targetfile} DEPENDS ${deploydir}/${deploy_TARGET} ${_deploy_deps}
) )
add_custom_target(deploy_${target} add_custom_target(deploy_${deploy_TARGET}
DEPENDS ${CMAKE_BINARY_DIR}/${target}.zip) DEPENDS ${CMAKE_BINARY_DIR}/${deploy_TARGET}.zip)
add_dependencies(deploy deploy_${target}) add_dependencies(deploy deploy_${deploy_TARGET})
endfunction() endfunction()
endif() endif()

View file

@ -137,11 +137,13 @@ set_property(TARGET RockboxUtility PROPERTY AUTOMOC ON)
set_property(TARGET RockboxUtility PROPERTY AUTORCC ON) set_property(TARGET RockboxUtility PROPERTY AUTORCC ON)
set_property(TARGET RockboxUtility PROPERTY AUTOUIC ON) set_property(TARGET RockboxUtility PROPERTY AUTOUIC ON)
deploy_qt(RockboxUtility deploy_qt(TARGET RockboxUtility
${QT_BINDIR} QTBINDIR ${QT_BINDIR}
${CMAKE_CURRENT_LIST_DIR}/../../docs/logo/rockbox-clef.svg ICONFILE ${CMAKE_CURRENT_LIST_DIR}/../../docs/logo/rockbox-clef.svg
${CMAKE_CURRENT_LIST_DIR}/RockboxUtility.desktop DESKTOPFILE ${CMAKE_CURRENT_LIST_DIR}/RockboxUtility.desktop
${CMAKE_CURRENT_LIST_DIR}/dmgbuild.cfg) DMGBUILDCFG ${CMAKE_CURRENT_LIST_DIR}/dmgbuild.cfg
EXECUTABLES ipodpatcher-bin sansapatcher-bin
)
add_library(rbbase add_library(rbbase
${CMAKE_CURRENT_LIST_DIR}/../../tools/iriver.c ${CMAKE_CURRENT_LIST_DIR}/../../tools/iriver.c

View file

@ -142,8 +142,9 @@ if(APPLE)
PROPERTIES MACOSX_PACKAGE_LOCATION Resources) PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
endif() endif()
deploy_qt(RockboxThemeEditor deploy_qt(TARGET RockboxThemeEditor
${QT_BINDIR} QTBINDIR ${QT_BINDIR}
${CMAKE_CURRENT_LIST_DIR}/resources/rbthemeeditor.svg ICONFILE ${CMAKE_CURRENT_LIST_DIR}/resources/rbthemeeditor.svg
${CMAKE_CURRENT_LIST_DIR}/RockboxThemeEditor.desktop DESKTOPFILE ${CMAKE_CURRENT_LIST_DIR}/RockboxThemeEditor.desktop
${CMAKE_CURRENT_LIST_DIR}/dmgbuild.cfg) DMGBUILDCFG ${CMAKE_CURRENT_LIST_DIR}/dmgbuild.cfg)