Fix memleak
[appimagekit/gsi.git] / src / CMakeLists.txt
blob3f25442812faf5fc381f0e8dba6cc39673edecc2
1 find_package(Sanitizers)
3 if(NOT COMMAND add_sanitizers)
4     message(WARNING "Sanitizers CMake module not found, sanitizer support is not available")
5     # defining a no-op function to avoid CMake errors
6     function(add_sanitizers ...)
7     endfunction()
8 endif()
11 # include XDG basedir library
12 add_subdirectory(xdg-basedir)
15 # allow setting different path for mksquashfs after installation
16 set(AUXILIARY_FILES_DESTINATION "lib/appimagekit" CACHE STRING "Target install directory for mksquashfs")
19 add_library(libappimage SHARED
20     ${PROJECT_SOURCE_DIR}/include/appimage/appimage.h
21     shared.c
22     getsection.c
23     notify.c
24     elf.c
25     appimagetool_shared.c
28 set_target_properties(libappimage PROPERTIES PREFIX "")
29 set_target_properties(libappimage PROPERTIES PUBLIC_HEADER "${PROJECT_SOURCE_DIR}/include/appimage/appimage.h")
31 target_compile_definitions(libappimage
32     PRIVATE -D_FILE_OFFSET_BITS=64
33     PRIVATE -DGIT_COMMIT="${GIT_COMMIT}"
34     PRIVATE -DENABLE_BINRELOC
37 target_include_directories(libappimage
38     PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
39     INTERFACE $<INSTALL_INTERFACE:include/>
42 target_link_libraries(libappimage
43     PRIVATE
44     squashfuse
45     libarchive
46     inotify-tools
47     xz
48     xdg-basedir
49     PUBLIC
50     pthread
51     libglib
52     libgobject
53     libgio
54     libzlib
55     libcairo
59 add_library(libappimage_static STATIC
60     ${PROJECT_SOURCE_DIR}/include/appimage/appimage.h
61     shared.c
62     getsection.c
63     notify.c
64     elf.c
65     appimagetool_shared.c
68 set_target_properties(libappimage_static PROPERTIES PREFIX "")
69 set_target_properties(libappimage_static PROPERTIES LIBRARY_OUTPUT_NAME libappimage)
70 set_target_properties(libappimage_static PROPERTIES PUBLIC_HEADER "${PROJECT_SOURCE_DIR}/include/appimage/appimage.h")
72 target_compile_definitions(libappimage_static
73     PRIVATE -D_FILE_OFFSET_BITS=64
74     PRIVATE -DGIT_COMMIT="${GIT_COMMIT}"
75     PRIVATE -DENABLE_BINRELOC
78 target_include_directories(libappimage_static
79     PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
80     INTERFACE $<INSTALL_INTERFACE:include/>
83 target_link_libraries(libappimage_static
84     PRIVATE
85     squashfuse
86     libarchive
87     inotify-tools
88     xz
89     xdg-basedir
90     PUBLIC
91     pthread
92     libglib
93     libgobject
94     libgio
95     libzlib
96     libcairo
100 include(build-runtime.cmake)
103 add_executable(appimagetool
104     ${PROJECT_SOURCE_DIR}/include/appimage/appimage.h
105     appimagetool.c
106     getsection.c
107     binreloc.c
108     elf.c
109     runtime_embed.o
110     appimagetool_shared.c
113 target_include_directories(appimagetool
114     PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
115     INTERFACE $<INSTALL_INTERFACE:include/>
118 # trick: list libraries on which imported static ones depend on in the PUBLIC section
119 # CMake then adds them after the PRIVATE ones in the linker command
120 target_link_libraries(appimagetool
121     PRIVATE
122     ${CMAKE_DL_LIBS}
123     squashfuse
124     xz
125     xdg-basedir
126     PUBLIC
127     pthread
128     libglib
129     libgobject
130     libzlib
133 target_compile_definitions(appimagetool
134     PRIVATE -D_FILE_OFFSET_BITS=64
135     PRIVATE -DGIT_COMMIT="${GIT_COMMIT}"
136     PRIVATE -DBUILD_NUMBER="${BUILD_NUMBER}"
137     PRIVATE -DBUILD_DATE="${DATE}"
138     PRIVATE -DENABLE_BINRELOC
141 target_include_directories(appimagetool
142     PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
143     INTERFACE $<INSTALL_INTERFACE:include/>
146 if(AUXILIARY_FILES_DESTINATION)
147     message(STATUS "Installing auxiliary files in path: ${AUXILIARY_FILES_DESTINATION}")
148     target_compile_definitions(appimagetool
149         PRIVATE -DAUXILIARY_FILES_DESTINATION="${AUXILIARY_FILES_DESTINATION}"
150     )
151 endif()
153 add_sanitizers(appimagetool)
156 add_executable(AppRun AppRun.c)
158 target_compile_definitions(AppRun
159     PRIVATE -D_FILE_OFFSET_BITS=64
160     PRIVATE -DGIT_COMMIT="${GIT_COMMIT}"
161     PRIVATE -DENABLE_BINRELOC
164 add_sanitizers(AppRun)
167 add_executable(validate validate.c getsection.c)
169 target_link_libraries(validate
170     libglib
171     libopenssl
174 target_include_directories(validate
175     PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
176     INTERFACE $<INSTALL_INTERFACE:include/
180 add_executable(digest digest.c getsection.c)
182 target_link_libraries(digest
183     libopenssl
186 add_sanitizers(digest)
189 # digest_md5 demo application
190 # can be used to verify AppImages' MD5 digest
191 add_executable(digest_md5 EXCLUDE_FROM_ALL digest_md5.c getsection.c appimagetool_shared.c)
193 target_include_directories(digest_md5
194     PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
195     INTERFACE $<INSTALL_INTERFACE:include/>
198 target_link_libraries(digest_md5
199     PRIVATE
200     libglib
204 # install binaries
205 if(AUXILIARY_FILES_DESTINATION)
206     install(
207         PROGRAMS ${mksquashfs_INSTALL_DIR}/mksquashfs ${CMAKE_CURRENT_BINARY_DIR}/runtime
208         DESTINATION ${AUXILIARY_FILES_DESTINATION}
209         COMPONENT applications
210     )
211 else()
212     install(
213         PROGRAMS ${mksquashfs_INSTALL_DIR}/mksquashfs ${CMAKE_CURRENT_BINARY_DIR}/runtime
214         DESTINATION bin
215         COMPONENT applications
216     )
217 endif()
219 install(
220     TARGETS AppRun appimagetool digest validate
221     RUNTIME DESTINATION bin COMPONENT applications
222     LIBRARY DESTINATION lib COMPONENT applications
223     ARCHIVE DESTINATION lib/static COMPONENT applications
224     INCLUDES DESTINATION include COMPONENT applications
228 # install libappimage
229 install(TARGETS libappimage
230     EXPORT AppImageKitTargets
231     LIBRARY DESTINATION lib COMPONENT libappimage
232     ARCHIVE DESTINATION lib/static COMPONENT libappimage
233     PUBLIC_HEADER DESTINATION include/appimage COMPONENT libappimage-dev
236 # Add all targets to the build-tree export set
237 export(
238     TARGETS libappimage
239     FILE "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/AppImageKitTargets.cmake"
242 # Export the package for use from the build-tree
243 # (this registers the build-tree with a global CMake-registry)
244 export(PACKAGE AppImageKit)
246 # Create the AppImageConfig.cmake and AppImageConfigVersion files
247 configure_file(
248     "${PROJECT_SOURCE_DIR}/cmake/AppImageKitConfig.cmake.in"
249     "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/AppImageKitConfig.cmake"
250     @ONLY
252 # ... for both
253 configure_file(
254     "${PROJECT_SOURCE_DIR}/cmake/AppImageKitConfigVersion.cmake.in"
255     "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/AppImageKitConfigVersion.cmake"
256     @ONLY
259 # Install the AppImageConfig.cmake and AppImageConfigVersion.cmake
260 install(FILES
261     "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/AppImageKitConfig.cmake"
262     "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/AppImageKitConfigVersion.cmake"
263     DESTINATION "lib/cmake/AppImageKit"
264     COMPONENT libappimage-dev
267 # Install the export set for use with the install-tree
268 install(EXPORT AppImageKitTargets
269     DESTINATION "lib/cmake/AppImageKit"
270     COMPONENT libappimage-dev