|
| 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