File: LinuxAppImageBuild.cmake

package info (click to toggle)
blupimania 1.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,204 kB
  • sloc: ansic: 20,082; xml: 24; sh: 6; makefile: 5
file content (154 lines) | stat: -rw-r--r-- 5,192 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

set (APPIMAGE_ASSISTANT_PROGRAM CACHE FILEPATH "AppImageAssistant executable")
set (APPIMAGE_APPRUN_PROGRAM    CACHE FILEPATH "AppImage AppRun executable")

set (APPIMAGE_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deploy/linux-appimage" CACHE PATH "Where to put the AppDir items")
set (APPIMAGE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/package/linux-appimage" CACHE PATH "AppImage output directory")
set (APPIMAGE_FOLLOW_STANDARD OFF CACHE BOOL "Whether generator should follow the spec")

macro (APPIMAGE_PACKAGE TARGET APPIMAGE_TITLE APPIMAGE_DISPLAYNAME CONFIGDIR DATA LIBRARIES LIBRARY_FILES ICON_REF SIGN_APP)
  string (TOLOWER "${APPIMAGE_TITLE}" APPIMAGE_INTERNALNAME)
  string (MAKE_C_IDENTIFIER "${APPIMAGE_INTERNALNAME}" APPIMAGE_INTERNALNAME)

  # Some prerequisites
  # TITLE here is used as the name of the final AppImage as well as the desktop entry's name
  set (APPIMAGE_TITLE "${APPIMAGE_TITLE}")
  set (APPIMAGE_DISPLAYNAME "${APPIMAGE_DISPLAYNAME}")
  set (APPIMAGE_INTERNALNAME "${APPIMAGE_INTERNALNAME}")
  set (APPIMAGE_LIBRARIES)
  set (APPIMAGE_DATA)
  set (APPIMAGE_CONFIG_DIR "${CONFIGDIR}")
  set (APPIMAGE_DEFAULT_ICON_FILE "${APPIMAGE_CONFIG_DIR}/icon.svg")

  # Icon file to be used for the AppImage, only one in this case, preferrably SVG
  set (APPIMAGE_ICON "${APPIMAGE_DEFAULT_ICON_FILE}")
  # We define a way to reference this icon based on where it is located
  set (APPIMAGE_ICON_REF "${ICON_REF}")

  # This helps the window manager to recognize the program even if it has no embedded or loaded icon
  set (APPIMAGE_EXEC_WM ${TARGET})

  # Sets the launch variable in .desktop entry
  set (APPIMAGE_EXEC ${TARGET})

  # This directory is used for temporary files, might get messy
  set ( APPIMAGE_CACHE_DIR "${APPIMAGE_WORKING_DIRECTORY}/${APPIMAGE_INTERNALNAME}_cache")
  # Where the AppDir is generated
  set (APPIMAGE_INTERMEDIATE_DIR "${APPIMAGE_WORKING_DIRECTORY}/${APPIMAGE_INTERNALNAME}")
  set (APPIMAGE_ICON_TARGET "${APPIMAGE_INTERMEDIATE_DIR}/${APPIMAGE_ICON_REF}")
  set (APPIMAGE_BINARY_DIR "${APPIMAGE_INTERMEDIATE_DIR}/usr/bin")
  set (APPIMAGE_ASSET_DIR "${APPIMAGE_INTERMEDIATE_DIR}/usr/share")
  set (APPIMAGE_LIBRARY_DIR "${APPIMAGE_INTERMEDIATE_DIR}/usr/lib")
  set (APPIMAGE_FINAL_NAME "${APPIMAGE_OUTPUT_DIRECTORY}/${APPIMAGE_TITLE}.AppImage")

  list (APPEND APPIMAGE_LIBRARIES ${LIBRARIES})
  list (APPEND APPIMAGE_DATA ${DATA})

  # Remove the previous AppImage file to avoid confusion when generating a new one
  add_custom_command (
    TARGET ${TARGET}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E remove "${APPIMAGE_FINAL_NAME}"
  )

  # Create some necessary directory structure in AppDir
  add_custom_command (
    TARGET ${TARGET}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${APPIMAGE_OUTPUT_DIRECTORY}"
  )
  add_custom_command (
    TARGET ${TARGET}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${APPIMAGE_BINARY_DIR}"
  )
  add_custom_command (
    TARGET ${TARGET}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${APPIMAGE_CACHE_DIR}"
  )
  add_custom_command (
    TARGET ${TARGET}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${APPIMAGE_LIBRARY_DIR}"
  )
  add_custom_command (
    TARGET ${TARGET}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${APPIMAGE_ASSET_DIR}"
  )

  # Copy and configure some data for the AppDir
  configure_file (
    "${APPIMAGE_ICON}"
    "${APPIMAGE_ICON_TARGET}.svg"
    COPYONLY
  )
  configure_file (
    "${APPIMAGE_ICON}"
    "${APPIMAGE_INTERMEDIATE_DIR}/.DirIcon"
    COPYONLY
  )
  configure_file (
    "${APPIMAGE_CONFIG_DIR}/application.desktop.in"
    "${APPIMAGE_INTERMEDIATE_DIR}/${APPIMAGE_INTERNALNAME}.desktop"
    @ONLY
  )
  configure_file (
    "${APPIMAGE_APPRUN_PROGRAM}"
    "${APPIMAGE_INTERMEDIATE_DIR}/AppRun"
    COPYONLY
  )

  # Copy resources into AppDir
  foreach (RESC ${DATA})
    add_custom_command (
      TARGET ${TARGET}
      PRE_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy_directory "${RESC}" "${APPIMAGE_ASSET_DIR}"
    )
  endforeach ()

  # Copy bundled libraries into AppDir
  foreach (LIB ${LIBRARY_FILES})
    add_custom_command (
      TARGET ${TARGET}
      PRE_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy "${LIB}" "${APPIMAGE_LIBRARY_DIR}"
    )
  endforeach ()

  foreach (LIB ${LIBRARIES})
    add_custom_command (
      TARGET ${TARGET}
      PRE_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${LIB}>" "${APPIMAGE_LIBRARY_DIR}"
    )
  endforeach ()

  # Copy the binary to AppDir
  add_custom_command (
    TARGET ${TARGET}
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${TARGET}>" "${APPIMAGE_BINARY_DIR}"
  )

  if (SIGN_APP)
    set (APPIMGKITARGS "-s")
  else ()
    set (APPIMGKITARGS "")
  endif ()

  # Do the actual packaging step with AppImageKit
  add_custom_command (
    TARGET ${TARGET}
    POST_BUILD
    COMMAND "${APPIMAGE_ASSISTANT_PROGRAM}" "${APPIMGKITARGS}" "${APPIMAGE_INTERMEDIATE_DIR}" "${APPIMAGE_FINAL_NAME}"
  )

  install (
    FILES "${APPIMAGE_FINAL_NAME}"
    DESTINATION "${CMAKE_PACKAGED_OUTPUT_PREFIX}/linux-appimage"
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
  )
endmacro ()