Added prefix to CMakeList.txt options. #357

This commit is contained in:
Nathan Moinvaziri 2019-01-21 15:18:49 -08:00
parent e51dd48a91
commit cdedc087e7
3 changed files with 91 additions and 89 deletions

View File

@ -13,31 +13,31 @@ matrix:
env: BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_ZLIB=OFF" BUILDDIR="../build"
env: TOOL="-DMZ_ZLIB=OFF" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_BZIP=OFF" BUILDDIR="../build"
env: TOOL="-DMZ_BZIP=OFF" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_LZMA=OFF" BUILDDIR="../build"
env: TOOL="-DMZ_LZMA=OFF" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_WZAES=OFF" BUILDDIR="../build"
env: TOOL="-DMZ_WZAES=OFF" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_PKCRYPT=OFF" BUILDDIR="../build"
env: TOOL="-DMZ_PKCRYPT=OFF" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DCOMPRESS_ONLY=ON" BUILDDIR="../build"
env: TOOL="-DMZ_COMPRESS_ONLY=ON" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DDECOMPRESS_ONLY=ON" BUILDDIR="../build"
env: TOOL="-DMZ_DECOMPRESS_ONLY=ON" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_PKCRYPT=OFF -DUSE_WZAES=OFF" BUILDDIR="../build"
env: TOOL="-DMZ_PKCRYPT=OFF -DMZ_WZAES=OFF" BUILDDIR="../build"
- os: linux
compiler: clang
env: TOOL="-DUSE_OPENSSL=ON" BUILDDIR="../build"
env: TOOL="-DMZ_OPENSSL=ON" BUILDDIR="../build"
- os: linux
compiler: gcc
env: BUILDDIR="../build"
@ -49,13 +49,13 @@ matrix:
env: BUILDDIR="../build"
- os: osx
compiler: clang
env: TOOL="-DUSE_LIBCOMP=ON" BUILDDIR="../build"
env: TOOL="-DMZ_LIBCOMP=ON" BUILDDIR="../build"
- os: osx
compiler: gcc
env: TOOL="-DUSE_LIBCOMP=ON" BUILDDIR="../build"
env: TOOL="-DMZ_LIBCOMP=ON" BUILDDIR="../build"
- os: osx
compiler: clang
env: TOOL="-DUSE_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_INCLUDE_DIRS=/usr/local/opt/openssl/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib" BUILDDIR="../build"
env: TOOL="-DMZ_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_INCLUDE_DIRS=/usr/local/opt/openssl/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib" BUILDDIR="../build"
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libbsd-dev; fi
@ -65,7 +65,7 @@ before_install:
before_script:
- mkdir build
- cd build
- cmake .. -DBUILD_TEST=ON -DBUILD_UNIT_TEST=ON $TOOL
- cmake .. -DMZ_BUILD_TEST=ON -DMZ_BUILD_UNIT_TEST=ON $TOOL
script:
- cmake --build .

View File

