cmake/appimage: 改进对 Linux 平台 Appimage 的生成模式

This commit is contained in:
zinface 2023-03-29 00:58:00 +08:00
parent a55f53bfd3
commit b929bca982
4 changed files with 106 additions and 61 deletions

View File

@ -24,41 +24,60 @@
# default.desktop default.png
# copy-desktop-appimage
# if ()
set(APPIMAGE_OUTPUT "${CMAKE_BINARY_DIR}/appimage")
set(APPIMAGE_ICON "${APPIMAGE_OUTPUT}/default.png")
set(APPIMAGE_DESTKOP "${APPIMAGE_OUTPUT}/default.desktop")
# set(LINUXDEPLOYQT)
# set(APPIMAGETOOL)
# :
# LINUXDEPLOYQT linuxdeployqt
# APPIMAGETOOL appimagetool
function(execute_linuxdeploy _PATH)
execute_process(COMMAND ${LINUXDEPLOYQT}
WORKING_DIRECTORY "${APPIMAGE_OUTPUT}"
)
endfunction(execute_linuxdeploy _PATH)
option(USE_APPIMAGE_NEW_GLIBC "允许在打包过程中使用较新版本的 glibc 库" ON)
set(APPIMAGE_OUTPUT "${CMAKE_BINARY_DIR}/appimage")
set(APPIMAGE_OUTPUT_ICON "${APPIMAGE_OUTPUT}/default.png")
set(APPIMAGE_OUTPUT_DESTKOP "${APPIMAGE_OUTPUT}/default.desktop")
# 1. Appimage 使
function(add_appimage_icon _icon)
if(CMAKE_VERSION VERSION_LESS 3.21)
message("> cmake version is less than 3.21")
configure_file(${_icon} ${APPIMAGE_OUTPUT_ICON} COPYONLY)
else()
file(MAKE_DIRECTORY ${APPIMAGE_OUTPUT})
file(COPY_FILE ${_icon} ${APPIMAGE_OUTPUT_ICON})
endif(CMAKE_VERSION VERSION_LESS 3.21)
endfunction(add_appimage_icon _icon)
# 2. SparkDesktopMacros.cmake desktop
# 使 desktop.in
function(add_appimage_desktop)
configure_file(cmake/spark-appimage.desktop.in
${APPIMAGE_OUTPUT_DESTKOP} @ONLY)
endfunction(add_appimage_desktop)
function(target_linuxdeploy)
add_custom_target(linuxdeploy pwd
BYPRODUCTS appimage
COMMAND cp ../${PROJECT_NAME} .
COMMAND "${LINUXDEPLOYQT}" ${PROJECT_NAME} -appimage -unsupported-allow-new-glibc -verbose=3 -no-strip|| true
COMMAND cp ../spark-appimage.desktop default.desktop
COMMAND cp ../spark-appimage.png default.png
WORKING_DIRECTORY "${APPIMAGE_OUTPUT}")
if(USE_APPIMAGE_NEW_GLIBC)
message("Use New glibc")
add_custom_target(linuxdeploy pwd
BYPRODUCTS appimage
COMMAND "${LINUXDEPLOYQT}" ${PROJECT_NAME} -appimage -unsupported-allow-new-glibc -verbose=3 -no-strip|| true
WORKING_DIRECTORY "${APPIMAGE_OUTPUT}")
else()
message("Un Use New glibc")
add_custom_target(linuxdeploy pwd
BYPRODUCTS appimage
COMMAND "${LINUXDEPLOYQT}" ${PROJECT_NAME} -appimage -verbose=3 -no-strip|| true
WORKING_DIRECTORY "${APPIMAGE_OUTPUT}")
endif(USE_APPIMAGE_NEW_GLIBC)
endfunction(target_linuxdeploy)
function(target_appimage)
add_custom_target(copy-desktop-appimage
COMMAND cp ../spark-appimage.desktop default.desktop
COMMAND cp ../spark-appimage.png default.png
WORKING_DIRECTORY "${APPIMAGE_OUTPUT}")
add_custom_target(appimage pwd
COMMAND ${APPIMAGETOOL} ${APPIMAGE_OUTPUT}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS copy-desktop-appimage)
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
endfunction(target_appimage)
function(add_appimage)
# 3. Appimage Appimage
function(add_appimage_target _target)
# check linuxdeploy
if(NOT DEFINED LINUXDEPLOYQT)
message("AppImage> Not Found LINUXDEPLOYQT Variable!")
@ -84,40 +103,46 @@ function(add_appimage)
else()
file(REAL_PATH ${APPIMAGETOOL} APPIMAGETOOL_REAL_PATH)
endif(CMAKE_VERSION VERSION_LESS 3.19 AND NOT EXISTS ${LINUXDEPLOYQT})
message("AppImage> Found APPIMAGETOOL Variable: ${LINUXDEPLOYQT_REAL_PATH}")
message("AppImage> Found APPIMAGETOOL Variable: ${APPIMAGETOOL}")
# do add_custome_target
make_directory(${APPIMAGE_OUTPUT})
target_linuxdeploy()
target_appimage()
endfunction(add_appimage)
function(add_appimage_desktop)
configure_file(cmake/spark-appimage.desktop.in
${CMAKE_BINARY_DIR}/spark-appimage.desktop @ONLY)
endfunction(add_appimage_desktop)
#
set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APPIMAGE_OUTPUT}")
function(add_appimage_icon _ICON_PATH)
if(CMAKE_VERSION VERSION_LESS 3.21)
message("> cmake version is less than 3.21")
configure_file(${_ICON_PATH} ${CMAKE_BINARY_DIR}/spark-appimage.png COPYONLY)
else()
file(COPY_FILE ${_ICON_PATH} ${CMAKE_BINARY_DIR}/spark-appimage.png)
endif(CMAKE_VERSION VERSION_LESS 3.21)
endfunction(add_appimage_icon _ICON_PATH)
# 使 -unsupported-allow-new-glibc
# AppRun
if(NOT USE_APPIMAGE_NEW_GLIBC)
set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_NAME "AppRun")
endif(NOT USE_APPIMAGE_NEW_GLIBC)
endfunction(add_appimage_target _target)
# glic>=2.27, -unsupported-allow-new-glibc (意思就是不再低版本发行版使用了)
# -unsupported-bundle-everything
# glic>=2.27, -unsupported-allow-new-glibc 使
# -unsupported-bundle-everything
#
# -unsupported-bundle-everything
# ld-linux.so glibc使
# ld-linux.so glibc
#
# 使
# -unsupported-allow-new-glibc
# linuxdeployqt Ubuntu LTS AppImage
# linuxdeployqt Ubuntu LTS
# AppImage
# ./linuxdeployqt-7-x86_64.AppImage / -appimage -unsupported-allow-new-glibc
# ./linuxdeployqt-7-x86_64.AppImage / -appimage -unsupported-bundle-everything
# linuxdeployqt 使
# ./linuxdeployqt-7-x86_64.AppImage
# / -appimage -unsupported-allow-new-glibc
# ./linuxdeployqt-7-x86_64.AppImage
# / -appimage -unsupported-bundle-everything
@ -126,7 +151,7 @@ endfunction(add_appimage_icon _ICON_PATH)
# include(cmake/SparkAppimageConfig.cmake) # Spark Appimage
# add_appimage_icon(assets/spark.png) # Appimage
# add_appimage_desktop() # Appimage 中的默认desktop(使用来自 Spark 构建的 Desktop 构建中配置的信息(必须要求 spark-desktop))
# add_appimage() # Appimage
# add_appimage_target(${PROJECT_NAME}) # Appimage Appimage
# 2. Makefile Appimage --
# Makefile Appimage (要求提供工具的绝对路径然后可依次进行linuxdeployqt, genrate-appimage)

