Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Make options consistent #422

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 41 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ project(libzip
VERSION 1.10.1
LANGUAGES C)

option(ENABLE_COMMONCRYPTO "Enable use of CommonCrypto" ON)
option(ENABLE_GNUTLS "Enable use of GnuTLS" ON)
option(ENABLE_MBEDTLS "Enable use of mbed TLS" ON)
option(ENABLE_OPENSSL "Enable use of OpenSSL" ON)
option(ENABLE_WINDOWS_CRYPTO "Enable use of Windows cryptography libraries" ON)
option(LIBZIP_ENABLE_COMMONCRYPTO "Enable use of CommonCrypto" ON)
option(LIBZIP_ENABLE_GNUTLS "Enable use of GnuTLS" ON)
option(LIBZIP_ENABLE_MBEDTLS "Enable use of mbed TLS" ON)
option(LIBZIP_ENABLE_OPENSSL "Enable use of OpenSSL" ON)
option(LIBZIP_ENABLE_WINDOWS_CRYPTO "Enable use of Windows cryptography libraries" ON)

option(ENABLE_BZIP2 "Enable use of BZip2" ON)
option(ENABLE_LZMA "Enable use of LZMA" ON)
option(ENABLE_ZSTD "Enable use of Zstandard" ON)
option(LIBZIP_ENABLE_BZIP2 "Enable use of BZip2" ON)
option(LIBZIP_ENABLE_LZMA "Enable use of LZMA" ON)
option(LIBZIP_ENABLE_ZSTD "Enable use of Zstandard" ON)

option(ENABLE_FDOPEN "Enable zip_fdopen, which is not allowed in Microsoft CRT secure libraries" ON)
option(LIBZIP_ENABLE_FDOPEN "Enable zip_fdopen, which is not allowed in Microsoft CRT secure libraries" ON)

option(BUILD_TOOLS "Build tools in the src directory (zipcmp, zipmerge, ziptool)" ON)
option(BUILD_REGRESS "Build regression tests" ON)
option(BUILD_OSSFUZZ "Build fuzzers for ossfuzz" ON)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_DOC "Build documentation" ON)
option(LIBZIP_BUILD_TOOLS "Build tools in the src directory (zipcmp, zipmerge, ziptool)" ON)
option(LIBZIP_BUILD_REGRESS "Build regression tests" ON)
option(LIBZIP_BUILD_OSSFUZZ "Build fuzzers for ossfuzz" ON)
option(LIBZIP_BUILD_EXAMPLES "Build examples" ON)
option(LIBZIP_BUILD_DOC "Build documentation" ON)

include(CheckFunctionExists)
include(CheckIncludeFiles)
Expand All @@ -38,39 +38,39 @@ include(CheckStructHasMember)
include(TestBigEndian)
include(GNUInstallDirs)

if(ENABLE_COMMONCRYPTO)
if(LIBZIP_ENABLE_COMMONCRYPTO)
check_include_files(CommonCrypto/CommonCrypto.h COMMONCRYPTO_FOUND)
endif()
if(ENABLE_GNUTLS)
if(LIBZIP_ENABLE_GNUTLS)
find_package(Nettle 3.0)
find_package(GnuTLS)
endif()
if(ENABLE_MBEDTLS)
if(LIBZIP_ENABLE_MBEDTLS)
find_package(MbedTLS 1.0)
endif()
if(ENABLE_OPENSSL)
if(LIBZIP_ENABLE_OPENSSL)
find_package(OpenSSL)
endif()
if(WIN32)
if(ENABLE_WINDOWS_CRYPTO)
if(LIBZIP_ENABLE_WINDOWS_CRYPTO)
set(WINDOWS_CRYPTO_FOUND TRUE)
endif()
endif()

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(LIBZIP_DO_INSTALL "Install libzip and the related files" ON)

option(SHARED_LIB_VERSIONNING "Add SO version in .so build" ON)
option(LIBZIP_SHARED_LIB_VERSIONING "Add SO version in .so build" ON)

find_program(MDOCTOOL NAMES mandoc groff)
if (MDOCTOOL)
set(DOCUMENTATION_FORMAT "mdoc" CACHE STRING "Documentation format")
set(LIBZIP_DOCUMENTATION_FORMAT "mdoc" CACHE STRING "Documentation format")
else()
find_program(MANTOOL NAMES nroff)
if (MANTOOL)
set(DOCUMENTATION_FORMAT "man" CACHE STRING "Documentation format")
set(LIBZIP_DOCUMENTATION_FORMAT "man" CACHE STRING "Documentation format")
else()
set(DOCUMENTATION_FORMAT "html" CACHE STRING "Documentation format")
set(LIBZIP_DOCUMENTATION_FORMAT "html" CACHE STRING "Documentation format")
endif()
endif()

