Merge pull request #316 from zhaozg/fix/stdio

cmake: new option BUILD_NO_STDIO to enable MINIZ_NO_STDIO
This commit is contained in:
Martin Raiber 2024-10-17 20:11:01 +02:00 committed by GitHub
commit 35528ad769
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 24 deletions

View File

@ -42,6 +42,7 @@ option(BUILD_FUZZERS "Build fuzz targets" OFF)
option(AMALGAMATE_SOURCES "Amalgamate sources into miniz.h/c" OFF)
option(BUILD_HEADER_ONLY "Build a header-only version" OFF)
option(BUILD_SHARED_LIBS "Build shared library instead of static" OFF)
option(BUILD_NO_STDIO" Build a without stdio version" OFF)
option(BUILD_TESTS "Build tests" ${MINIZ_STANDALONE_PROJECT})
option(INSTALL_PROJECT "Install project" ${MINIZ_STANDALONE_PROJECT})
@ -178,6 +179,10 @@ if(NOT BUILD_HEADER_ONLY)
endif()
endif()
if(BUILD_NO_STDIO)
target_compile_definitions(${PROJECT_NAME} PRIVATE MINIZ_NO_STDIO)
endif()
set_property(TARGET ${PROJECT_NAME} PROPERTY
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${MINIZ_API_VERSION})
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY
@ -242,8 +247,10 @@ if(BUILD_EXAMPLES)
add_executable(example1 ${EXAMPLE1_SRC_LIST})
target_link_libraries(example1 miniz)
add_executable(example2 ${EXAMPLE2_SRC_LIST})
target_link_libraries(example2 miniz)
if(NOT BUILD_NO_STDIO)
add_executable(example2 ${EXAMPLE2_SRC_LIST})
target_link_libraries(example2 miniz)
endif()
add_executable(example3 ${EXAMPLE3_SRC_LIST})
target_link_libraries(example3 miniz)
add_executable(example4 ${EXAMPLE4_SRC_LIST})
@ -298,17 +305,18 @@ if(BUILD_FUZZERS)
endif()
if(BUILD_TESTS)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
add_executable(catch_tests tests/main.cpp
tests/catch_amalgamated.cpp)
target_link_libraries(catch_tests miniz)
add_executable(catch_tests tests/main.cpp tests/catch_amalgamated.cpp)
if(BUILD_NO_STDIO)
target_compile_definitions(catch_tests PRIVATE -DMINIZ_NO_STDIO)
endif()
target_link_libraries(catch_tests miniz)
enable_testing()
enable_testing()
add_test(NAME catch_tests
COMMAND $<TARGET_FILE:catch_tests>)
add_test(NAME catch_tests COMMAND $<TARGET_FILE:catch_tests>)
endif()
set(INCLUDE_INSTALL_DIR "include")

View File

@ -5,8 +5,11 @@
#ifdef _WIN32
#define unlink _unlink
#else
#include <unistd.h>
#endif
#ifndef MINIZ_NO_STDIO
bool create_test_zip()
{
unlink("test.zip");
@ -79,6 +82,7 @@ TEST_CASE("Zip writer tests")
}
}
}
#endif
TEST_CASE("Tinfl / tdefl tests")
{