Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
413d38e
Update to version 3.0.0
Jun 17, 2025
aaf7ac3
Authors
Jun 17, 2025
4e7f20f
Require C++14 to fix build errors (tested on Ubuntu 24 + GCC 13 x86) …
Mq-b Jul 7, 2025
087c681
Update README.md: Replace C++11 to C++14
Lecrapouille Jul 7, 2025
d779ccd
CI: add Ubuntu + CMake
Jul 7, 2025
5f482e3
Disable temporary a test for Windows #30
Jul 7, 2025
237c8f2
Include zipper from CMake #31
Jul 7, 2025
7afe417
Fix English
Jul 7, 2025
7fa84fa
Update CI: CMakeHelloWorld #31
Lecrapouille Jul 7, 2025
8d6da92
Update to version 3.0.1
Lecrapouille Jul 8, 2025
6c423cc
Update Makefile #33
Lecrapouille Jul 13, 2025
07b4903
Update licenses #38
Lecrapouille Jul 18, 2025
3938d0a
Update minizip
Lecrapouille Jul 18, 2025
f859409
Add support for using packaged GTest (#37)
LecrisUT Jul 18, 2025
f5f85e1
Update minizip #35
Lecrapouille Jul 18, 2025
157bb70
CMake: fetch minizip and zlib #34
Lecrapouille Jul 18, 2025
0f0bce3
Missing update version in CMake #36
Lecrapouille Jul 18, 2025
e1f9805
Set tags to third parties
Lecrapouille Jul 18, 2025
34323b0
Misc changes Makefile
Lecrapouille Jul 18, 2025
11b0a2d
Export build-tree targets
LecrisUT Jul 18, 2025
2821036
Simplify the Config.cmake export
LecrisUT Jul 18, 2025
17ebaec
Move and rewrite third-party dependencies
LecrisUT Jul 18, 2025
1bffa4f
Use namepsaced options
LecrisUT Jul 18, 2025
e3c0289
Use a more modern design for the project
LecrisUT Jul 18, 2025
247b888
Need to bump minimum CMake for CMP0079
LecrisUT Jul 18, 2025
05a443c
Fix minizip include path
LecrisUT Jul 18, 2025
db578ad
Merge branch 'master' into cmake/modern
Lecrapouille Jul 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 48 additions & 111 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,107 +13,46 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

include(GNUInstallDirs)
include(FetchContent)
include(CMakePackageConfigHelpers)

##############################################################################
# Build options for enabling/disabling demos and tests
# Build options
##############################################################################
option(ZIPPER_BUILD_DEMOS "Build the demo applications" OFF)
option(ZIPPER_BUILD_TESTS "Build the test applications" OFF)
option(ZIPPER_SHARED_LIB "Build zipper as a shared library" OFF)
option(ZIPPER_USE_LOCAL_SUBMODULES "Use local submodules instead of FetchContent" OFF)

##############################################################################
# External dependencies
# Third-party dependencies
##############################################################################
# Force static libraries for dependencies
set(BUILD_SHARED_LIBS OFF)

# Configure zlib-ng
set(ZLIB_COMPAT ON CACHE BOOL "Enable zlib-ng compatibility")
set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Disable zlib-ng tests")
set(SKIP_INSTALL_ALL ON CACHE BOOL "Skip installation of zlib-ng")
add_subdirectory(external/zlib-ng)

# Configure minizip with AES encryption support
# Define the CMP0077 policy to avoid warning with option() in external/minizip
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
option(USE_AES "Enable AES encryption" ON)
add_subdirectory(external/minizip)
target_include_directories(minizip PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/external/zlib-ng>
)
add_subdirectory(external)

##############################################################################
# Main library targets (static and shared)
# Main library targets
##############################################################################
# Common source files definition
set(ZIPPER_SOURCES
src/utils/Path.cpp
src/utils/Timestamp.cpp
src/utils/glob.cpp
src/Zipper.cpp
src/Unzipper.cpp
)

# Compile as static or as shared library
if(ZIPPER_SHARED_LIB)
add_library(zipper SHARED ${ZIPPER_SOURCES})
else()
add_library(zipper STATIC ${ZIPPER_SOURCES})
endif()

# Add platform-specific dependencies
if(WIN32)
target_sources(zipper PRIVATE
src/utils/dirent.c
)

target_compile_definitions(zipper PRIVATE
# Prevent Windows' min/max macros from conflicting with std::min/max
NOMINMAX=ON
)
endif()

# Export symbols for Windows and DLLs.
if(WIN32 AND ZIPPER_SHARED_LIB)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

# Include and setup for exporting symbols
include(GenerateExportHeader)

# Generate export header for shared library symbols
generate_export_header(zipper
BASE_NAME zipper
EXPORT_MACRO_NAME ZIPPER_EXPORT
EXPORT_FILE_NAME zipper_export.h
)
target_compile_definitions(zipper PRIVATE zipper_EXPORTS)
target_compile_definitions(zipper PUBLIC ZIPPER_EXPORT_DEFINED)
set(BUILD_SHARED_LIBS ON)
else()
# For all other cases, undefine the macro
target_compile_options(zipper PRIVATE -UZIPPER_EXPORT_DEFINED)
set(BUILD_SHARED_LIBS OFF)
endif()

# Include directories configuration
target_include_directories(zipper PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
src
external/minizip
)
add_library(zipper)
add_library(zipper::zipper ALIAS zipper)

# Public include directories
target_include_directories(zipper PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
set_target_properties(zipper PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

# Library dependencies
target_link_libraries(zipper PRIVATE
minizip
zlibstatic
)
# Main implementation in here
add_subdirectory(src)
add_subdirectory(include)

##############################################################################
# Build demos if CMake option is enabled
Expand All @@ -134,8 +73,8 @@ endif()
##############################################################################
if(ZIPPER_BUILD_TESTS)
message(STATUS "Building test applications")
add_subdirectory(tests)
enable_testing()
add_subdirectory(tests)
endif()

##############################################################################
Expand All @@ -146,45 +85,43 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/zipper.pc
@ONLY
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zipper.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

##############################################################################
# Installation rules
# CMake Package Configuration (for find_package support)
##############################################################################
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# Configure version information for shared libraries
if(ZIPPER_SHARED_LIB)
set_target_properties(zipper PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
endif()

install(TARGETS zipper
EXPORT zipperTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_SKIP
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# Export the installed targets
install(EXPORT zipperTargets
FILE zipperTargets.cmake
NAMESPACE zipper::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zipper
)
# Export for build-tree targets also
export(EXPORT zipperTargets
FILE zipperTargets.cmake
NAMESPACE zipper::
)

# For shared libraries, add NAMELINK installation
if(ZIPPER_SHARED_LIB)
install(TARGETS zipper
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
)
endif()
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/zipperConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/zipperConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zipper
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/zipperConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)

install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(WIN32 AND ZIPPER_SHARED_LIB)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zipper_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zipper.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
# Install the configuration files
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/zipperConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/zipperConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zipper
)

##############################################################################
Expand Down
67 changes: 67 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Support for FetchContent/find_package integration using CMake 3.24
set(fetch_content_extra_args)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
list(APPEND fetch_content_extra_args
FIND_PACKAGE_ARGS CONFIG
)
endif()

# Declare the dependencies
# Some default options are overwritten to better support bundled buildings
option(WITH_GTEST "zipper: Override" OFF)
option(WITH_FUZZERS "zipper: Override" OFF)
option(WITH_BENCHMARKS "zipper: Override" OFF)
# TODO: Do without the ZLIB_COMPAT
option(ZLIB_COMPAT "zipper: Override" ON)
option(ZLIB_ENABLE_TESTS "zipper: Override" OFF)
option(SKIP_INSTALL_ALL "zipper: Override" ON)
FetchContent_Declare(zlib-ng
GIT_REPOSITORY https://github.com/zlib-ng/zlib-ng.git
GIT_TAG 2.2.4
${fetch_content_extra_args}
)

option(USE_AES "zipper: Override" ON)
FetchContent_Declare(minizip
GIT_REPOSITORY https://github.com/Lecrapouille/minizip.git
GIT_TAG v1.2
${fetch_content_extra_args}
)

# If we are asked to use submodules, override the paths to point to
# the submodule destination
if(ZIPPER_USE_LOCAL_SUBMODULES)
set(FETCHCONTENT_SOURCE_DIR_MINIZIP ${CMAKE_CURRENT_SOURCE_DIR}/minizip CACHE PATH
"zipper: Override (USE_LOCAL_SUBMODULES)"
)
set(FETCHCONTENT_SOURCE_DIR_ZLIB-NG ${CMAKE_CURRENT_SOURCE_DIR}/zlib-ng CACHE PATH
"zipper: Override (USE_LOCAL_SUBMODULES)"
)
endif()

# Make all dependencies build as static libraries
# TODO: This can be scoped for each dependency, but requires
# reorganization of the folder structure or CMake 3.25
set(BUILD_SHARED_LIBS OFF)

# Do the actual add_subdirectory/find_package calls
FetchContent_MakeAvailable(minizip zlib-ng)

# Additional compatibility support because the dependencies do not properly support
# FetchContent (gated by <PROJECT_NAME>_SOURCE_DIR) or find_package is not compatible
if(minizip_SOURCE_DIR)
# Ugly hack to make sure #include <minizip/*> works
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/include)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
${minizip_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include/minizip
)
target_include_directories(minizip PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
)
add_library(MINIZIP::minizip ALIAS minizip)
endif()

if(zlib-ng_SOURCE_DIR)
# TODO: after ZLIB_COMPAT is off, switch to zlib-ng
add_library(ZLIB::zlib ALIAS zlib)
endif()
1 change: 1 addition & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install(DIRECTORY Zipper/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Zipper)
54 changes: 54 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
target_sources(zipper PRIVATE
Zipper.cpp
Unzipper.cpp
)
add_subdirectory(utils)

# Export symbols for Windows and DLLs.
if(WIN32 AND ZIPPER_SHARED_LIB)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

# Include and setup for exporting symbols
include(GenerateExportHeader)

# Generate export header for shared library symbols
generate_export_header(zipper
BASE_NAME zipper
EXPORT_MACRO_NAME ZIPPER_EXPORT
EXPORT_FILE_NAME zipper_export.h
)
target_compile_definitions(zipper PRIVATE zipper_EXPORTS)
target_compile_definitions(zipper PUBLIC ZIPPER_EXPORT_DEFINED)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zipper_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
# For all other cases, undefine the macro
target_compile_options(zipper PRIVATE -UZIPPER_EXPORT_DEFINED)
endif()

# Include directories configuration
target_include_directories(zipper PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

# Public include directories
target_include_directories(zipper PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
# for the zipper_export.h file. Is it needed though?
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Library dependencies
target_link_libraries(zipper PRIVATE
MINIZIP::minizip
# TODO: Use the non-compat version
ZLIB::zlib
)

install(TARGETS zipper
EXPORT zipperTargets
)
8 changes: 4 additions & 4 deletions src/Unzipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "utils/Path.hpp"
#include "utils/glob.hpp"

#include "external/minizip/ioapi_mem.h"
#include "external/minizip/minishared.h"
#include "external/minizip/unzip.h"
#include "external/minizip/zip.h"
#include <minizip/ioapi_mem.h>
#include <minizip/minishared.h>
#include <minizip/unzip.h>
#include <minizip/zip.h>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, potatoes. Can you fix the Makefile part to account for this change? This change would be needed to support using system packages.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an issue for me with Makefile: it's just fixing a -I piece of cake. I find sad that the hard part is always coming from CMake. On the original project 99% of issues come from CMake that is why I used my Makefile system. I'm not even able to compile with your changes. The nightmare is coming back again ;(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- The following OPTIONAL packages have not been found:

  • minizip
  • zlib-ng

-- Configuring done (10.5s)
CMake Error: install(EXPORT "zipperTargets" ...) includes target "zipper" which requires target "zlib" that is not in any export set.
CMake Error in CMakeLists.txt:
export called with target "zipper" which requires target "minizip" that is
not in any export set.

CMake Error in CMakeLists.txt:
export called with target "zipper" which requires target "zlib" that is not
in any export set.

-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are not optional packages. They either comes from initially with make download-external-libs then I added git submodules for Red-Hat

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- Configuring done (10.5s)
CMake Error: install(EXPORT "zipperTargets" ...) includes target "zipper" which requires target "zlib" that is not in any export set.

This is a complex issue about static libraries requiring to have all dependencies installed. Iirc, that is an existing issue.

I can look into that afterwards, but for now, try building with -DZIPPER_SHARED_LIBS=ON

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LecrisUT why not letting people doing git clone ... --recurse then either our CMakeLists includes directly the CMake inside the external/minizip/CMakeLists.txt our we compile the C++ files directly ? I can modify headers for you now

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LecrisUT I have commited the includes. I'm not sure to switch "" to <> because, if I remember well the compiler will search for OS files first

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to switch "" to <> because, if I remember well the compiler will search for OS files first

Yes, but that is desired. You are signalling that this is a third-party library. The -I flags will make sure that the system dependency is picked up.

@LecrisUT why not letting people doing git clone ... --recurse then either our CMakeLists includes directly the CMake inside the external/minizip/CMakeLists.txt our we compile the C++ files directly ? I can modify headers for you now

The reason for this change is to make way to allow building against a system minizip which exports it as #include <minizip/*>. This will make it easier to pull in minizip-ng-compat-devel make it compatible with that, and move the bundled minizip to the upstream version.


#include <array>
#include <cstring>
Expand Down
4 changes: 2 additions & 2 deletions src/Zipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "utils/Path.hpp"
#include "utils/Timestamp.hpp"

#include "external/minizip/ioapi_mem.h"
#include "external/minizip/zip.h"
#include <minizip/ioapi_mem.h>
#include <minizip/zip.h>

#include <fstream>
#include <stdexcept>
Expand Down
16 changes: 16 additions & 0 deletions src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
target_sources(zipper PRIVATE
Path.cpp
Timestamp.cpp
glob.cpp
)

# Add platform-specific dependencies
if(WIN32)
target_sources(zipper PRIVATE
dirent.c
)
target_compile_definitions(zipper PRIVATE
# Prevent Windows' min/max macros from conflicting with std::min/max
NOMINMAX=ON
)
endif()
Loading
Loading