Expand Down Expand Up @@ -221,25 +221,25 @@ if (NOT ZLIB_LINK_LIBRARY_NAME)
endif()
endif(NOT ZLIB_LINK_LIBRARY_NAME)

if(ENABLE_BZIP2)
if(LIBZIP_ENABLE_BZIP2)
find_package(BZip2)
if(BZIP2_FOUND)
set(HAVE_LIBBZ2 1)
else()
message(WARNING "-- bzip2 library not found; bzip2 support disabled")
endif(BZIP2_FOUND)
endif(ENABLE_BZIP2)
endif(LIBZIP_ENABLE_BZIP2)

if(ENABLE_LZMA)
if(LIBZIP_ENABLE_LZMA)
find_package(LibLZMA 5.2)
if(LIBLZMA_FOUND)
set(HAVE_LIBLZMA 1)
else()
message(WARNING "-- lzma library not found; lzma/xz support disabled")
endif(LIBLZMA_FOUND)
endif(ENABLE_LZMA)
endif(LIBZIP_ENABLE_LZMA)

if(ENABLE_ZSTD)
if(LIBZIP_ENABLE_ZSTD)
find_package(zstd 1.3.6)
if(zstd_FOUND)
set(HAVE_LIBZSTD 1)
Expand All @@ -251,7 +251,7 @@ if(ENABLE_ZSTD)
else()
message(WARNING "-- zstd library not found; zstandard support disabled")
endif(zstd_FOUND)
endif(ENABLE_ZSTD)
endif(LIBZIP_ENABLE_ZSTD)

if (COMMONCRYPTO_FOUND)
set(HAVE_CRYPTO 1)
Expand All @@ -270,7 +270,7 @@ elseif (MBEDTLS_FOUND)
set(HAVE_MBEDTLS 1)
endif()

if ((ENABLE_COMMONCRYPTO OR ENABLE_GNUTLS OR ENABLE_MBEDTLS OR ENABLE_OPENSSL OR ENABLE_WINDOWS_CRYPTO) AND NOT HAVE_CRYPTO)
if ((LIBZIP_ENABLE_COMMONCRYPTO OR LIBZIP_ENABLE_GNUTLS OR LIBZIP_ENABLE_MBEDTLS OR LIBZIP_ENABLE_OPENSSL OR LIBZIP_ENABLE_WINDOWS_CRYPTO) AND NOT HAVE_CRYPTO)
message(WARNING "-- neither Common Crypto, GnuTLS, mbed TLS, OpenSSL, nor Windows Cryptography found; AES support disabled")
endif()

Expand Down Expand Up @@ -300,35 +300,35 @@ ENABLE_TESTING()
# Targets
ADD_SUBDIRECTORY(lib)

if(BUILD_DOC)
if(LIBZIP_BUILD_DOC)
ADD_SUBDIRECTORY(man)
endif()

if(BUILD_TOOLS)
if(LIBZIP_BUILD_TOOLS)
ADD_SUBDIRECTORY(src)
else(BUILD_TOOLS)
if(BUILD_REGRESS)
else(LIBZIP_BUILD_TOOLS)
if(LIBZIP_BUILD_REGRESS)
message(WARNING "-- tools build has been disabled, but they are needed for regression tests; regression testing disabled")
set(BUILD_REGRESS OFF)
endif(BUILD_REGRESS)
set(LIBZIP_BUILD_REGRESS OFF)
endif(LIBZIP_BUILD_REGRESS)
endif()

find_program(NIHTEST nihtest)

if(BUILD_REGRESS AND NOT NIHTEST)
if(LIBZIP_BUILD_REGRESS AND NOT NIHTEST)
message(WARNING "-- nihtest not found, regression testing disabled")
set(BUILD_REGRESS OFF)
set(LIBZIP_BUILD_REGRESS OFF)
endif()

if(BUILD_REGRESS)
if(LIBZIP_BUILD_REGRESS)
add_subdirectory(regress)
endif()

if(BUILD_OSSFUZZ)
if(LIBZIP_BUILD_OSSFUZZ)
add_subdirectory(ossfuzz)
endif()

