From ac9dae7fac9d63e4d29ff6476176df01e9034d59 Mon Sep 17 00:00:00 2001 From: zhaozg Date: Wed, 10 Jul 2024 15:27:22 +0800 Subject: [PATCH] cmake: new option BUILD_NO_STDIO to enable MINIZ_NO_STDIO --- CMakeLists.txt | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8978910..7e1174c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ endif() set(MINIZ_API_VERSION 3) set(MINIZ_MINOR_VERSION 0) set(MINIZ_PATCH_VERSION 2) -set(MINIZ_VERSION +set(MINIZ_VERSION ${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION}) if(CMAKE_BUILD_TYPE STREQUAL "") @@ -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}) @@ -85,14 +86,14 @@ if(AMALGAMATE_SOURCES) "${AMAL_MINIZ_C}" "\n#endif // MINIZ_HEADER_FILE_ONLY\n") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}") add_library(${PROJECT_NAME} INTERFACE) - + # Might not be a good idea to force this on the library user # as it could bloat the global namespace # https://github.com/libevent/libevent/issues/460 - # target_compile_definitions(${PROJECT_NAME} + # target_compile_definitions(${PROJECT_NAME} # INTERFACE $<$:_GNU_SOURCE>) - - set_property(TARGET ${PROJECT_NAME} APPEND + + set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ $ @@ -111,7 +112,7 @@ if(AMALGAMATE_SOURCES) endif(BUILD_HEADER_ONLY) set(INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h) - + file(GLOB_RECURSE ZIP_FILES RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/amalgamation" "${CMAKE_CURRENT_BINARY_DIR}/amalgamation/*") file(GLOB_RECURSE ZIP_FILES2 RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/examples/*") list(APPEND ZIP_FILES ${ZIP_FILES2}) @@ -131,7 +132,7 @@ if(AMALGAMATE_SOURCES) DEPENDS ${ZIP_FILES} COMMENT "Zipping to ${CMAKE_CURRENT_BINARY_DIR}/miniz.zip." ) - + add_custom_target( create_zip ALL DEPENDS "${ZIP_OUT_FN}" @@ -152,20 +153,20 @@ else(AMALGAMATE_SOURCES) set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${MINIZ_VERSION}) set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${MINIZ_API_VERSION}) - + target_include_directories(${PROJECT_NAME} PUBLIC $ $ $ ) - + file(GLOB INSTALL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) list(APPEND INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h) endif(AMALGAMATE_SOURCES) if(NOT BUILD_HEADER_ONLY) - target_compile_definitions(${PROJECT_NAME} + target_compile_definitions(${PROJECT_NAME} PRIVATE $<$:_GNU_SOURCE>) # pkg-config file @@ -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 @@ -300,13 +305,13 @@ endif() if(BUILD_TESTS) 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) - + enable_testing() - + add_test(NAME catch_tests COMMAND $) endif()