Skip to content

Commit 5bf0a94

Browse files
committed
Begin work on appimage for linux
1 parent 164be6d commit 5bf0a94

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ if(MSVC)
1111
endif()
1212

1313
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE INTERNAL "")
14+
# linux detection
15+
if(UNIX AND NOT APPLE)
16+
set(LINUX TRUE CACHE INTERNAL "")
17+
endif()
1418

1519
file(GLOB source "source/*.cpp" "source/*.hpp" "source/*.h")
1620
add_executable("${PROJECT_NAME}" WIN32 ${source} "source/wxmac.icns" "source/windows.rc")
@@ -50,6 +54,20 @@ if(APPLE)
5054
"
5155
COMPONENT Runtime
5256
)
57+
elseif(LINUX)
58+
INSTALL(CODE
59+
"include(../../appimage.cmake)
60+
make_appimage(
61+
EXE \"${CMAKE_INSTALL_PREFIX}/$<CONFIGURATION>/${PROJECT_NAME}\"
62+
NAME \"${PROJECT_NAME}\"
63+
ICON \"wxlin\"
64+
DIR_ICON \"wxlin.xpm\"
65+
OUTPUT_NAME \"${CMAKE_INSTALL_PREFIX}/$<CONFIGURATION>/${PROJECT_NAME}.AppImage\"
66+
ASSETS \"\"
67+
)
68+
"
69+
COMPONENT Runtime
70+
)
5371
endif()
5472
# windows app
5573
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DPI_AWARE "PerMonitor")

appimage.cmake

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
function(make_appimage)
2+
set(optional)
3+
set(args EXE NAME DIR_ICON ICON OUTPUT_NAME)
4+
set(list_args ASSETS)
5+
cmake_parse_arguments(
6+
PARSE_ARGV 0
7+
ARGS
8+
"${optional}"
9+
"${args}"
10+
"${list_args}"
11+
)
12+
13+
if(${ARGS_UNPARSED_ARGUMENTS})
14+
message(WARNING "Unparsed arguments: ${ARGS_UNPARSED_ARGUMENTS}")
15+
endif()
16+
17+
18+
# download AppImageTool if needed (TODO: non-x86 build machine?)
19+
SET(AIT_PATH "${CMAKE_BINARY_DIR}/AppImageTool.AppImage" CACHE INTERNAL "")
20+
if (NOT EXISTS "${AIT_PATH}")
21+
file(DOWNLOAD https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage "${AIT_PATH}")
22+
execute_process(COMMAND chmod +x ${AIT_PATH})
23+
endif()
24+
25+
# make the AppDir
26+
set(APPDIR "${CMAKE_BINARY_DIR}/AppDir")
27+
file(REMOVE_RECURSE "${APPDIR}") # remove if leftover
28+
file(MAKE_DIRECTORY "${APPDIR}")
29+
30+
# copy executable to appdir
31+
file(COPY "${ARGS_EXE}" DESTINATION "${APPDIR}" FOLLOW_SYMLINK_CHAIN)
32+
get_filename_component(EXE_NAME "${ARGS_EXE}" NAME)
33+
34+
# create the script that will launch the AppImage
35+
file(WRITE "${APPDIR}/AppRun"
36+
"#!/bin/sh
37+
cd \"$(dirname \"$0\")\";
38+
./${EXE_NAME} $@"
39+
)
40+
execute_process(COMMAND chmod +x "${APPDIR}/AppRun")
41+
42+
# copy assets to appdir
43+
file(COPY ${ARGS_ASSETS} DESTINATION "${APPDIR}")
44+
45+
# copy icon thumbnail
46+
file(COPY ${ARGS_DIR_ICON} DESTINATION "${APPDIR}")
47+
get_filename_component(THUMB_NAME "${ARGS_DIR_ICON}" NAME)
48+
file(RENAME "${APPDIR}/${THUMB_NAME}" "${APPDIR}/.DirIcon")
49+
50+
# copy icon highres
51+
file(COPY ${ARGS_ICON} DESTINATION "${APPDIR}")
52+
get_filename_component(ICON_NAME "${ARGS_ICON}" NAME)
53+
get_filename_component(ICON_EXT "${ARGS_ICON}" EXT)
54+
file(RENAME "${APPDIR}/${ICON_NAME}" "${APPDIR}/${ARGS_NAME}${ICON_EXT}")
55+
56+
# Create the .desktop file
57+
file(WRITE "${APPDIR}/${ARGS_NAME}.desktop"
58+
"[Desktop Entry]
59+
Type=Application
60+
Name=${ARGS_NAME}
61+
Icon=${ARGS_NAME}
62+
Categories=X-None;"
63+
)
64+
65+
# Invoke AppImageTool
66+
execute_process(COMMAND ${AIT_PATH} ${APPDIR} ${ARGS_OUTPUT_NAME})
67+
file(REMOVE_RECURSE "${APPDIR}")
68+
69+
endfunction()
70+

0 commit comments

Comments
 (0)