if(BUILD_EXAMPLES)
if(LIBZIP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ listed in order of preference:
- [mbed TLS](https://tls.mbed.org/)

If you don't want a library even if it is installed, you can
pass `-DENABLE_<LIBRARY>=OFF` to cmake, where `<LIBRARY>` is one of
pass `-DLIBZIP_ENABLE_<LIBRARY>=OFF` to cmake, where `<LIBRARY>` is one of
`COMMONCRYPTO`, `GNUTLS`, `MBEDTLS`, or `OPENSSL`.

For running the tests, you need to have
Expand All @@ -44,7 +44,7 @@ Some useful parameters you can pass to `cmake` with `-Dparameter=value`:
- `BUILD_SHARED_LIBS`: set to `ON` or `OFF` to enable/disable building
of shared libraries, defaults to `ON`
- `CMAKE_INSTALL_PREFIX`: for setting the installation path
- `DOCUMENTATION_FORMAT`: choose one of `man`, `mdoc`, and `html` for
- `LIBZIP_DOCUMENTATION_FORMAT`: choose one of `man`, `mdoc`, and `html` for
the installed documentation (default: decided by cmake depending on
available tools)
- `LIBZIP_DO_INSTALL`: If you include libzip as a subproject, link it
Expand Down
20 changes: 10 additions & 10 deletions android/do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ build_it()
cmake -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/../../${INSTALL_DIR}/${ANDROID_TARGET_PLATFORM} \
-DANDROID_ABI=${ANDROID_TARGET_PLATFORM} \
-DENABLE_OPENSSL:BOOL=OFF \
-DENABLE_COMMONCRYPTO:BOOL=OFF \
-DENABLE_GNUTLS:BOOL=OFF \
-DENABLE_MBEDTLS:BOOL=OFF \
-DENABLE_OPENSSL:BOOL=OFF \
-DENABLE_WINDOWS_CRYPTO:BOOL=OFF \
-DBUILD_TOOLS:BOOL=OFF \
-DBUILD_REGRESS:BOOL=OFF \
-DBUILD_EXAMPLES:BOOL=OFF \
-DLIBZIP_ENABLE_OPENSSL:BOOL=OFF \
-DLIBZIP_ENABLE_COMMONCRYPTO:BOOL=OFF \
-DLIBZIP_ENABLE_GNUTLS:BOOL=OFF \
-DLIBZIP_ENABLE_MBEDTLS:BOOL=OFF \
-DLIBZIP_ENABLE_OPENSSL:BOOL=OFF \
-DLIBZIP_ENABLE_WINDOWS_CRYPTO:BOOL=OFF \
-DLIBZIP_BUILD_TOOLS:BOOL=OFF \
-DLIBZIP_BUILD_REGRESS:BOOL=OFF \
-DLIBZIP_BUILD_EXAMPLES:BOOL=OFF \
-DBUILD_SHARED_LIBS:BOOL=$want_shared \
-DBUILD_DOC:BOOL=OFF \
-DLIBZIP_BUILD_DOC:BOOL=OFF \
-DANDROID_TOOLCHAIN=clang cmake -H.. -B$BUILD_DIR/${ANDROID_TARGET_PLATFORM}

#run make with all system threads and install
Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ environment:
- GENERATOR: "Visual Studio 16 2019"
PLATFORM: ARM
TRIPLET: arm-windows
CMAKE_OPTS: "-DENABLE_OPENSSL=off"
CMAKE_OPTS: "-DLIBZIP_ENABLE_OPENSSL=off"
CMAKE_CONFIG: Release
RUN_TESTS: no
TOXENV: py311
- GENERATOR: "Visual Studio 16 2019"
PLATFORM: ARM
TRIPLET: arm-uwp
CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DENABLE_OPENSSL=off"
CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DLIBZIP_ENABLE_OPENSSL=off"
CMAKE_CONFIG: Release
RUN_TESTS: no
TOXENV: py311
- GENERATOR: "Visual Studio 16 2019"
PLATFORM: ARM64
TRIPLET: arm64-windows
CMAKE_OPTS: "-DENABLE_OPENSSL=off"
CMAKE_OPTS: "-DLIBZIP_ENABLE_OPENSSL=off"
CMAKE_CONFIG: Release
RUN_TESTS: no
TOXENV: py311
- GENERATOR: "Visual Studio 16 2019"
PLATFORM: ARM64
TRIPLET: arm64-uwp
CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DENABLE_OPENSSL=off"
CMAKE_OPTS: "-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DLIBZIP_ENABLE_OPENSSL=off"
CMAKE_CONFIG: Release
RUN_TESTS: no
TOXENV: py311
Expand Down
2 changes: 1 addition & 1 deletion cmake-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "zipconf.h"
#endif
/* BEGIN DEFINES */
#cmakedefine ENABLE_FDOPEN
#cmakedefine LIBZIP_ENABLE_FDOPEN
#cmakedefine HAVE___PROGNAME
#cmakedefine HAVE__CLOSE
#cmakedefine HAVE__DUP
Expand Down
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ if(HAVE_CRYPTO)
target_sources(zip PRIVATE zip_winzip_aes.c zip_source_winzip_aes_decode.c zip_source_winzip_aes_encode.c)
endif()

if(SHARED_LIB_VERSIONNING)
if(LIBZIP_SHARED_LIB_VERSIONING)
# MACHO_*_VERSION can be removed when SOVERSION gets increased. Cf #405
set_target_properties(zip PROPERTIES VERSION 5.5 SOVERSION 5 MACHO_CURRENT_VERSION 6.5 MACHO_COMPATIBILITY_VERSION 6)
endif()
Expand Down
2 changes: 1 addition & 1 deletion lib/zip_fdopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ zip_fdopen(int fd_orig, int _flags, int *zep) {
return NULL;
}

#ifndef ENABLE_FDOPEN
#ifndef LIBZIP_ENABLE_FDOPEN
_zip_set_open_error(zep, NULL, ZIP_ER_OPNOTSUPP);
return NULL;
#else
Expand Down
24 changes: 12 additions & 12 deletions libzip-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ if (NOT IS_SHARED)
include(CMakeFindDependencyMacro)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/modules")

set(ENABLE_BZIP2 @BZIP2_FOUND@)
set(ENABLE_LZMA @LIBLZMA_FOUND@)
set(ENABLE_ZSTD @ZSTD_FOUND@)
set(ENABLE_GNUTLS @GNUTLS_FOUND@)
set(ENABLE_MBEDTLS @MBEDTLS_FOUND@)
set(ENABLE_OPENSSL @OPENSSL_FOUND@)
set(LIBZIP_ENABLE_BZIP2 @BZIP2_FOUND@)
set(LIBZIP_ENABLE_LZMA @LIBLZMA_FOUND@)
set(LIBZIP_ENABLE_ZSTD @ZSTD_FOUND@)
set(LIBZIP_ENABLE_GNUTLS @GNUTLS_FOUND@)
set(LIBZIP_ENABLE_MBEDTLS @MBEDTLS_FOUND@)
set(LIBZIP_ENABLE_OPENSSL @OPENSSL_FOUND@)

find_dependency(ZLIB 1.1.2)
if(ENABLE_BZIP2)
if(LIBZIP_ENABLE_BZIP2)
find_dependency(BZip2)
endif()

if(ENABLE_LZMA)
if(LIBZIP_ENABLE_LZMA)
find_dependency(LibLZMA 5.2)
endif()

if(ENABLE_ZSTD)
if(LIBZIP_ENABLE_ZSTD)
find_dependency(zstd 1.3.6)
endif()

if(ENABLE_GNUTLS)
if(LIBZIP_ENABLE_GNUTLS)
find_dependency(Nettle 3.0)
find_dependency(GnuTLS)
endif()
if(ENABLE_MBEDTLS)
if(LIBZIP_ENABLE_MBEDTLS)
find_dependency(MbedTLS 1.0)
endif()
if(ENABLE_OPENSSL)
if(LIBZIP_ENABLE_OPENSSL)
find_dependency(OpenSSL)
endif()
endif()
Expand Down
6 changes: 3 additions & 3 deletions man/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ set(MAN_PAGES
)

foreach(MAN_PAGE ${MAN_PAGES})
string(REGEX REPLACE "[1-9]$" "${DOCUMENTATION_FORMAT}" SOURCE_FILE ${MAN_PAGE})
string(REGEX REPLACE "[1-9]$" "${LIBZIP_DOCUMENTATION_FORMAT}" SOURCE_FILE ${MAN_PAGE})
if(LIBZIP_DO_INSTALL)
if (DOCUMENTATION_FORMAT MATCHES "html")
if (LIBZIP_DOCUMENTATION_FORMAT MATCHES "html")
install(FILES ${PROJECT_BINARY_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME} RENAME ${SOURCE_FILE})
else()
string(REGEX REPLACE ".*(.)$" "man\\1" SUBDIR ${MAN_PAGE})
Expand Down Expand Up @@ -153,7 +153,7 @@ foreach(LINKS_LINE ${MANPAGE_LINKS})
set(SOURCE ${CMAKE_MATCH_1})
set(TARGET ${CMAKE_MATCH_2})
if(LIBZIP_DO_INSTALL)
if (DOCUMENTATION_FORMAT MATCHES "html")
if (LIBZIP_DOCUMENTATION_FORMAT MATCHES "html")
INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME} RENAME ${TARGET}.html)
else()
INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 RENAME ${TARGET}.3)
Expand Down
2 changes: 1 addition & 1 deletion ossfuzz/ossfuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=OFF -DENABLE_GNUTLS=OFF -DENABLE_MBEDTLS=OFF -DENABLE_OPENSSL=ON -DBUILD_TOOLS=OFF -DHAVE_CRYPTO=ON ..
cmake -DBUILD_SHARED_LIBS=OFF -DLIBZIP_ENABLE_GNUTLS=OFF -DLIBZIP_ENABLE_MBEDTLS=OFF -DLIBZIP_ENABLE_OPENSSL=ON -DLIBZIP_BUILD_TOOLS=OFF -DHAVE_CRYPTO=ON ..
make -j$(nproc)

for fuzzer in $(make list-fuzzers | sed -n 's/^FUZZERS: //p')
Expand Down