View File

@ -43,6 +43,11 @@ if(USE_LINUX_APPIMAGE)
include(cmake/SparkAppimageConfig.cmake) # Spark Appimage
add_appimage_icon(assets/spark.png) # Appimage
add_appimage_desktop() # Appimage 中的默认desktop(使用来自 Spark 构建的 Desktop 构建中配置的信息(必须要求 spark-desktop))
add_appimage() # Appimage
add_appimage_target(${PROJECT_NAME}) # Appimage Appimage
# src/themes
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/themes $<TARGET_FILE_DIR:${PROJECT_NAME}>/themes)
endif(USE_LINUX_APPIMAGE)

View File

@ -30,16 +30,26 @@ APPIMAGETOOL := "$(BUNDLE_LINUXDEPLOYQT)/appimagetool-x86_64.AppImage"
# 追加 Appimagetool、linuxdeployqt 构建配置
CMAKE_OPTIONS := -DLINUXDEPLOYQT=$(LINUXDEPLOYQT) -DAPPIMAGETOOL=$(APPIMAGETOOL) $(CMAKE_OPTIONS)
# 执行 Linux DeployQt 并生成可制作 Appimage 的目录结构
linuxdeploy: download-bundle-linuxdeploytools
cmake -B$(builddir) $(CMAKE_OPTIONS) -DUSE_APPIMAGE_NEW_GLIBC=ON
cmake --build $(builddir) --target linuxdeploy
# 执行 Linux DeployQt 并生成可制作 Appimage 的目录结构
# 但生成的应用程序将只使用操作系统中已安装的标准glibc库版本。
linuxdeploy-fast: download-bundle-linuxdeploytools
cmake -B$(builddir) $(CMAKE_OPTIONS) -DUSE_APPIMAGE_NEW_GLIBC=OFF
cmake --build $(builddir) --target linuxdeploy
# 执行 Appimage 目录结构的打包生成
make-appimage:
cmake -B$(builddir) $(CMAKE_OPTIONS)
cmake --build $(builddir) -- linuxdeploy
cmake --build $(builddir) --target appimage
genrate-appimage:
cmake -B$(builddir) $(CMAKE_OPTIONS)
cmake --build $(builddir) -- appimage
package: linux-universal-release linuxdeploy make-appimage
package: linux-universal-release linuxdeploy genrate-appimage
# 不要一开始就使用 - 否则无法生成 AppRun
package-fast: linux-universal-release linuxdeploy-fast make-appimage
linux-build-options:
@echo $(CMAKE_OPTIONS)

View File

@ -1,16 +1,21 @@
option(USE_NOTEPAD_PLUGIN "Notepad-- 插件构建配置" ON)
option(USE_NOTEPAD_PLUGIN "构建 Notepad-- 内部插件" ON)
option(USE_NOTEPAD_PLUGIN_BASE "构建 Notepad-- 内部的插件基础模板" OFF)
if(TRUE)
if(USE_NOTEPAD_PLUGIN)
add_subdirectory(helloworld-next)
#
add_subdirectory(template-plugins/base-plugin)
add_subdirectory(template-plugins/base-widget-plugin)
add_subdirectory(template-plugins/base-widget-ui-plugin)
if(USE_NOTEPAD_PLUGIN_BASE)
#
add_subdirectory(template-plugins/base-plugin)
add_subdirectory(template-plugins/base-widget-plugin)
add_subdirectory(template-plugins/base-widget-ui-plugin)
endif(USE_NOTEPAD_PLUGIN_BASE)
# opencc 项目(基于 git)
add_subdirectory(opencc-demo-plugin)
#
add_subdirectory(versionUpdate)
endif(TRUE)
endif(USE_NOTEPAD_PLUGIN)