Update appimagetool.c
[appimagekit/gsi.git] / CMakeLists.txt
blob0a2f07310d541c2d205166a64ee354c24666f4bf
1 cmake_minimum_required(VERSION 3.2)
3 include(ExternalProject)
5 find_package(PkgConfig REQUIRED)
7 pkg_check_modules(GLIB REQUIRED glib-2.0)
8 pkg_check_modules(LZMA REQUIRED liblzma)
9 pkg_check_modules(ZLIB REQUIRED zlib)
11 execute_process(
12     COMMAND git describe --tags --always --abbrev=7
13     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
14     OUTPUT_VARIABLE GIT_VERSION
15     OUTPUT_STRIP_TRAILING_WHITESPACE
18 ExternalProject_Add(libxz
19     URL http://tukaani.org/xz/xz-5.2.3.tar.gz
20     URL_MD5 ef68674fb47a8b8e741b34e429d86e9d
21     CONFIGURE_COMMAND ./configure --enable-static --prefix=${CMAKE_INSTALL_PREFIX} --libdir=${CMAKE_INSTALL_PREFIX}/lib
22     BUILD_COMMAND make -j8
23     BUILD_IN_SOURCE 1
24 #    INSTALL_COMMAND make install
25     INSTALL_COMMAND true
27 ExternalProject_Get_Property(libxz SOURCE_DIR)
28 set(xz_SOURCE_DIR ${SOURCE_DIR})
30 add_custom_target(patch_squashfuse ALL
31     COMMAND bash patch.sh
32     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
35 ExternalProject_Add(squashfuse
36     SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/squashfuse
37     CONFIGURE_COMMAND libtoolize --force
38               COMMAND env ACLOCAL_FLAGS="-I /usr/share/aclocal" aclocal
39               COMMAND autoheader
40               COMMAND automake --force-missing --add-missing
41               COMMAND autoreconf -fi || true
42               COMMAND sed -i "/PKG_CHECK_MODULES.*/,/,:./d" configure  # https://github.com/vasi/squashfuse/issues/12
43               COMMAND ./configure --disable-demo --disable-high-level --without-lzo --without-lz4 --prefix=${CMAKE_INSTALL_PREFIX} --libdir=${CMAKE_INSTALL_PREFIX}/lib --with-xz=${SOURCE_DIR}/build
44               COMMAND sed -i "s|XZ_LIBS = -llzma  -L${xz_SOURCE_DIR}/src/liblzma/.libs/|XZ_LIBS = -Bstatic -llzma  -L${xz_SOURCE_DIR}/src/liblzma/.libs/|g" Makefile
45     BUILD_COMMAND make -j8
46     BUILD_IN_SOURCE 1
47     INSTALL_COMMAND true
50 ExternalProject_Add(mksquashfs
51     SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/squashfs-tools/squashfs-tools
52     CONFIGURE_COMMAND true
53     CONFIGURE_COMMAND sed -i "s|CFLAGS += -DXZ_SUPPORT|CFLAGS += -DXZ_SUPPORT -I${xz_SOURCE_DIR}/build/include|g" <SOURCE_DIR>/Makefile
54               COMMAND sed -i "s|LIBS += -llzma|LIBS += -Bstatic -llzma -L${xz_SOURCE_DIR}/build/lib|g" <SOURCE_DIR>/Makefile
55     BUILD_COMMAND make XZ_SUPPORT=1 mksquashfs -j8
56     BUILD_IN_SOURCE 1
57     INSTALL_COMMAND true
60 include_directories(${GLIB_INCLUDE_DIRS})
61 include_directories(${xz_SOURCE_DIR}/)
62 include_directories(${ZLIB_INCLUDE_DIRS})
63 include_directories(squashfuse)
65 add_custom_command(OUTPUT data.o
66     COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/build-runtime.sh
67     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
70 add_executable(appimagetool
71     appimagetool.c
72     getsection.c
73     binreloc.c
74     elf.c
75     data.o
78 add_dependencies(squashfuse patch_squashfuse)
79 add_dependencies(squashfuse libxz)
80 add_dependencies(appimagetool mksquashfs squashfuse)
82 link_directories(${xz_SOURCE_DIR}/src/liblzma/.libs/)
84 find_library(LIBSQUASHFUSE libsquashfuse.a PATHS squashfuse/.libs)
85 find_library(LIBFUSEPRIVATE libfuseprivate.a PATHS squashfuse/.libs)
86 find_library(LIBLZMA libzma.a ${xz_SOURCE_DIR}/src/liblzma/.libs/)
89 #add_library(data STATIC ${CMAKE_CURRENT_BINARY_DIR}/data.o)
90 #set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/data.o
91 #    PROPERTIES EXTERNAL_OBJECT true GENERATED true
94 target_link_libraries(appimagetool
95     ${GLIB_LIBRARIES}
96     ${ZLIB_LIBRARIES}
97     ${LIBFUSEPRIVATE}
98     ${LIBSQUASHFUSE}
100 target_link_libraries(appimagetool dl pthread lzma z)
102 target_compile_definitions(appimagetool
103     PRIVATE -D_FILE_OFFSET_BITS=64
104     PRIVATE -DVERSION_NUMBER="${GIT_VERSION}"
105     PRIVATE -DENABLE_BINRELOC
108 enable_testing()
109 add_test(test_appimagetool
110     bash ${CMAKE_CURRENT_SOURCE_DIR}/test-appimagetool.sh ${CMAKE_CURRENT_BINARY_DIR}/appimagetool