-cmake_minimum_required(VERSION 3.12...3.29.0)
+cmake_minimum_required(VERSION 3.14...3.31.0)
message(STATUS "Using CMake version ${CMAKE_VERSION}")
if(POLICY CMP0169)
include(CheckCCompilerFlag)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
+include(CTest)
include(FeatureSummary)
# We need to enable C++ before trying to check for coverage
-option(ZLIB_ENABLE_TESTS "Build test binaries" ON)
-cmake_dependent_option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON "ZLIB_ENABLE_TESTS" OFF)
-cmake_dependent_option(WITH_GTEST "Build gtest_zlib" ON "ZLIB_ENABLE_TESTS" OFF)
-cmake_dependent_option(WITH_FUZZERS "Build test/fuzz" OFF "ZLIB_ENABLE_TESTS" OFF)
-cmake_dependent_option(WITH_BENCHMARKS "Build test/benchmarks" OFF "ZLIB_ENABLE_TESTS" OFF)
-cmake_dependent_option(WITH_BENCHMARK_APPS "Build application benchmarks" OFF "WITH_BENCHMARKS" OFF)
+option(BUILD_TESTING "Build test binaries." ON) # Depends on CMP0077 (3.13)
+if (DEFINED ZLIB_ENABLE_TESTS)
+ message(DEPRECATION "ZLIB_ENABLE_TESTS is deprecated. Please use BUILD_TESTING instead.")
+ if (NOT ZLIB_ENABLE_TESTS)
+ set(BUILD_TESTING OFF)
+ endif()
+endif()
+cmake_dependent_option(WITH_GTEST "Build gtest_zlib" ON "BUILD_TESTING" OFF)
+cmake_dependent_option(WITH_FUZZERS "Build test/fuzz" OFF "BUILD_TESTING" OFF)
+cmake_dependent_option(WITH_BENCHMARKS "Build test/benchmarks" OFF "BUILD_TESTING" OFF)
+cmake_dependent_option(WITH_BENCHMARK_APPS "Build application benchmarks" OFF "BUILD_TESTING" OFF)
if(WITH_GTEST OR WITH_FUZZERS OR WITH_BENCHMARKS)
enable_language(CXX)
# Example binaries
#============================================================================
-if(ZLIB_ENABLE_TESTS)
+if(BUILD_TESTING)
enable_testing()
if(BUILD_SHARED_LIBS)
- if(ZLIBNG_ENABLE_TESTS)
- message(STATUS "Disabling zlib-ng tests because shared libraries are enabled")
- set(ZLIBNG_ENABLE_TESTS OFF)
+ if(WITH_GTEST)
+ message(STATUS "Disabling gtest because only shared libraries are enabled")
+ set(WITH_GTEST OFF)
endif()
if(WITH_BENCHMARKS OR WITH_BENCHMARK_APPS)
- message(STATUS "Disabling benchmarks because shared libraries are enabled")
+ message(STATUS "Disabling google benchmarks because only shared libraries are enabled")
set(WITH_BENCHMARKS OFF)
set(WITH_BENCHMARK_APPS OFF)
endif()
add_feature_info(WITH_GZFILEOP WITH_GZFILEOP "Compile with support for gzFile related functions")
add_feature_info(ZLIB_COMPAT ZLIB_COMPAT "Compile with zlib compatible API")
add_feature_info(ZLIB_ALIASES ZLIB_ALIASES "Compile with zlib compatible CMake targets")
-add_feature_info(ZLIB_ENABLE_TESTS ZLIB_ENABLE_TESTS "Enable options for building tests")
-add_feature_info(ZLIBNG_ENABLE_TESTS ZLIBNG_ENABLE_TESTS "Build test binaries")
-add_feature_info(WITH_SANITIZER WITH_SANITIZER "Enable sanitizer support")
+add_feature_info(BUILD_TESTING BUILD_TESTING "Build test binaries")
+add_feature_info(WITH_SANITIZER WITH_SANITIZER "Enable sanitizer testing support")
add_feature_info(WITH_GTEST WITH_GTEST "Build tests using Gtest framework")
add_feature_info(WITH_FUZZERS WITH_FUZZERS "Build test/fuzz")
add_feature_info(WITH_BENCHMARKS WITH_BENCHMARKS "Build benchmarks using Google Benchmark framework")
|:---------------------------|:-------------------------|:------------------------------------------------------------------------------------|---------|
| ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF |
| ZLIB_ALIASES | | Provide zlib compatible CMake targets | ON |
-| ZLIB_ENABLE_TESTS | | Tests masterswitch, does not enable any tests by itself | ON |
-| ZLIBNG_ENABLE_TESTS | | Build test binaries | ON |
| WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON |
| WITH_OPTIM | --without-optimizations | Build with optimisations | ON |
| WITH_NEW_STRATEGIES | --without-new-strategies | Use new strategies | ON |
| WITH_GTEST | | Build tests using GTest framework | ON |
| WITH_BENCHMARKS | | Build benchmarks using Google Benchmark framework | OFF |
| INSTALL_UTILS | | Copy minigzip and minideflate during install | OFF |
+| BUILD_TESTING | | Build test binaries | ON |
Install
endif()
endmacro()
-if(ZLIBNG_ENABLE_TESTS)
- add_definitions(-DZLIBNG_ENABLE_TESTS)
+if(TEST_STOCK_ZLIB)
+ add_definitions(-DTEST_STOCK_ZLIB)
endif()
add_executable(example example.c)
if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
target_sources(infcover PRIVATE ${PROJECT_SOURCE_DIR}/inftrees.c)
endif()
-# infcover references zng_inflate_table() and struct inflate_state, which are internal to zlib-ng.
-if(ZLIBNG_ENABLE_TESTS)
- add_test(NAME infcover COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:infcover>)
-endif()
+add_test(NAME infcover COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:infcover>)
add_executable(makefixed ${PROJECT_SOURCE_DIR}/tools/makefixed.c ${PROJECT_SOURCE_DIR}/inftrees.c)
configure_test_executable(makefixed)
list(APPEND TEST_SRCS test_gzio.cc)
endif()
- if(ZLIBNG_ENABLE_TESTS)
+ if(NOT TEST_STOCK_ZLIB)
list(APPEND TEST_SRCS
test_adler32.cc # adler32_neon(), etc
test_compare256.cc # compare256_neon(), etc
include(CTest)
set(BUILD_SHARED_LIBS OFF)
-set(ZLIB_ENABLE_TESTS ON CACHE BOOL "Build test binaries" FORCE)
+set(BUILD_TESTING ON CACHE BOOL "Build test binaries" FORCE)
add_subdirectory(../.. zlib-ng)
*comprLen = (z_size_t)c_stream.total_out;
}
-#ifdef ZLIBNG_ENABLE_TESTS
+#ifndef TEST_STOCK_ZLIB
/* ===========================================================================
* Test inflateSync()
* We expect a certain compressed block layout, so skip this with the original zlib.
#endif
test_flush(compr, &comprLen);
-#ifdef ZLIBNG_ENABLE_TESTS
+#ifndef TEST_STOCK_ZLIB
test_sync(compr, comprLen, uncompr, uncomprLen);
#endif
comprLen = uncomprLen;
target_link_libraries(${FUZZER} ${FUZZING_ENGINE})
endif()
- if(ZLIB_ENABLE_TESTS)
- file(GLOB FUZZER_TEST_FILES ${PROJECT_SOURCE_DIR}/*)
- set(FUZZER_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${FUZZER}> ${FUZZER_TEST_FILES})
- add_test(NAME ${FUZZER} COMMAND ${FUZZER_COMMAND})
- endif()
+ file(GLOB FUZZER_TEST_FILES ${PROJECT_SOURCE_DIR}/*)
+ set(FUZZER_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${FUZZER}> ${FUZZER_TEST_FILES})
+ add_test(NAME ${FUZZER} COMMAND ${FUZZER_COMMAND})
endforeach()
inf("63 18 5 40 c 0", "window wrap", 3, -8, 300, Z_OK);
}
+#ifndef TEST_STOCK_ZLIB
/* cover remaining lines in inftrees.c */
static void cover_trees(void) {
int ret;
fputs("inflate_table not enough errors\n", stderr);
Z_UNUSED(ret);
}
+#endif
/* cover remaining inffast.c decoding and window copying */
static void cover_fast(void) {
cover_wrap();
cover_back();
cover_inflate();
+#ifndef TEST_STOCK_ZLIB
cover_trees();
+#endif
cover_fast();
cover_cve_2022_37434();
return 0;
static inline int deflate_prime_32(PREFIX3(stream) *stream, uint32_t value) {
int err;
-#ifdef ZLIBNG_ENABLE_TESTS
+#ifndef TEST_STOCK_ZLIB
err = PREFIX(deflatePrime)(stream, 32, value);
#else
/* zlib's deflatePrime() takes at most 16 bits */