Skip to content

Commit 0880085

Browse files
authored
Merge pull request #1057 from Mailaender/system-mksquashfs
Use mksquashfs instead of downloading during the build
2 parents bc5a03a + 884e2ee commit 0880085

File tree

2 files changed

+57
-50
lines changed

2 files changed

+57
-50
lines changed

cmake/dependencies.cmake

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,54 @@ set(CFLAGS ${DEPENDENCIES_CFLAGS})
3030
set(CPPFLAGS ${DEPENDENCIES_CPPFLAGS})
3131
set(LDFLAGS ${DEPENDENCIES_LDFLAGS})
3232

33+
set(USE_SYSTEM_MKSQUASHFS OFF CACHE BOOL "Use system mksquashfs instead of downloading and building our own. Warning: you need a recent version otherwise it might not work as intended.")
3334

34-
# TODO: allow using system wide mksquashfs
35-
set(mksquashfs_cflags "-DXZ_SUPPORT ${CFLAGS}")
35+
if(NOT USE_SYSTEM_MKSQUASHFS)
36+
set(mksquashfs_cflags "-DXZ_SUPPORT ${CFLAGS}")
3637

37-
if(NOT xz_LIBRARIES OR xz_LIBRARIES STREQUAL "")
38-
message(FATAL_ERROR "xz_LIBRARIES not set")
39-
elseif(xz_LIBRARIES MATCHES "\\.a$")
40-
set(mksquashfs_ldflags "${xz_LIBRARIES}")
41-
else()
42-
set(mksquashfs_ldflags "-l${xz_LIBRARIES}")
43-
endif()
38+
if(NOT xz_LIBRARIES OR xz_LIBRARIES STREQUAL "")
39+
message(FATAL_ERROR "xz_LIBRARIES not set")
40+
elseif(xz_LIBRARIES MATCHES "\\.a$")
41+
set(mksquashfs_ldflags "${xz_LIBRARIES}")
42+
else()
43+
set(mksquashfs_ldflags "-l${xz_LIBRARIES}")
44+
endif()
4445

45-
if(xz_INCLUDE_DIRS)
46-
set(mksquashfs_cflags "${mksquashfs_cflags} -I${xz_INCLUDE_DIRS}")
47-
endif()
48-
if(xz_LIBRARY_DIRS)
49-
set(mksquashfs_ldflags "${mksquashfs_ldflags} -L${xz_LIBRARY_DIRS}")
50-
endif()
46+
if(xz_INCLUDE_DIRS)
47+
set(mksquashfs_cflags "${mksquashfs_cflags} -I${xz_INCLUDE_DIRS}")
48+
endif()
49+
if(xz_LIBRARY_DIRS)
50+
set(mksquashfs_ldflags "${mksquashfs_ldflags} -L${xz_LIBRARY_DIRS}")
51+
endif()
5152

