| 1 |
# minizip-ng project |
| 2 |
# |
| 3 |
# Copyright (C) Nathan Moinvaziri |
| 4 |
# https://github.com/zlib-ng/minizip-ng |
| 5 |
# Copyright (C) 2016 Matthias Schmieder |
| 6 |
# [email protected] |
| 7 |
|
| 8 |
cmake_minimum_required(VERSION 3.13) |
| 9 |
|
| 10 |
# Library version |
| 11 |
set(VERSION "4.0.10") |
| 12 |
# API version |
| 13 |
set(SOVERSION "4") |
| 14 |
|
| 15 |
project(minizip-ng |
| 16 |
VERSION ${VERSION} |
| 17 |
LANGUAGES C |
| 18 |
DESCRIPTION "Zip manipulation library" |
| 19 |
HOMEPAGE_URL https://github.com/zlib-ng/minizip-ng/) |
| 20 |
|
| 21 |
include(CMakeDependentOption) |
| 22 |
include(CheckLibraryExists) |
| 23 |
include(CheckSymbolExists) |
| 24 |
include(CheckFunctionExists) |
| 25 |
include(CheckIncludeFile) |
| 26 |
include(CheckIncludeFiles) |
| 27 |
include(CheckCSourceCompiles) |
| 28 |
include(CheckTypeSize) |
| 29 |
include(GNUInstallDirs) |
| 30 |
include(FeatureSummary) |
| 31 |
|
| 32 |
include(cmake/detect-sanitizer.cmake) |
| 33 |
|
| 34 |
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") |
| 35 |
|
| 36 |
message(STATUS "Using CMake version ${CMAKE_VERSION}") |
| 37 |
|
| 38 |
# Compatibility options |
| 39 |
option(MZ_COMPAT "Enables compatibility layer" ON) |
| 40 |
# Compression library options |
| 41 |
option(MZ_ZLIB "Enables ZLIB compression" ON) |
| 42 |
option(MZ_BZIP2 "Enables BZIP2 compression" ON) |
| 43 |
option(MZ_LZMA "Enables LZMA & XZ compression" ON) |
| 44 |
option(MZ_ZSTD "Enables ZSTD compression" ON) |
| 45 |
cmake_dependent_option(MZ_LIBCOMP "Enables Apple compression" ON "APPLE" OFF) |
| 46 |
option(MZ_FETCH_LIBS "Enables fetching third-party libraries if not found" ${WIN32}) |
| 47 |
option(MZ_FORCE_FETCH_LIBS "Enables fetching third-party libraries always" OFF) |
| 48 |
# Encryption support options |
| 49 |
option(MZ_PKCRYPT "Enables PKWARE traditional encryption" ON) |
| 50 |
option(MZ_WZAES "Enables WinZIP AES encryption" ON) |
| 51 |
cmake_dependent_option(MZ_OPENSSL "Enables OpenSSL for encryption" ON "UNIX" OFF) |
| 52 |
cmake_dependent_option(MZ_LIBBSD "Builds with libbsd crypto random" ON "UNIX" OFF) |
| 53 |
# Character conversion options |
| 54 |
option(MZ_ICONV "Enables iconv for string encoding conversion" ON) |
| 55 |
# Code generation options |
| 56 |
option(MZ_COMPRESS_ONLY "Only support compression" OFF) |
| 57 |
option(MZ_DECOMPRESS_ONLY "Only support decompression" OFF) |
| 58 |
option(MZ_FILE32_API "Builds using posix 32-bit file api" OFF) |
| 59 |
# Build and continuous integration options |
| 60 |
option(MZ_BUILD_TESTS "Builds minizip test executable" OFF) |
| 61 |
option(MZ_BUILD_UNIT_TESTS "Builds minizip unit test project" OFF) |
| 62 |
option(MZ_BUILD_FUZZ_TESTS "Builds minizip fuzzer executables" OFF) |
| 63 |
option(MZ_CODE_COVERAGE "Builds with code coverage flags" OFF) |
| 64 |
# Multi-choice code sanitizer option |
| 65 |
set(MZ_SANITIZER AUTO CACHE STRING "Enable sanitizer support") |
| 66 |
set_property(CACHE MZ_SANITIZER PROPERTY STRINGS "Memory" "Address" "Undefined" "Thread") |
| 67 |
|
| 68 |
# Backwards compatibility |
| 69 |
if(DEFINED MZ_BUILD_TEST) |
| 70 |
set(MZ_BUILD_TESTS ${MZ_BUILD_TEST}) |
| 71 |
endif() |
| 72 |
if(DEFINED MZ_BUILD_UNIT_TEST) |
| 73 |
set(MZ_BUILD_UNIT_TESTS ${MZ_BUILD_UNIT_TEST}) |
| 74 |
endif() |
| 75 |
if(DEFINED MZ_BUILD_FUZZ_TEST) |
| 76 |
set(MZ_BUILD_FUZZ_TESTS ${MZ_BUILD_FUZZ_TEST}) |
| 77 |
endif() |
| 78 |
if(DEFINED MZ_PROJECT_SUFFIX) |
| 79 |
set(MZ_LIB_SUFFIX ${MZ_PROJECT_SUFFIX}) |
| 80 |
endif() |
| 81 |
|
| 82 |
# Package management options |
| 83 |
if(NOT MZ_COMPAT AND NOT DEFINED MZ_LIB_SUFFIX) |
| 84 |
set(MZ_LIB_SUFFIX "-ng" CACHE STRING "Library name suffix for package managers") |
| 85 |
else() |
| 86 |
set(MZ_LIB_SUFFIX "" CACHE STRING "Library name suffix for package managers") |
| 87 |
endif() |
| 88 |
|
| 89 |
mark_as_advanced(MZ_FILE32_API MZ_LIB_SUFFIX) |
| 90 |
|
| 91 |
# ZLIB_ROOT - Parent directory of zlib installation |
| 92 |
# BZIP2_ROOT - Parent directory of BZip2 installation |
| 93 |
# OPENSSL_ROOT - Parent directory of OpenSSL installation |
| 94 |
|
| 95 |
include(cmake/clone-repo.cmake) |
| 96 |
|
| 97 |
set(STDLIB_DEF) |
| 98 |
set(MINIZIP_DEF) |
| 99 |
set(MINIZIP_INC) |
| 100 |
set(MINIZIP_LIB) |
| 101 |
set(MINIZIP_LBD) |
| 102 |
set(MINIZIP_DEP) |
| 103 |
set(MINIZIP_DEP_PKG) |
| 104 |
set(MINIZIP_LFG) |
| 105 |
|
| 106 |
# Initial source files |
| 107 |
set(MINIZIP_SRC |
| 108 |
mz_crypt.c |
| 109 |
mz_os.c |
| 110 |
mz_strm.c |
| 111 |
mz_strm_buf.c |
| 112 |
mz_strm_mem.c |
| 113 |
mz_strm_split.c |
| 114 |
mz_zip.c |
| 115 |
mz_zip_rw.c) |
| 116 |
|
| 117 |
# Initial header files |
| 118 |
set(MINIZIP_HDR |
| 119 |
mz.h |
| 120 |
mz_os.h |
| 121 |
mz_crypt.h |
| 122 |
mz_strm.h |
| 123 |
mz_strm_buf.h |
| 124 |
mz_strm_mem.h |
| 125 |
mz_strm_split.h |
| 126 |
mz_strm_os.h |
| 127 |
mz_zip.h |
| 128 |
mz_zip_rw.h) |
| 129 |
|
| 130 |
set(PC_PRIVATE_LIBS) |
| 131 |
set(PC_PRIVATE_DEPS) |
| 132 |
|
| 133 |
# Check for system includes |
| 134 |
check_include_file(stdint.h HAVE_STDINT_H) |
| 135 |
check_include_file(inttypes.h HAVE_INTTYPES_H) |
| 136 |
|
| 137 |
if(HAVE_STDINT_H) |
| 138 |
list(APPEND STDLIB_DEF -DHAVE_STDINT_H) |
| 139 |
endif() |
| 140 |
if(HAVE_INTTYPES_H) |
| 141 |
list(APPEND STDLIB_DEF -DHAVE_INTTYPES_H) |
| 142 |
endif() |
| 143 |
|
| 144 |
# Check for large file support |
| 145 |
check_type_size(off64_t OFF64_T) |
| 146 |
if(HAVE_OFF64_T) |
| 147 |
list(APPEND STDLIB_DEF -D__USE_LARGEFILE64) |
| 148 |
list(APPEND STDLIB_DEF -D_LARGEFILE64_SOURCE) |
| 149 |
endif() |
| 150 |
# Check for fseeko support |
| 151 |
check_function_exists(fseeko HAVE_FSEEKO) |
| 152 |
if(NOT HAVE_FSEEKO) |
| 153 |
list(APPEND STDLIB_DEF -DNO_FSEEKO) |
| 154 |
endif() |
| 155 |
|
| 156 |
if(MZ_LIBCOMP) |
| 157 |
if(APPLE) |
| 158 |
# Use Apple libcompression |
| 159 |
list(APPEND MINIZIP_DEF -DHAVE_LIBCOMP) |
| 160 |
list(APPEND MINIZIP_SRC mz_strm_libcomp.c) |
| 161 |
list(APPEND MINIZIP_HDR mz_strm_libcomp.h) |
| 162 |
list(APPEND MINIZIP_LIB compression) |
| 163 |
|
| 164 |
# Disable zlib as libcompression is preferred |
| 165 |
set(MZ_ZLIB OFF) |
| 166 |
else() |
| 167 |
message(STATUS "LibCompression not supported on the current platform") |
| 168 |
|
| 169 |
set(MZ_LIBCOMP OFF) |
| 170 |
endif() |
| 171 |
endif() |
| 172 |
|
| 173 |
if(MZ_ZLIB) |
| 174 |
# Check if zlib is present |
| 175 |
if(NOT MZ_FORCE_FETCH_LIBS) |
| 176 |
find_package(ZLIBNG QUIET) |
| 177 |
find_package(ZLIB QUIET) |
| 178 |
set(ZLIB_VERSION ${ZLIB_VERSION_STRING}) |
| 179 |
endif() |
| 180 |
|
| 181 |
if(ZLIBNG_FOUND AND NOT MZ_FORCE_FETCH_LIBS) |
| 182 |
message(STATUS "Using ZLIBNG") |
| 183 |
|
| 184 |
list(APPEND MINIZIP_INC ${ZLIBNG_INCLUDE_DIRS}) |
| 185 |
list(APPEND MINIZIP_LIB ${ZLIBNG_LIBRARIES}) |
| 186 |
list(APPEND MINIZIP_LBD ${ZLIBNG_LIBRARY_DIRS}) |
| 187 |
|
| 188 |
set(PC_PRIVATE_DEPS "zlib-ng") |
| 189 |
set(ZLIB_COMPAT OFF) |
| 190 |
elseif(ZLIB_FOUND AND NOT MZ_FORCE_FETCH_LIBS) |
| 191 |
message(STATUS "Using ZLIB ${ZLIB_VERSION}") |
| 192 |
|
| 193 |
list(APPEND MINIZIP_INC ${ZLIB_INCLUDE_DIRS}) |
| 194 |
list(APPEND MINIZIP_LIB ${ZLIB_LIBRARIES}) |
| 195 |
list(APPEND MINIZIP_LBD ${ZLIB_LIBRARY_DIRS}) |
| 196 |
|
| 197 |
set(PC_PRIVATE_DEPS "zlib") |
| 198 |
set(ZLIB_COMPAT ON) |
| 199 |
elseif(MZ_FETCH_LIBS) |
| 200 |
set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Build zlib-ng tests" FORCE) |
| 201 |
|
| 202 |
clone_repo(zlib https://github.com/zlib-ng/zlib-ng stable) |
| 203 |
|
| 204 |
# Don't automatically add all targets to the solution |
| 205 |
add_subdirectory(${ZLIB_SOURCE_DIR} ${ZLIB_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 206 |
|
| 207 |
list(APPEND MINIZIP_INC ${ZLIB_SOURCE_DIR}) |
| 208 |
list(APPEND MINIZIP_INC ${ZLIB_BINARY_DIR}) |
| 209 |
|
| 210 |
# Have to add zlib to install targets |
| 211 |
if(ZLIB_COMPAT AND (NOT DEFINED BUILD_SHARED_LIBS OR NOT BUILD_SHARED_LIBS)) |
| 212 |
list(APPEND MINIZIP_DEP zlibstatic) |
| 213 |
else() |
| 214 |
list(APPEND MINIZIP_DEP zlib) |
| 215 |
endif() |
| 216 |
|
| 217 |
if(EXISTS "${ZLIB_BINARY_DIR}/zlib-ng.h") |
| 218 |
message(STATUS "ZLIB repository detected as ZLIBNG") |
| 219 |
set(ZLIB_COMPAT OFF) |
| 220 |
else() |
| 221 |
set(ZLIB_COMPAT ON) |
| 222 |
endif() |
| 223 |
else() |
| 224 |
message(STATUS "ZLIB library not found") |
| 225 |
|
| 226 |
set(MZ_ZLIB OFF) |
| 227 |
endif() |
| 228 |
|
| 229 |
if(MZ_ZLIB) |
| 230 |
list(APPEND MINIZIP_DEF -DHAVE_ZLIB) |
| 231 |
if(ZLIB_COMPAT) |
| 232 |
list(APPEND MINIZIP_DEF -DZLIB_COMPAT) |
| 233 |
endif() |
| 234 |
if(ZLIBNG_FOUND OR NOT ZLIB_COMPAT) |
| 235 |
list(APPEND MINIZIP_DEP_PKG ZLIBNG) |
| 236 |
elseif(ZLIB_FOUND) |
| 237 |
list(APPEND MINIZIP_DEP_PKG ZLIB) |
| 238 |
endif() |
| 239 |
list(APPEND MINIZIP_SRC mz_strm_zlib.c) |
| 240 |
list(APPEND MINIZIP_HDR mz_strm_zlib.h) |
| 241 |
endif() |
| 242 |
endif() |
| 243 |
|
| 244 |
if(MZ_BZIP2) |
| 245 |
# Check if bzip2 is present |
| 246 |
if(NOT MZ_FORCE_FETCH_LIBS) |
| 247 |
find_package(BZip2 QUIET) |
| 248 |
endif() |
| 249 |
|
| 250 |
if(BZIP2_FOUND AND NOT MZ_FORCE_FETCH_LIBS) |
| 251 |
message(STATUS "Using BZIP2 ${BZIP2_VERSION_STRING}") |
| 252 |
|
| 253 |
list(APPEND MINIZIP_INC ${BZIP2_INCLUDE_DIRS}) |
| 254 |
list(APPEND MINIZIP_LIB ${BZIP2_LIBRARIES}) |
| 255 |
list(APPEND MINIZIP_LBD ${BZIP2_LIBRARY_DIRS}) |
| 256 |
|
| 257 |
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lbz2") |
| 258 |
elseif(MZ_FETCH_LIBS) |
| 259 |
clone_repo(bzip2 https://sourceware.org/git/bzip2.git master) |
| 260 |
|
| 261 |
# BZip2 repository does not support cmake so we have to create |
| 262 |
# the bzip2 library ourselves |
| 263 |
set(BZIP2_SRC |
| 264 |
${BZIP2_SOURCE_DIR}/blocksort.c |
| 265 |
${BZIP2_SOURCE_DIR}/bzlib.c |
| 266 |
${BZIP2_SOURCE_DIR}/compress.c |
| 267 |
${BZIP2_SOURCE_DIR}/crctable.c |
| 268 |
${BZIP2_SOURCE_DIR}/decompress.c |
| 269 |
${BZIP2_SOURCE_DIR}/huffman.c |
| 270 |
${BZIP2_SOURCE_DIR}/randtable.c) |
| 271 |
|
| 272 |
set(BZIP2_HDR |
| 273 |
${BZIP2_SOURCE_DIR}/bzlib.h |
| 274 |
${BZIP2_SOURCE_DIR}/bzlib_private.h) |
| 275 |
|
| 276 |
add_library(bzip2 STATIC ${BZIP2_SRC} ${BZIP2_HDR}) |
| 277 |
|
| 278 |
target_compile_definitions(bzip2 PRIVATE -DBZ_NO_STDIO) |
| 279 |
|
| 280 |
list(APPEND MINIZIP_DEP bzip2) |
| 281 |
list(APPEND MINIZIP_INC ${BZIP2_SOURCE_DIR}) |
| 282 |
else() |
| 283 |
message(STATUS "BZip2 library not found") |
| 284 |
|
| 285 |
set(MZ_BZIP2 OFF) |
| 286 |
endif() |
| 287 |
|
| 288 |
if(MZ_BZIP2) |
| 289 |
list(APPEND MINIZIP_DEP_PKG BZip2) |
| 290 |
list(APPEND MINIZIP_DEF -DHAVE_BZIP2) |
| 291 |
list(APPEND MINIZIP_SRC mz_strm_bzip.c) |
| 292 |
list(APPEND MINIZIP_HDR mz_strm_bzip.h) |
| 293 |
endif() |
| 294 |
endif() |
| 295 |
|
| 296 |
if(MZ_LZMA) |
| 297 |
# Check if liblzma is present |
| 298 |
if(NOT MZ_FORCE_FETCH_LIBS) |
| 299 |
find_package(PkgConfig QUIET) |
| 300 |
if(PKGCONFIG_FOUND) |
| 301 |
pkg_check_modules(LIBLZMA liblzma) |
| 302 |
endif() |
| 303 |
if(NOT LIBLZMA_FOUND) |
| 304 |
find_package(LibLZMA QUIET) |
| 305 |
set(LIBLZMA_VERSION ${LIBLZMA_VERSION_STRING}) |
| 306 |
endif() |
| 307 |
endif() |
| 308 |
|
| 309 |
if(LIBLZMA_FOUND AND NOT MZ_FORCE_FETCH_LIBS) |
| 310 |
message(STATUS "Using LZMA ${LIBLZMA_VERSION}") |
| 311 |
|
| 312 |
list(APPEND MINIZIP_INC ${LIBLZMA_INCLUDE_DIRS}) |
| 313 |
list(APPEND MINIZIP_LIB ${LIBLZMA_LIBRARIES}) |
| 314 |
list(APPEND MINIZIP_LBD ${LIBLZMA_LIBRARY_DIRS}) |
| 315 |
|
| 316 |
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -llzma") |
| 317 |
elseif(MZ_FETCH_LIBS) |
| 318 |
set(BUILD_TESTING OFF CACHE BOOL "Build lzma tests" FORCE) |
| 319 |
|
| 320 |
clone_repo(liblzma https://github.com/tukaani-project/xz master) |
| 321 |
|
| 322 |
# Don't automatically add all targets to the solution |
| 323 |
add_subdirectory(${LIBLZMA_SOURCE_DIR} ${LIBLZMA_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 324 |
|
| 325 |
list(APPEND MINIZIP_INC ${LIBLZMA_SOURCE_DIR}/src/liblzma/api) |
| 326 |
list(APPEND MINIZIP_DEP liblzma) |
| 327 |
list(APPEND MINIZIP_LIB ${LIBLZMA_TARGET}) |
| 328 |
else() |
| 329 |
message(STATUS "LibLZMA library not found") |
| 330 |
|
| 331 |
set(MZ_LZMA OFF) |
| 332 |
endif() |
| 333 |
|
| 334 |
if(MZ_LZMA) |
| 335 |
list(APPEND MINIZIP_DEP_PKG LibLZMA) |
| 336 |
list(APPEND MINIZIP_DEF -DHAVE_LZMA -DLZMA_API_STATIC) |
| 337 |
list(APPEND MINIZIP_SRC mz_strm_lzma.c) |
| 338 |
list(APPEND MINIZIP_HDR mz_strm_lzma.h) |
| 339 |
endif() |
| 340 |
endif() |
| 341 |
|
| 342 |
if(MZ_ZSTD) |
| 343 |
# Check if zstd is present |
| 344 |
if(NOT MZ_FORCE_FETCH_LIBS) |
| 345 |
find_package(PkgConfig QUIET) |
| 346 |
if(PKGCONFIG_FOUND) |
| 347 |
pkg_check_modules(ZSTD libzstd) |
| 348 |
endif() |
| 349 |
if(NOT ZSTD_FOUND) |
| 350 |
find_package(ZSTD QUIET) |
| 351 |
if(ZSTD_FOUND) |
| 352 |
if(TARGET zstd::libzstd_static) |
| 353 |
list(APPEND ZSTD_LIBRARIES zstd::libzstd_static) |
| 354 |
else() |
| 355 |
list(APPEND ZSTD_LIBRARIES zstd::libzstd_shared) |
| 356 |
endif() |
| 357 |
endif() |
| 358 |
endif() |
| 359 |
endif() |
| 360 |
|
| 361 |
if(ZSTD_FOUND AND NOT MZ_FORCE_FETCH_LIBS) |
| 362 |
message(STATUS "Using ZSTD ${ZSTD_VERSION}") |
| 363 |
|
| 364 |
list(APPEND MINIZIP_INC ${ZSTD_INCLUDE_DIRS}) |
| 365 |
list(APPEND MINIZIP_LIB ${ZSTD_LIBRARIES}) |
| 366 |
list(APPEND MINIZIP_LBD ${ZSTD_LIBRARY_DIRS}) |
| 367 |
|
| 368 |
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lzstd") |
| 369 |
elseif(MZ_FETCH_LIBS) |
| 370 |
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "Build zstd programs") |
| 371 |
|
| 372 |
clone_repo(zstd https://github.com/facebook/zstd release) |
| 373 |
|
| 374 |
# Don't automatically add all targets to the solution |
| 375 |
add_subdirectory(${ZSTD_SOURCE_DIR}/build/cmake ${ZSTD_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 376 |
|
| 377 |
list(APPEND MINIZIP_INC ${ZSTD_SOURCE_DIR}/lib) |
| 378 |
if(NOT DEFINED BUILD_SHARED_LIBS OR NOT ${BUILD_SHARED_LIBS}) |
| 379 |
list(APPEND MINIZIP_DEP libzstd_static) |
| 380 |
else() |
| 381 |
list(APPEND MINIZIP_DEP libzstd_shared) |
| 382 |
endif() |
| 383 |
else() |
| 384 |
message(STATUS "ZSTD library not found") |
| 385 |
|
| 386 |
set(MZ_ZSTD OFF) |
| 387 |
endif() |
| 388 |
|
| 389 |
if(MZ_ZSTD) |
| 390 |
list(APPEND MINIZIP_DEP_PKG zstd) |
| 391 |
list(APPEND MINIZIP_DEF -DHAVE_ZSTD) |
| 392 |
list(APPEND MINIZIP_SRC mz_strm_zstd.c) |
| 393 |
list(APPEND MINIZIP_HDR mz_strm_zstd.h) |
| 394 |
endif() |
| 395 |
endif() |
| 396 |
|
| 397 |
if(NOT MZ_LIBCOMP AND NOT MZ_ZLIB AND NOT MZ_ZSTD AND NOT MZ_BZIP2 AND NOT MZ_LZMA) |
| 398 |
message(STATUS "Compression not supported due to missing libraries") |
| 399 |
|
| 400 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_DECOMPRESSION) |
| 401 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_COMPRESSION) |
| 402 |
endif() |
| 403 |
|
| 404 |
if(MZ_OPENSSL) |
| 405 |
# Check to see if openssl installation is present |
| 406 |
find_package(PkgConfig) |
| 407 |
if(PKGCONFIG_FOUND) |
| 408 |
pkg_check_modules(OPENSSL openssl) |
| 409 |
endif() |
| 410 |
if(NOT OPENSSL_FOUND) |
| 411 |
find_package(OpenSSL) |
| 412 |
endif() |
| 413 |
|
| 414 |
if(OPENSSL_FOUND) |
| 415 |
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}") |
| 416 |
|
| 417 |
list(APPEND MINIZIP_SRC mz_crypt_openssl.c) |
| 418 |
list(APPEND MINIZIP_LIB ${OPENSSL_LIBRARIES}) |
| 419 |
list(APPEND MINIZIP_LBD ${OPENSSL_LIBRARY_DIRS}) |
| 420 |
|
| 421 |
if(OPENSSL_INCLUDE_DIRS) |
| 422 |
list(APPEND MINIZIP_INC ${OPENSSL_INCLUDE_DIRS}) |
| 423 |
endif() |
| 424 |
if(OPENSSL_INCLUDE_DIR) |
| 425 |
list(APPEND MINIZIP_INC ${OPENSSL_INCLUDE_DIR}) |
| 426 |
endif() |
| 427 |
|
| 428 |
foreach(i ${OPENSSL_LIBRARIES}) |
| 429 |
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -l${i}") |
| 430 |
endforeach() |
| 431 |
else() |
| 432 |
message(STATUS "OpenSSL library not found") |
| 433 |
|
| 434 |
set(MZ_OPENSSL OFF) |
| 435 |
endif() |
| 436 |
endif() |
| 437 |
|
| 438 |
# Platform specific |
| 439 |
if(WIN32) |
| 440 |
list(APPEND MINIZIP_DEF -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) |
| 441 |
list(APPEND MINIZIP_SRC mz_os_win32.c mz_strm_os_win32.c) |
| 442 |
|
| 443 |
if(MZ_PKCRYPT OR MZ_WZAES) |
| 444 |
if(MZ_OPENSSL) |
| 445 |
list(APPEND MINIZIP_DEP_PKG OpenSSL) |
| 446 |
else() |
| 447 |
# Check for existence of BCrypt API |
| 448 |
set(CMAKE_REQUIRED_LIBRARIES bcrypt.lib ncrypt.lib crypt32.lib) |
| 449 |
check_symbol_exists(BCryptGenRandom "windows.h;bcrypt.h" HAVE_BCRYPT) |
| 450 |
set(CMAKE_REQUIRED_LIBRARIES) |
| 451 |
if (HAVE_BCRYPT) |
| 452 |
list(APPEND MINIZIP_SRC mz_crypt_winvista.c) |
| 453 |
list(APPEND MINIZIP_LIB bcrypt.lib ncrypt.lib) |
| 454 |
endif() |
| 455 |
|
| 456 |
list(APPEND MINIZIP_SRC mz_crypt_winxp.c) |
| 457 |
list(APPEND MINIZIP_LIB crypt32.lib) |
| 458 |
endif() |
| 459 |
else() |
| 460 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO) |
| 461 |
endif() |
| 462 |
|
| 463 |
set(MZ_LIBBSD OFF) |
| 464 |
set(MZ_ICONV OFF) |
| 465 |
else() |
| 466 |
list(APPEND STDLIB_DEF -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE -D_DEFAULT_SOURCE) |
| 467 |
list(APPEND MINIZIP_SRC mz_os_posix.c mz_strm_os_posix.c) |
| 468 |
|
| 469 |
if(MZ_PKCRYPT OR MZ_WZAES) |
| 470 |
if(MZ_OPENSSL) |
| 471 |
list(APPEND MINIZIP_DEP_PKG OpenSSL) |
| 472 |
else() |
| 473 |
if(APPLE) |
| 474 |
message(STATUS "Using CoreFoundation Framework") |
| 475 |
find_library(COREFOUNDATION_LIBRARY CoreFoundation) |
| 476 |
|
| 477 |
list(APPEND MINIZIP_LIB ${COREFOUNDATION_LIBRARY}) |
| 478 |
|
| 479 |
message(STATUS "Using Security Framework") |
| 480 |
find_library(SECURITY_LIBRARY Security) |
| 481 |
|
| 482 |
list(APPEND MINIZIP_LIB ${SECURITY_LIBRARY}) |
| 483 |
list(APPEND MINIZIP_LFG "-Wl,-F/Library/Frameworks") |
| 484 |
|
| 485 |
check_include_file(CommonCrypto/CommonCrypto.h COMMONCRYPTO_FOUND) |
| 486 |
if(COMMONCRYPTO_FOUND) |
| 487 |
message(STATUS "Using CommonCrypto") |
| 488 |
|
| 489 |
list(APPEND MINIZIP_SRC mz_crypt_apple.c) |
| 490 |
|
| 491 |
set(MZ_LIBBSD OFF) |
| 492 |
else() |
| 493 |
message(STATUS "CommonCrypto library not found") |
| 494 |
|
| 495 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO) |
| 496 |
|
| 497 |
if(MZ_WZAES) |
| 498 |
message(STATUS "WinZIP AES support requires CommonCrypto or OpenSSL") |
| 499 |
|
| 500 |
set(MZ_WZAES OFF) |
| 501 |
endif() |
| 502 |
endif() |
| 503 |
else() |
| 504 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO) |
| 505 |
|
| 506 |
if(MZ_WZAES) |
| 507 |
message(STATUS "WinZIP AES support requires OpenSSL") |
| 508 |
|
| 509 |
set(MZ_WZAES OFF) |
| 510 |
endif() |
| 511 |
endif() |
| 512 |
|
| 513 |
# Check to see which random generation functions we have |
| 514 |
check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM) |
| 515 |
if(HAVE_GETRANDOM) |
| 516 |
list(APPEND MINIZIP_DEF -DHAVE_GETRANDOM) |
| 517 |
endif() |
| 518 |
check_symbol_exists("arc4random_buf" "stdlib.h" HAVE_ARC4RANDOM_BUF) |
| 519 |
if(HAVE_ARC4RANDOM_BUF) |
| 520 |
list(APPEND MINIZIP_DEF -DHAVE_ARC4RANDOM_BUF) |
| 521 |
else() |
| 522 |
check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM) |
| 523 |
if(HAVE_ARC4RANDOM) |
| 524 |
list(APPEND MINIZIP_DEF -DHAVE_ARC4RANDOM) |
| 525 |
endif() |
| 526 |
endif() |
| 527 |
|
| 528 |
if(APPLE) |
| 529 |
# Requires _DARWIN_C_SOURCE for arcrandom functions |
| 530 |
list(APPEND MINIZIP_DEF -D_DARWIN_C_SOURCE) |
| 531 |
endif() |
| 532 |
|
| 533 |
if(MZ_LIBBSD AND NOT HAVE_ARC4RANDOM_BUF) |
| 534 |
find_package(PkgConfig REQUIRED) |
| 535 |
|
| 536 |
pkg_check_modules(LIBBSD libbsd-overlay) |
| 537 |
if(LIBBSD_FOUND) |
| 538 |
check_library_exists("${LIBBSD_LIBRARIES}" "arc4random_buf" |
| 539 |
"${LIBBSD_LIBRARY_DIRS}" HAVE_LIBBSD_ARC4RANDOM_BUF) |
| 540 |
|
| 541 |
if(HAVE_LIBBSD_ARC4RANDOM_BUF) |
| 542 |
list(APPEND MINIZIP_DEF -DHAVE_LIBBSD -DHAVE_ARC4RANDOM_BUF) |
| 543 |
list(APPEND MINIZIP_INC ${LIBBSD_INCLUDE_DIRS}) |
| 544 |
list(APPEND MINIZIP_LIB ${LIBBSD_LIBRARIES}) |
| 545 |
list(APPEND MINIZIP_LBD ${LIBBSD_LIBRARY_DIRS}) |
| 546 |
|
| 547 |
link_directories(${LIBBSD_LIBRARY_DIRS}) |
| 548 |
endif() |
| 549 |
else() |
| 550 |
set(MZ_LIBBSD OFF) |
| 551 |
endif() |
| 552 |
else() |
| 553 |
set(MZ_LIBBSD OFF) |
| 554 |
endif() |
| 555 |
|
| 556 |
if(NOT MZ_LIBBSD AND NOT HAVE_GETRANDOM AND NOT HAVE_ARC4RANDOM_BUF AND NOT HAVE_ARC4RANDOM) |
| 557 |
message(WARNING "Low quality entropy function used for encryption") |
| 558 |
endif() |
| 559 |
endif() |
| 560 |
else() |
| 561 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO) |
| 562 |
endif() |
| 563 |
|
| 564 |
# Iconv is only necessary when it is not already built-in |
| 565 |
# FindIconv requires cmake 3.11 or higher |
| 566 |
if (MZ_ICONV) |
| 567 |
find_package(Iconv QUIET) |
| 568 |
endif() |
| 569 |
|
| 570 |
if(Iconv_FOUND) |
| 571 |
message(STATUS "Using Iconv") |
| 572 |
|
| 573 |
list(APPEND MINIZIP_DEF -DHAVE_ICONV) |
| 574 |
list(APPEND MINIZIP_INC ${Iconv_INCLUDE_DIRS}) |
| 575 |
list(APPEND MINIZIP_DEP_PKG Iconv) |
| 576 |
if(NOT Iconv_IS_BUILT_IN) |
| 577 |
list(APPEND MINIZIP_LIB ${Iconv_LIBRARIES}) |
| 578 |
list(APPEND MINIZIP_LBD ${Iconv_LIBRARY_DIRS}) |
| 579 |
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -liconv") |
| 580 |
endif() |
| 581 |
else() |
| 582 |
message(STATUS "Character encoding support requires iconv") |
| 583 |
|
| 584 |
set(MZ_ICONV OFF) |
| 585 |
endif() |
| 586 |
endif() |
| 587 |
|
| 588 |
# Setup predefined macros |
| 589 |
if(MZ_COMPRESS_ONLY) |
| 590 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_DECOMPRESSION) |
| 591 |
endif() |
| 592 |
if(MZ_DECOMPRESS_ONLY) |
| 593 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_COMPRESSION) |
| 594 |
endif() |
| 595 |
if(NOT MZ_PKCRYPT AND NOT MZ_WZAES) |
| 596 |
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_ENCRYPTION) |
| 597 |
endif() |
| 598 |
if(MZ_FILE32_API) |
| 599 |
list(APPEND MINIZIP_DEF -DMZ_FILE32_API) |
| 600 |
endif() |
| 601 |
|
| 602 |
# Include traditional PKWare encryption |
| 603 |
if(MZ_PKCRYPT) |
| 604 |
list(APPEND MINIZIP_DEF -DHAVE_PKCRYPT) |
| 605 |
list(APPEND MINIZIP_SRC mz_strm_pkcrypt.c) |
| 606 |
list(APPEND MINIZIP_HDR mz_strm_pkcrypt.h) |
| 607 |
endif() |
| 608 |
|
| 609 |
# Include WinZIP AES encryption |
| 610 |
if(MZ_WZAES) |
| 611 |
list(APPEND MINIZIP_DEF -DHAVE_WZAES) |
| 612 |
list(APPEND MINIZIP_SRC mz_strm_wzaes.c) |
| 613 |
list(APPEND MINIZIP_HDR mz_strm_wzaes.h) |
| 614 |
endif() |
| 615 |
|
| 616 |
# Include compatibility layer |
| 617 |
if(MZ_COMPAT) |
| 618 |
set(SOVERSION "1") |
| 619 |
|
| 620 |
list(APPEND MINIZIP_SRC |
| 621 |
compat/ioapi.c |
| 622 |
compat/unzip.c |
| 623 |
compat/zip.c) |
| 624 |
list(APPEND MINIZIP_HDR |
| 625 |
compat/ioapi.h |
| 626 |
compat/unzip.h |
| 627 |
compat/zip.h) |
| 628 |
|
| 629 |
if(MZ_COMPAT_VERSION) |
| 630 |
list(APPEND MINIZIP_DEF -DMZ_COMPAT_VERSION=${MZ_COMPAT_VERSION}) |
| 631 |
endif() |
| 632 |
endif() |
| 633 |
|
| 634 |
# Detect available sanitizers |
| 635 |
if(MZ_SANITIZER STREQUAL "Address") |
| 636 |
add_address_sanitizer() |
| 637 |
elseif(MZ_SANITIZER STREQUAL "Memory") |
| 638 |
add_memory_sanitizer() |
| 639 |
elseif(MZ_SANITIZER STREQUAL "Thread") |
| 640 |
add_thread_sanitizer() |
| 641 |
elseif(MZ_SANITIZER STREQUAL "Undefined") |
| 642 |
add_undefined_sanitizer() |
| 643 |
endif() |
| 644 |
|
| 645 |
# Set compiler options |
| 646 |
if(MZ_CODE_COVERAGE) |
| 647 |
if(NOT MSVC) |
| 648 |
message(STATUS "Code coverage enabled") |
| 649 |
add_compile_options(-O0 -g -fprofile-arcs -ftest-coverage) |
| 650 |
if(CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang") |
| 651 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") |
| 652 |
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") |
| 653 |
link_libraries(gcov) |
| 654 |
endif() |
| 655 |
set_property(DIRECTORY PROPERTY |
| 656 |
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS YES |
| 657 |
GCC_GENERATE_TEST_COVERAGE_FILES YES) |
| 658 |
else() |
| 659 |
set(MZ_CODE_COVERAGE OFF) |
| 660 |
endif() |
| 661 |
else() |
| 662 |
if(MSVC) |
| 663 |
add_compile_options($<$<CONFIG:Debug>:/W3>) |
| 664 |
else() |
| 665 |
add_compile_options($<$<CONFIG:Debug>:-Wall>) |
| 666 |
endif() |
| 667 |
endif() |
| 668 |
|
| 669 |
list(APPEND MINIZIP_INC ${CMAKE_CURRENT_SOURCE_DIR}) |
| 670 |
|
| 671 |
set(MINIZIP_TARGET minizip${MZ_LIB_SUFFIX}) |
| 672 |
set(MINIZIP_PC ${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}.pc) |
| 673 |
configure_file(minizip.pc.cmakein ${MINIZIP_PC} @ONLY) |
| 674 |
|
| 675 |
# Create minizip library and aliases |
| 676 |
add_library(${MINIZIP_TARGET} ${MINIZIP_SRC} ${MINIZIP_HDR}) |
| 677 |
add_library(MINIZIP::${MINIZIP_TARGET} ALIAS ${MINIZIP_TARGET}) |
| 678 |
if(NOT TARGET MINIZIP::minizip) |
| 679 |
add_library(MINIZIP::minizip ALIAS ${MINIZIP_TARGET}) |
| 680 |
endif() |
| 681 |
|
| 682 |
set_target_properties(${MINIZIP_TARGET} PROPERTIES |
| 683 |
VERSION ${VERSION} |
| 684 |
SOVERSION ${SOVERSION} |
| 685 |
LINKER_LANGUAGE C |
| 686 |
DEFINE_SYMBOL "MZ_EXPORTS") |
| 687 |
|
| 688 |
if(MINIZIP_LFG) |
| 689 |
set_target_properties(${MINIZIP_TARGET} PROPERTIES LINK_FLAGS ${MINIZIP_LFG}) |
| 690 |
endif() |
| 691 |
if(MZ_LZMA) |
| 692 |
set_target_properties(${MINIZIP_TARGET} PROPERTIES C_STANDARD 99) |
| 693 |
endif() |
| 694 |
|
| 695 |
target_link_libraries(${MINIZIP_TARGET} PUBLIC ${MINIZIP_LIB} ${MINIZIP_DEP}) |
| 696 |
target_link_directories(${MINIZIP_TARGET} PUBLIC ${MINIZIP_LBD}) |
| 697 |
target_compile_definitions(${MINIZIP_TARGET} PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) |
| 698 |
target_include_directories(${MINIZIP_TARGET} PRIVATE ${MINIZIP_INC}) |
| 699 |
target_include_directories(${MINIZIP_TARGET} PUBLIC |
| 700 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) |
| 701 |
if(MZ_COMPAT) |
| 702 |
target_include_directories(${MINIZIP_TARGET} PUBLIC |
| 703 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compat/> |
| 704 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>) |
| 705 |
endif() |
| 706 |
|
| 707 |
# Install files |
| 708 |
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) |
| 709 |
target_include_directories(${MINIZIP_TARGET} PUBLIC |
| 710 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${MINIZIP_TARGET}>) |
| 711 |
|
| 712 |
install(TARGETS ${MINIZIP_TARGET} ${MINIZIP_DEP} |
| 713 |
EXPORT ${MINIZIP_TARGET} |
| 714 |
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${MINIZIP_TARGET}" |
| 715 |
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 716 |
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 717 |
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") |
| 718 |
install(EXPORT ${MINIZIP_TARGET} |
| 719 |
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${MINIZIP_TARGET}" |
| 720 |
NAMESPACE "MINIZIP::") |
| 721 |
|
| 722 |
# Create and install CMake package config version file to allow find_package() |
| 723 |
include(CMakePackageConfigHelpers) |
| 724 |
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}-config-version.cmake |
| 725 |
COMPATIBILITY SameMajorVersion) |
| 726 |
set(MINIZIP_CONFIG_CONTENT "@PACKAGE_INIT@\n") |
| 727 |
if(MINIZIP_DEP_PKG) |
| 728 |
string(APPEND MINIZIP_CONFIG_CONTENT "include(CMakeFindDependencyMacro)\n") |
| 729 |
foreach(pkg_name ${MINIZIP_DEP_PKG}) |
| 730 |
string(APPEND MINIZIP_CONFIG_CONTENT "find_dependency(${pkg_name})\n") |
| 731 |
endforeach() |
| 732 |
endif() |
| 733 |
string(APPEND MINIZIP_CONFIG_CONTENT "include(\"\${CMAKE_CURRENT_LIST_DIR}/${MINIZIP_TARGET}.cmake\")") |
| 734 |
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/minizip-config.cmake.in ${MINIZIP_CONFIG_CONTENT}) |
| 735 |
|
| 736 |
# Create config for find_package() |
| 737 |
configure_package_config_file( |
| 738 |
${CMAKE_CURRENT_BINARY_DIR}/minizip-config.cmake.in |
| 739 |
${MINIZIP_TARGET}-config.cmake |
| 740 |
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${MINIZIP_TARGET}") |
| 741 |
|
| 742 |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}-config-version.cmake |
| 743 |
${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}-config.cmake |
| 744 |
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${MINIZIP_TARGET}") |
| 745 |
endif() |
| 746 |
if(NOT SKIP_INSTALL_HDR AND NOT SKIP_INSTALL_ALL) |
| 747 |
install(FILES ${MINIZIP_HDR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${MINIZIP_TARGET}") |
| 748 |
endif() |
| 749 |
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL) |
| 750 |
install(FILES ${MINIZIP_PC} DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 751 |
endif() |
| 752 |
|
| 753 |
# Build test executables |
| 754 |
if(MZ_BUILD_TESTS) |
| 755 |
if(MZ_ZLIB AND NOT MZ_LIBCOMP) |
| 756 |
add_executable(minigzip_cli minigzip.c) |
| 757 |
set_target_properties(minigzip_cli PROPERTIES OUTPUT_NAME minigzip) |
| 758 |
target_compile_definitions(minigzip_cli PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) |
| 759 |
target_include_directories(minigzip_cli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) |
| 760 |
target_link_libraries(minigzip_cli ${MINIZIP_TARGET}) |
| 761 |
|
| 762 |
if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL) |
| 763 |
install(TARGETS minigzip_cli RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 764 |
endif() |
| 765 |
endif() |
| 766 |
|
| 767 |
add_executable(minizip_cli minizip.c) |
| 768 |
|
| 769 |
if(MSVC AND MZ_COMPAT AND CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo") |
| 770 |
# VS debugger has problems when executable and static library are named the same |
| 771 |
set_target_properties(minizip_cli PROPERTIES OUTPUT_NAME minizip_cli) |
| 772 |
else() |
| 773 |
set_target_properties(minizip_cli PROPERTIES OUTPUT_NAME minizip) |
| 774 |
endif() |
| 775 |
|
| 776 |
target_compile_definitions(minizip_cli PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) |
| 777 |
target_include_directories(minizip_cli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) |
| 778 |
target_link_libraries(minizip_cli ${MINIZIP_TARGET}) |
| 779 |
if(WIN32) |
| 780 |
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT minizip_cli) |
| 781 |
endif() |
| 782 |
|
| 783 |
if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL) |
| 784 |
install(TARGETS minizip_cli RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 785 |
endif() |
| 786 |
endif() |
| 787 |
|
| 788 |
if(MZ_BUILD_TESTS AND MZ_BUILD_UNIT_TESTS) |
| 789 |
enable_testing() |
| 790 |
|
| 791 |
add_subdirectory(test) |
| 792 |
|
| 793 |
# Can't disable zlib testing so ctest tries to run zlib example app |
| 794 |
if(MZ_ZLIB AND NOT MZ_LIBCOMP AND NOT ZLIB_FOUND) |
| 795 |
if(TARGET example) |
| 796 |
target_include_directories(example PRIVATE ${ZLIB_SOURCE_DIR}) |
| 797 |
add_dependencies(${MINIZIP_TARGET} example) |
| 798 |
endif() |
| 799 |
if(TARGET example64) |
| 800 |
target_include_directories(example64 PRIVATE ${ZLIB_SOURCE_DIR}) |
| 801 |
add_dependencies(${MINIZIP_TARGET} example64) |
| 802 |
endif() |
| 803 |
endif() |
| 804 |
|
| 805 |
set(TEST_TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/Testing/Temporary) |
| 806 |
|
| 807 |
function(create_compress_tests EXTRA_NAME EXTRA_ARGS) |
| 808 |
if(MZ_DECOMPRESS_ONLY) |
| 809 |
return() |
| 810 |
endif() |
| 811 |
list(FIND EXTRA_ARGS "-z" ZIPCD_IDX) |
| 812 |
if(${ZIPCD_IDX} EQUAL -1) |
| 813 |
set(COMPRESS_METHOD_NAMES "raw") |
| 814 |
set(COMPRESS_METHOD_ARGS "-0") |
| 815 |
endif() |
| 816 |
if(MZ_ZLIB OR MZ_LIBCOMP) |
| 817 |
list(APPEND COMPRESS_METHOD_NAMES "deflate") |
| 818 |
list(APPEND COMPRESS_METHOD_ARGS "-9") |
| 819 |
endif() |
| 820 |
if(MZ_BZIP2) |
| 821 |
list(APPEND COMPRESS_METHOD_NAMES "bzip2") |
| 822 |
list(APPEND COMPRESS_METHOD_ARGS "-b") |
| 823 |
endif() |
| 824 |
if(MZ_LZMA) |
| 825 |
list(APPEND COMPRESS_METHOD_NAMES "lzma") |
| 826 |
list(APPEND COMPRESS_METHOD_ARGS "-m") |
| 827 |
endif() |
| 828 |
if(MZ_LZMA OR MZ_LIBCOMP) |
| 829 |
list(APPEND COMPRESS_METHOD_NAMES "xz") |
| 830 |
list(APPEND COMPRESS_METHOD_ARGS "-n") |
| 831 |
endif() |
| 832 |
if(MZ_ZSTD) |
| 833 |
list(APPEND COMPRESS_METHOD_NAMES "zstd") |
| 834 |
list(APPEND COMPRESS_METHOD_ARGS "-t") |
| 835 |
endif() |
| 836 |
list(LENGTH COMPRESS_METHOD_NAMES COMPRESS_METHOD_COUNT) |
| 837 |
math(EXPR COMPRESS_METHOD_COUNT "${COMPRESS_METHOD_COUNT}-1") |
| 838 |
foreach(INDEX RANGE ${COMPRESS_METHOD_COUNT}) |
| 839 |
list(GET COMPRESS_METHOD_NAMES ${INDEX} COMPRESS_METHOD_NAME) |
| 840 |
list(GET COMPRESS_METHOD_ARGS ${INDEX} COMPRESS_METHOD_ARG) |
| 841 |
|
| 842 |
set(COMPRESS_METHOD_DEST_DIR |
| 843 |
${TEST_TEMP_DIR}/${COMPRESS_METHOD_NAME}-${EXTRA_NAME}) |
| 844 |
set(COMPRESS_METHOD_PATH |
| 845 |
${TEST_TEMP_DIR}/${COMPRESS_METHOD_NAME}-${EXTRA_NAME}.zip) |
| 846 |
|
| 847 |
add_test(NAME ${COMPRESS_METHOD_NAME}-zip-${EXTRA_NAME} |
| 848 |
COMMAND minizip_cli ${COMPRESS_METHOD_ARG} -o ${EXTRA_ARGS} |
| 849 |
${COMPRESS_METHOD_PATH} |
| 850 |
test.c test.h empty.txt random.bin uniform.bin fuzz |
| 851 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 852 |
add_test(NAME ${COMPRESS_METHOD_NAME}-list-${EXTRA_NAME} |
| 853 |
COMMAND minizip_cli -l ${EXTRA_ARGS} ${COMPRESS_METHOD_PATH} |
| 854 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 855 |
if(NOT MZ_COMPRESS_ONLY) |
| 856 |
add_test(NAME ${COMPRESS_METHOD_NAME}-unzip-${EXTRA_NAME} |
| 857 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 858 |
-d ${COMPRESS_METHOD_DEST_DIR} ${COMPRESS_METHOD_PATH} |
| 859 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 860 |
endif() |
| 861 |
add_test(NAME ${COMPRESS_METHOD_NAME}-append-${EXTRA_NAME} |
| 862 |
COMMAND minizip_cli ${COMPRESS_METHOD_ARG} -a ${EXTRA_ARGS} |
| 863 |
${COMPRESS_METHOD_PATH} single.txt |
| 864 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 865 |
if(NOT MZ_COMPRESS_ONLY) |
| 866 |
add_test(NAME ${COMPRESS_METHOD_NAME}-append-unzip-${EXTRA_NAME} |
| 867 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 868 |
-d ${COMPRESS_METHOD_DEST_DIR} ${COMPRESS_METHOD_PATH} |
| 869 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 870 |
endif() |
| 871 |
add_test(NAME ${COMPRESS_METHOD_NAME}-erase-${EXTRA_NAME} |
| 872 |
COMMAND minizip_cli -o -e ${COMPRESS_METHOD_PATH} test.c test.h |
| 873 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 874 |
if(NOT MZ_COMPRESS_ONLY) |
| 875 |
add_test(NAME ${COMPRESS_METHOD_NAME}-erase-unzip-${EXTRA_NAME} |
| 876 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 877 |
-d ${COMPRESS_METHOD_DEST_DIR} ${COMPRESS_METHOD_PATH} |
| 878 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 879 |
endif() |
| 880 |
endforeach() |
| 881 |
endfunction() |
| 882 |
|
| 883 |
# Perform tests against ourself |
| 884 |
create_compress_tests("generic" "") |
| 885 |
create_compress_tests("span" "-k;1024") |
| 886 |
create_compress_tests("zipcd" "-z") |
| 887 |
if(MZ_PKCRYPT) |
| 888 |
create_compress_tests("pkcrypt" "-p;test123") |
| 889 |
endif() |
| 890 |
if(MZ_WZAES) |
| 891 |
create_compress_tests("wzaes" "-s;-p;test123") |
| 892 |
endif() |
| 893 |
|
| 894 |
# Perform tests on others |
| 895 |
if(NOT MZ_COMPRESS_ONLY) |
| 896 |
if(MZ_ZLIB OR MZ_LIBCOMP) |
| 897 |
add_test(NAME unzip-tiny |
| 898 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 899 |
-d ${TEST_TEMP_DIR}/unzip-tiny |
| 900 |
fuzz/unzip_fuzzer_seed_corpus/tiny.zip |
| 901 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 902 |
endif() |
| 903 |
if(MZ_BZIP2) |
| 904 |
add_test(NAME unzip-bzip2 |
| 905 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 906 |
-d ${TEST_TEMP_DIR}/unzip-bzip2 |
| 907 |
fuzz/unzip_fuzzer_seed_corpus/bzip2.zip |
| 908 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 909 |
endif() |
| 910 |
if(MZ_LZMA) |
| 911 |
add_test(NAME unzip-lzma |
| 912 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 913 |
-d ${TEST_TEMP_DIR}/unzip-lzma |
| 914 |
fuzz/unzip_fuzzer_seed_corpus/lzma.zip |
| 915 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 916 |
endif() |
| 917 |
if(MZ_PKCRYPT) |
| 918 |
add_test(NAME unzip-pkcrypt |
| 919 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 920 |
-d ${TEST_TEMP_DIR}/unzip-pkcrypt -p test123 |
| 921 |
fuzz/unzip_fuzzer_seed_corpus/encrypted_pkcrypt.zip |
| 922 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 923 |
endif() |
| 924 |
if(MZ_WZAES) |
| 925 |
add_test(NAME unzip-wzaes |
| 926 |
COMMAND minizip_cli -x -o ${EXTRA_ARGS} |
| 927 |
-d ${TEST_TEMP_DIR}/unzip-wzaes -p test123 |
| 928 |
fuzz/unzip_fuzzer_seed_corpus/encrypted_wzaes.zip |
| 929 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) |
| 930 |
endif() |
| 931 |
endif() |
| 932 |
if(NOT MZ_COMPRESS_ONLY AND NOT MZ_DECOMPRESS_ONLY) |
| 933 |
if(MZ_ZLIB AND NOT MZ_LIBCOMP) |
| 934 |
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/random.bin DESTINATION ${TEST_TEMP_DIR}) |
| 935 |
add_test(NAME gz |
| 936 |
COMMAND minigzip_cli random.bin |
| 937 |
WORKING_DIRECTORY ${TEST_TEMP_DIR}) |
| 938 |
add_test(NAME ungz |
| 939 |
COMMAND minigzip_cli -x -d ${TEST_TEMP_DIR} random.bin.gz |
| 940 |
WORKING_DIRECTORY ${TEST_TEMP_DIR}) |
| 941 |
endif() |
| 942 |
endif() |
| 943 |
endif() |
| 944 |
|
| 945 |
#Build fuzzer executables |
| 946 |
if(MZ_BUILD_FUZZ_TESTS) |
| 947 |
if(CMAKE_C_COMPILER_ID MATCHES "Clang") |
| 948 |
enable_language(CXX) |
| 949 |
|
| 950 |
if(DEFINED ENV{LIB_FUZZING_ENGINE}) |
| 951 |
set(FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE}) |
| 952 |
set(FUZZING_ENGINE_FOUND TRUE) |
| 953 |
else() |
| 954 |
find_library(FUZZING_ENGINE "FuzzingEngine") |
| 955 |
endif() |
| 956 |
endif() |
| 957 |
|
| 958 |
if(NOT FUZZING_ENGINE_FOUND) |
| 959 |
set(FUZZER_SRC "test/fuzz/standalone.c") |
| 960 |
else() |
| 961 |
set(FUZZER_SRC) |
| 962 |
endif() |
| 963 |
|
| 964 |
macro(configure_fuzz_test target) |
| 965 |
add_executable(${target} "test/fuzz/${target}.c" ${FUZZER_SRC}) |
| 966 |
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX) |
| 967 |
target_compile_definitions(${target} PRIVATE ${STDLIB_DEF}) |
| 968 |
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) |
| 969 |
target_link_libraries(${target} ${MINIZIP_TARGET}) |
| 970 |
|
| 971 |
if(FUZZING_ENGINE_FOUND) |
| 972 |
target_link_libraries(${target} ${FUZZING_ENGINE}) |
| 973 |
endif() |
| 974 |
endmacro() |
| 975 |
|
| 976 |
configure_fuzz_test(zip_fuzzer) |
| 977 |
configure_fuzz_test(unzip_fuzzer) |
| 978 |
|
| 979 |
if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL) |
| 980 |
install(TARGETS zip_fuzzer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 981 |
install(TARGETS unzip_fuzzer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 982 |
endif() |
| 983 |
endif() |
| 984 |
|
| 985 |
# Compatibility options |
| 986 |
add_feature_info(MZ_COMPAT MZ_COMPAT "Enables compatibility layer") |
| 987 |
# Compression library options |
| 988 |
add_feature_info(MZ_ZLIB MZ_ZLIB "Enables ZLIB compression") |
| 989 |
add_feature_info(MZ_BZIP2 MZ_BZIP2 "Enables BZIP2 compression") |
| 990 |
add_feature_info(MZ_LZMA MZ_LZMA "Enables LZMA & XZ compression") |
| 991 |
add_feature_info(MZ_ZSTD MZ_ZSTD "Enables ZSTD compression") |
| 992 |
add_feature_info(MZ_LIBCOMP MZ_LIBCOMP "Enables Apple compression") |
| 993 |
add_feature_info(MZ_FETCH_LIBS MZ_FETCH_LIBS "Enables fetching third-party libraries if not found") |
| 994 |
add_feature_info(MZ_FORCE_FETCH_LIBS MZ_FORCE_FETCH_LIBS "Enables fetching third-party libraries always") |
| 995 |
# Encryption support options |
| 996 |
add_feature_info(MZ_PKCRYPT MZ_PKCRYPT "Enables PKWARE traditional encryption") |
| 997 |
add_feature_info(MZ_WZAES MZ_WZAES "Enables WinZIP AES encryption") |
| 998 |
add_feature_info(MZ_OPENSSL MZ_OPENSSL "Enables OpenSSL for encryption") |
| 999 |
add_feature_info(MZ_LIBBSD MZ_LIBBSD "Builds with libbsd crypto random") |
| 1000 |
# Character conversion options |
| 1001 |
add_feature_info(MZ_ICONV MZ_ICONV "Enables iconv string encoding conversion library") |
| 1002 |
# Code generation options |
| 1003 |
add_feature_info(MZ_COMPRESS_ONLY MZ_COMPRESS_ONLY "Only support compression") |
| 1004 |
add_feature_info(MZ_DECOMPRESS_ONLY MZ_DECOMPRESS_ONLY "Only support decompression") |
| 1005 |
add_feature_info(MZ_FILE32_API MZ_FILE32_API "Builds using posix 32-bit file api") |
| 1006 |
# Build and continuous integration options |
| 1007 |
add_feature_info(MZ_BUILD_TESTS MZ_BUILD_TESTS "Builds minizip test executable") |
| 1008 |
add_feature_info(MZ_BUILD_UNIT_TESTS MZ_BUILD_UNIT_TESTS "Builds minizip unit test project") |
| 1009 |
add_feature_info(MZ_BUILD_FUZZ_TESTS MZ_BUILD_FUZZ_TESTS "Builds minizip fuzzer executables") |
| 1010 |
add_feature_info(MZ_CODE_COVERAGE MZ_CODE_COVERAGE "Builds with code coverage flags") |
| 1011 |
|
| 1012 |
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES INCLUDE_QUIET_PACKAGES) |