@ -8,20 +8,20 @@
cmake_minimum_required(VERSION 3.0.2)
message(STATUS "Using CMake version ${CMAKE_VERSION}")
option(USE_COMPAT "Enables compatibility layer" ON)
option(USE_ZLIB "Enables ZLIB compression" ON)
option(USE_BZIP2 "Enables BZIP2 compression" ON)
option(USE_LZMA "Enables LZMA compression" ON)
option(USE_PKCRYPT "Enables PKWARE traditional encryption" ON)
option(USE_WZAES "Enables WinZIP AES encryption" ON)
option(USE_LIBCOMP "Enables Apple compression" OFF)
option(USE_OPENSSL "Enables OpenSSL for encryption" OFF)
option(USE_BRG "Enables Brian Gladman's encryption library" OFF)
option(COMPRESS_ONLY "Only support compression" OFF)
option(DECOMPRESS_ONLY "Only support decompression" OFF)
option(BUILD_TEST "Builds minizip test executable" OFF)
option(BUILD_UNIT_TEST "Builds minizip unit test project" OFF)
option(BUILD_FUZZ_TEST "Builds minizip fuzzer executables" OFF)
option(MZ_COMPAT "Enables compatibility layer" ON)
option(MZ_ZLIB "Enables ZLIB compression" ON)
option(MZ_BZIP2 "Enables BZIP2 compression" ON)
option(MZ_LZMA "Enables LZMA compression" ON)
option(MZ_PKCRYPT "Enables PKWARE traditional encryption" ON)
option(MZ_WZAES "Enables WinZIP AES encryption" ON)
option(MZ_LIBCOMP "Enables Apple compression" OFF)
option(MZ_OPENSSL "Enables OpenSSL for encryption" OFF)
option(MZ_BRG "Enables Brian Gladman's encryption library" OFF)
option(MZ_COMPRESS_ONLY "Only support compression" OFF)
option(MZ_DECOMPRESS_ONLY "Only support decompression" OFF)
option(MZ_BUILD_TEST "Builds minizip test executable" OFF)
option(MZ_BUILD_UNIT_TEST "Builds minizip unit test project" OFF)
option(MZ_BUILD_FUZZ_TEST "Builds minizip fuzzer executables" OFF)
project("minizip" C)
@ -52,7 +52,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/minizip.pc.cmakein ${MINIZIP_PC} @ONL
set(PROJECT_NAME libminizip)
# Ensure correct version of zlib is referenced
if(USE_ZLIB AND NOT USE_LIBCOMP)
if(MZ_ZLIB AND NOT MZ_LIBCOMP)
set(ZLIB_ROOT ${DEF_ZLIB_ROOT} CACHE PATH "Parent directory of zlib installation")
find_package(ZLIB)
if(ZLIB_FOUND)
@ -103,10 +103,12 @@ if(USE_ZLIB AND NOT USE_LIBCOMP)
else()
set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})
endif()
list(APPEND CMAKE_ARGS "-D${CACHE_VAR}${CACHE_VAR_TYPE}=${${CACHE_VAR}};")
if (NOT CACHE_VAR MATCHES "^MZ_")
list(APPEND CMAKE_ARGS "-D${CACHE_VAR}${CACHE_VAR_TYPE}=${${CACHE_VAR}}")
endif()
endif()
endforeach()
message("${CMAKE_ARGS}")
ExternalProject_Add(zlib
PREFIX zlib
GIT_REPOSITORY ${ZLIB_REPOSITORY}
@ -124,7 +126,7 @@ if(USE_ZLIB AND NOT USE_LIBCOMP)
endif()
# Check if bzip2 installation is present
if(USE_BZIP2)
if(MZ_BZIP2)
set(BZIP2_ROOT ${DEF_BZIP2_ROOT} CACHE PATH "Parent directory of bzip2 installation")
find_package(BZip2)
if(BZIP2_FOUND)
@ -135,7 +137,7 @@ if(USE_BZIP2)
endif()
# Check to see if openssl installation is present
if (USE_OPENSSL)
if (MZ_OPENSSL)
set(OPENSSL_ROOT ${DEF_OPENSSL_ROOT} CACHE PATH "Parent directory of openssl installation")
find_package(OpenSSL)
if (OPENSSL_FOUND)
@ -171,13 +173,13 @@ set(MINIZIP_PUBLIC_HEADERS
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# Setup predefined macros
if(COMPRESS_ONLY)
if(MZ_COMPRESS_ONLY)
add_definitions(-DMZ_ZIP_NO_DECOMPRESSION)
endif()
if(DECOMPRESS_ONLY)
if(MZ_DECOMPRESS_ONLY)
add_definitions(-DMZ_ZIP_NO_COMPRESSION)
endif()
if(NOT USE_PKCRYPT AND NOT USE_WZAES)
if(NOT MZ_PKCRYPT AND NOT MZ_WZAES)
add_definitions(-DMZ_ZIP_NO_ENCRYPTION)
endif()
@ -212,8 +214,8 @@ if(WIN32)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
list(APPEND MINIZIP_SRC "mz_os_win32.c" "mz_strm_os_win32.c")
if (USE_PKCRYPT OR USE_WZAES)
if (NOT USE_OPENSSL AND NOT OPENSSL_FOUND AND NOT USE_BRG)
if (MZ_PKCRYPT OR MZ_WZAES)
if (NOT MZ_OPENSSL AND NOT OPENSSL_FOUND AND NOT MZ_BRG)
list(APPEND MINIZIP_SRC "mz_crypt_win32.c")
endif()
endif()
@ -227,12 +229,12 @@ if(UNIX)
add_definitions(-D_POSIX_C_SOURCE=200112L)
list(APPEND MINIZIP_SRC "mz_os_posix.c" "mz_strm_os_posix.c")
if ((USE_PKCRYPT OR USE_WZAES) AND NOT (USE_OPENSSL AND OPENSSL_FOUND))
if ((MZ_PKCRYPT OR MZ_WZAES) AND NOT (MZ_OPENSSL AND OPENSSL_FOUND))
if (APPLE AND NOT USE_BRG)
if (APPLE AND NOT MZ_BRG)
list(APPEND MINIZIP_SRC "mz_crypt_apple.c")
else()
set(USE_BRG TRUE)
set(MZ_BRG TRUE)
endif()
# Check to see which random generation functions we have
@ -276,7 +278,7 @@ if(UNIX)
endif()
# Include compatibility layer
if(USE_COMPAT)
if(MZ_COMPAT)
list(APPEND MINIZIP_SRC "mz_compat.c")
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_compat.h")
@ -303,7 +305,7 @@ if(USE_COMPAT)
endif()
# Include PKCRYPT
if(USE_PKCRYPT)
if(MZ_PKCRYPT)
add_definitions(-DHAVE_PKCRYPT)
list(APPEND MINIZIP_SRC "mz_strm_pkcrypt.c")
@ -311,7 +313,7 @@ if(USE_PKCRYPT)
endif()
# Include WinZIP AES
if(USE_WZAES)
if(MZ_WZAES)
add_definitions(-DHAVE_WZAES)
list(APPEND MINIZIP_SRC "mz_strm_wzaes.c")
@ -319,7 +321,7 @@ if(USE_WZAES)
endif()
# Include BRG
if(USE_BRG)
if(MZ_BRG)
list(APPEND MINIZIP_SRC "mz_crypt_brg.c")
add_definitions(-DMZ_ZIP_NO_SIGNING)
@ -348,13 +350,13 @@ if(USE_BRG)
endif()
# Include OpenSSL
if(USE_OPENSSL AND OPENSSL_FOUND)
if(MZ_OPENSSL AND OPENSSL_FOUND)
list(APPEND MINIZIP_SRC "mz_crypt_openssl.c")
endif()
# Include ZLIB
if(USE_ZLIB)
if(USE_LIBCOMP)
if(MZ_ZLIB)
if(MZ_LIBCOMP)
add_definitions(-DHAVE_LIBCOMP)
list(APPEND MINIZIP_SRC "mz_strm_libcomp.c")
@ -376,7 +378,7 @@ if(USE_ZLIB)
endif()
# Include BZIP2
if(USE_BZIP2)
if(MZ_BZIP2)
add_definitions(-DHAVE_BZIP2)
list(APPEND MINIZIP_SRC "mz_strm_bzip.c")
@ -405,7 +407,7 @@ if(USE_BZIP2)
endif()
# Include LZMA
if(USE_LZMA)
if(MZ_LZMA)
add_definitions(-DHAVE_LZMA)
add_definitions(-DLZMA_API_STATIC)
add_definitions(-DHAVE_CONFIG_H)
@ -589,7 +591,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
LINKER_LANGUAGE C
PREFIX ""
POSITION_INDEPENDENT_CODE 1)
if(USE_LZMA)
if(MZ_LZMA)
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
endif()
if (MSVC AND BUILD_SHARED_LIBS)
@ -597,25 +599,25 @@ if (MSVC AND BUILD_SHARED_LIBS)
endif ()
# Link with external libraries
if(USE_ZLIB AND NOT USE_LIBCOMP)
if(MZ_ZLIB AND NOT MZ_LIBCOMP)
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
if(NOT ZLIB_FOUND)
add_dependencies(${PROJECT_NAME} zlib)
endif()
endif()
if(USE_BZIP2 AND BZIP2_FOUND)
if(MZ_BZIP2 AND BZIP2_FOUND)
target_link_libraries(${PROJECT_NAME} ${BZIP2_LIBRARIES})
endif()
if(USE_LIBCOMP)
if(MZ_LIBCOMP)
target_link_libraries(${PROJECT_NAME} compression)
endif()
if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN)
target_link_libraries(${PROJECT_NAME} ${Iconv_LIBRARIES})
endif()
if(USE_OPENSSL AND OPENSSL_FOUND)
if(MZ_OPENSSL AND OPENSSL_FOUND)
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES})
elseif(UNIX)
if(APPLE AND NOT USE_BRG)
if(APPLE AND NOT MZ_BRG)
message(STATUS "Using Security Framework")
target_link_libraries(${PROJECT_NAME} "-framework CoreFoundation")
target_link_libraries(${PROJECT_NAME} "-framework Security")
@ -646,7 +648,7 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
endif()
# Build test executable
if(BUILD_TEST)
if(MZ_BUILD_TEST)
add_executable(minizip "minizip.c" "test/test.c" "test/test.h")
target_link_libraries(minizip ${PROJECT_NAME})
@ -655,11 +657,11 @@ if(BUILD_TEST)
endif()
endif()
if(BUILD_UNIT_TEST)
if(MZ_BUILD_UNIT_TEST)
enable_testing()
function(create_compress_tests EXTRA_NAME EXTRA_ARGS)
if(DECOMPRESS_ONLY)
if(MZ_DECOMPRESS_ONLY)
return()
endif()
list(FIND EXTRA_ARGS "-z" ZIPCD_IDX)
@ -667,15 +669,15 @@ if(BUILD_UNIT_TEST)
set(COMPRESS_METHOD_NAMES "raw")
set(COMPRESS_METHOD_ARGS "-0")
endif()
if (USE_ZLIB OR USE_LIBCOMP)
if (MZ_ZLIB OR MZ_LIBCOMP)
list(APPEND COMPRESS_METHOD_NAMES "deflate")
list(APPEND COMPRESS_METHOD_ARGS "-9")
endif()
if (USE_BZIP2)
if (MZ_BZIP2)
list(APPEND COMPRESS_METHOD_NAMES "bzip2")
list(APPEND COMPRESS_METHOD_ARGS "-b")
endif()
if (USE_LZMA)
if (MZ_LZMA)
list(APPEND COMPRESS_METHOD_NAMES "lzma")
list(APPEND COMPRESS_METHOD_ARGS "-m")
endif()
@ -691,7 +693,7 @@ if(BUILD_UNIT_TEST)
add_test(NAME ${COMPRESS_METHOD_NAME}-list-${EXTRA_NAME}
COMMAND minizip -l ${EXTRA_ARGS} result.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
if(NOT COMPRESS_ONLY)
if(NOT MZ_COMPRESS_ONLY)
add_test(NAME ${COMPRESS_METHOD_NAME}-unzip-${EXTRA_NAME}
COMMAND minizip -x -o ${EXTRA_ARGS} -d out result.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
@ -700,7 +702,7 @@ if(BUILD_UNIT_TEST)
COMMAND minizip ${COMPRESS_METHOD_ARG} -a ${EXTRA_ARGS}
result.zip single.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
if(NOT COMPRESS_ONLY)
if(NOT MZ_COMPRESS_ONLY)
add_test(NAME ${COMPRESS_METHOD_NAME}-append-unzip-${EXTRA_NAME}
COMMAND minizip -x -o ${EXTRA_ARGS} -d out result.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
@ -708,7 +710,7 @@ if(BUILD_UNIT_TEST)
add_test(NAME ${COMPRESS_METHOD_NAME}-erase-${EXTRA_NAME}
COMMAND minizip -o -e result.zip test.c test.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
if(NOT COMPRESS_ONLY)
if(NOT MZ_COMPRESS_ONLY)
add_test(NAME ${COMPRESS_METHOD_NAME}-erase-unzip-${EXTRA_NAME}
COMMAND minizip -x -o ${EXTRA_ARGS} -d out result.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
@ -720,43 +722,43 @@ if(BUILD_UNIT_TEST)
create_compress_tests("generic" "")
create_compress_tests("span" "-k;1024")
create_compress_tests("zipcd" "-z")
if(USE_PKCRYPT)
if(MZ_PKCRYPT)
create_compress_tests("pkcrypt" "-p;test123")
endif()
if(USE_WZAES)
if(MZ_WZAES)
create_compress_tests("wzaes" "-s;-p;test123")
endif()
if(USE_OPENSSL AND OPENSSL_FOUND)
if(MZ_OPENSSL AND OPENSSL_FOUND)
create_compress_tests("signed" "-h;ia.p12;-w;test")
create_compress_tests("secure" "-z;-h;ia.p12;-w;test")
endif()
# Perform tests on others
if(NOT COMPRESS_ONLY)
if(USE_ZLIB)
if(NOT MZ_COMPRESS_ONLY)
if(MZ_ZLIB)
add_test(NAME unzip-tiny
COMMAND minizip -x -o ${EXTRA_ARGS} -d out
fuzz/unzip_fuzzer_seed_corpus/tiny.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()
if(USE_BZIP2)
if(MZ_BZIP2)
add_test(NAME unzip-bzip2
COMMAND minizip -x -o ${EXTRA_ARGS} -d out
fuzz/unzip_fuzzer_seed_corpus/bzip2.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()
if(USE_LZMA)
if(MZ_LZMA)
add_test(NAME unzip-lzma
COMMAND minizip -x -o ${EXTRA_ARGS} -d out
fuzz/unzip_fuzzer_seed_corpus/lzma.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()
if(USE_PKCRYPT)
if(MZ_PKCRYPT)
add_test(NAME unzip-pkcrypt
COMMAND minizip -x -o ${EXTRA_ARGS} -d out -p test123
fuzz/unzip_fuzzer_seed_corpus/encrypted_pkcrypt.zip
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()
if(USE_WZAES)
if(MZ_WZAES)
add_test(NAME unzip-wzaes
COMMAND minizip -x -o ${EXTRA_ARGS} -d out -p test123
fuzz/unzip_fuzzer_seed_corpus/encrypted_wzaes.zip
@ -767,7 +769,7 @@ if(BUILD_UNIT_TEST)
endif()
#Build fuzzer executables
if(BUILD_FUZZ_TEST)
if(MZ_BUILD_FUZZ_TEST)
if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(FUZZER_SRC "test/fuzz/standalone.c")
endif()

View File

@ -61,7 +61,7 @@ To generate project files for your platform:
2. Run cmake in the minizip directory.
```
cmake . -DBUILD_TEST=ON
cmake . -DMZ_BUILD_TEST=ON
cmake --build .
```
@ -69,20 +69,20 @@ cmake --build .
| Name | Description | Default Value |
|:- |:-|:-:|
| USE_COMPAT | Enables compatibility layer | ON |
| USE_ZLIB | Enables ZLIB compression | ON |
| USE_BZIP2 | Enables BZIP2 compression | ON |
| USE_LZMA | Enables LZMA compression | ON |
| USE_PKCRYPT | Enables PKWARE traditional encryption | ON |
| USE_WZAES | Enables WinZIP AES encryption | ON |
| USE_LIBCOMP | Enables Apple compression | OFF |
| USE_OPENSSL | Enables OpenSSL encryption | OFF |
| USE_BRG | Enables Brian Gladman's library | OFF |
| COMPRESS_ONLY | Only support compression | OFF |
| DECOMPRESS_ONLY | Only support decompression | OFF |
| BUILD_TEST | Builds minizip test executable | OFF |
| BUILD_UNIT_TEST | Builds minizip unit test project | OFF |
| BUILD_FUZZ_TEST | Builds minizip fuzz executables | OFF |
| MZ_COMPAT | Enables compatibility layer | ON |
| MZ_ZLIB | Enables ZLIB compression | ON |
| MZ_BZIP2 | Enables BZIP2 compression | ON |
| MZ_LZMA | Enables LZMA compression | ON |
| MZ_PKCRYPT | Enables PKWARE traditional encryption | ON |
| MZ_WZAES | Enables WinZIP AES encryption | ON |
| MZ_LIBCOMP | Enables Apple compression | OFF |
| MZ_OPENSSL | Enables OpenSSL encryption | OFF |
| MZ_BRG | Enables Brian Gladman's library | OFF |
| MZ_COMPRESS_ONLY | Only support compression | OFF |
| MZ_DECOMPRESS_ONLY | Only support decompression | OFF |
| MZ_BUILD_TEST | Builds minizip test executable | OFF |
| MZ_BUILD_UNIT_TEST | Builds minizip unit test project | OFF |
| MZ_BUILD_FUZZ_TEST | Builds minizip fuzz executables | OFF |
## Contents