52-
ExternalProject_Add(mksquashfs
53-
GIT_REPOSITORY https://github.com/plougher/squashfs-tools/
54-
GIT_TAG 4.4
55-
UPDATE_COMMAND "" # Make sure CMake won't try to fetch updates unnecessarily and hence rebuild the dependency every time
56-
CONFIGURE_COMMAND ${SED} -i "s|CFLAGS += -DXZ_SUPPORT|CFLAGS += ${mksquashfs_cflags}|g" <SOURCE_DIR>/squashfs-tools/Makefile
57-
COMMAND ${SED} -i "s|LIBS += -llzma|LIBS += -Bstatic ${mksquashfs_ldflags}|g" <SOURCE_DIR>/squashfs-tools/Makefile
58-
COMMAND ${SED} -i "s|install: mksquashfs unsquashfs|install: mksquashfs|g" squashfs-tools/Makefile
59-
COMMAND ${SED} -i "/cp unsquashfs/d" squashfs-tools/Makefile
60-
BUILD_COMMAND env CC=${CC} CXX=${CXX} LDFLAGS=${LDFLAGS} ${MAKE} -C squashfs-tools/ XZ_SUPPORT=1 mksquashfs
61-
# ${MAKE} install unfortunately expects unsquashfs to be built as well, hence can't install the binary
62-
# therefore using built file in SOURCE_DIR
63-
# TODO: implement building out of source
64-
BUILD_IN_SOURCE ON
65-
INSTALL_COMMAND ${MAKE} -C squashfs-tools/ install INSTALL_DIR=<INSTALL_DIR>
66-
)
67-
68-
ExternalProject_Get_Property(mksquashfs INSTALL_DIR)
69-
set(mksquashfs_INSTALL_DIR "${INSTALL_DIR}")
70-
mark_as_advanced(mksquashfs_INSTALL_DIR)
71-
72-
# for later use when packaging as an AppImage
73-
set(mksquashfs_BINARY "${mksquashfs_INSTALL_DIR}/mksquashfs")
74-
mark_as_advanced(mksquashfs_BINARY)
53+
ExternalProject_Add(mksquashfs
54+
GIT_REPOSITORY https://github.com/plougher/squashfs-tools/
55+
GIT_TAG 4.4
56+
UPDATE_COMMAND "" # Make sure CMake won't try to fetch updates unnecessarily and hence rebuild the dependency every time
57+
CONFIGURE_COMMAND ${SED} -i "s|CFLAGS += -DXZ_SUPPORT|CFLAGS += ${mksquashfs_cflags}|g" <SOURCE_DIR>/squashfs-tools/Makefile
58+
COMMAND ${SED} -i "s|LIBS += -llzma|LIBS += -Bstatic ${mksquashfs_ldflags}|g" <SOURCE_DIR>/squashfs-tools/Makefile
59+
COMMAND ${SED} -i "s|install: mksquashfs unsquashfs|install: mksquashfs|g" squashfs-tools/Makefile
60+
COMMAND ${SED} -i "/cp unsquashfs/d" squashfs-tools/Makefile
61+
BUILD_COMMAND env CC=${CC} CXX=${CXX} LDFLAGS=${LDFLAGS} ${MAKE} -C squashfs-tools/ XZ_SUPPORT=1 mksquashfs
62+
# ${MAKE} install unfortunately expects unsquashfs to be built as well, hence can't install the binary
63+
# therefore using built file in SOURCE_DIR
64+
# TODO: implement building out of source
65+
BUILD_IN_SOURCE ON
66+
INSTALL_COMMAND ${MAKE} -C squashfs-tools/ install INSTALL_DIR=<INSTALL_DIR>
67+
)
68+
69+
ExternalProject_Get_Property(mksquashfs INSTALL_DIR)
70+
set(mksquashfs_INSTALL_DIR "${INSTALL_DIR}")
71+
mark_as_advanced(mksquashfs_INSTALL_DIR)
72+
73+
# for later use when packaging as an AppImage
74+
set(mksquashfs_BINARY "${mksquashfs_INSTALL_DIR}/mksquashfs")
75+
mark_as_advanced(mksquashfs_BINARY)
76+
else()
77+
message(STATUS "Using system mksquashfs")
7578

79+
set(mksquashfs_BINARY "mksquashfs")
80+
endif()
7681

7782
#### build dependency configuration ####
7883

src/CMakeLists.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,20 @@ target_link_libraries(digest_md5
117117

118118

119119
# install binaries
120-
if(AUXILIARY_FILES_DESTINATION)
121-
install(
122-
PROGRAMS ${mksquashfs_INSTALL_DIR}/mksquashfs ${CMAKE_CURRENT_BINARY_DIR}/runtime
123-
DESTINATION ${AUXILIARY_FILES_DESTINATION}
124-
COMPONENT applications
125-
)
126-
else()
127-
install(
128-
PROGRAMS ${mksquashfs_INSTALL_DIR}/mksquashfs ${CMAKE_CURRENT_BINARY_DIR}/runtime
129-
DESTINATION bin
130-
COMPONENT applications
131-
)
120+
if(NOT USE_SYSTEM_MKSQUASHFS)
121+
if(AUXILIARY_FILES_DESTINATION)
122+
install(
123+
PROGRAMS ${mksquashfs_INSTALL_DIR}/mksquashfs ${CMAKE_CURRENT_BINARY_DIR}/runtime
124+
DESTINATION ${AUXILIARY_FILES_DESTINATION}
125+
COMPONENT applications
126+
)
127+
else()
128+
install(
129+
PROGRAMS ${mksquashfs_INSTALL_DIR}/mksquashfs ${CMAKE_CURRENT_BINARY_DIR}/runtime
130+
DESTINATION bin
131+
COMPONENT applications
132+
)
133+
endif()
132134
endif()
133135

134136
set(optional_targets "")

0 commit comments

Comments
 (0)