This commit is contained in:
Naiyang Lin 2022-11-06 13:44:09 +01:00 committed by GitHub
commit f216fc95de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 89 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
# Top-most EditorConfig file
root = true
# Unix-style newlines
[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
[{*.cmake,CMakeLists.txt,*.yml}]
indent_size = 2
[*.{h,hpp,c,cpp}]
indent_size = 4

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/_build /_build
/amalgamation /amalgamation
/bin /bin
/build-cmake/

View File

@ -16,8 +16,9 @@ else()
# set(CMAKE_C_VISIBILITY_PRESET hidden) # set(CMAKE_C_VISIBILITY_PRESET hidden)
# set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) # set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
# warning C4996: This function or variable may be unsafe. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
if (MSVC) if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /Zi /permissive-") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /Zi /permissive- /D_CRT_SECURE_NO_WARNINGS")
else () else ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wformat=2 -Wall -Wno-overlength-strings -pedantic") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wformat=2 -Wall -Wno-overlength-strings -pedantic")
endif () endif ()
@ -26,8 +27,7 @@ endif()
set(MINIZ_API_VERSION 3) set(MINIZ_API_VERSION 3)
set(MINIZ_MINOR_VERSION 0) set(MINIZ_MINOR_VERSION 0)
set(MINIZ_PATCH_VERSION 0) set(MINIZ_PATCH_VERSION 0)
set(MINIZ_VERSION set(MINIZ_VERSION ${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION})
${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION})
if(CMAKE_BUILD_TYPE STREQUAL "") if(CMAKE_BUILD_TYPE STREQUAL "")
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
@ -48,6 +48,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
if(INSTALL_PROJECT) if(INSTALL_PROJECT)
include(GNUInstallDirs) include(GNUInstallDirs)
if(MSVC)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
endif()
endif() endif()
if(BUILD_HEADER_ONLY) if(BUILD_HEADER_ONLY)
@ -143,8 +146,7 @@ else(AMALGAMATE_SOURCES)
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
string(TOUPPER ${PROJECT_NAME} PROJECT_UPPER) string(TOUPPER ${PROJECT_NAME} PROJECT_UPPER)
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE)
PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE)
else() else()
set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden) set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden)
endif() endif()
@ -229,72 +231,27 @@ if(INSTALL_PROJECT)
endif() endif()
if(BUILD_EXAMPLES) if(BUILD_EXAMPLES)
set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c") foreach(X example1 example2 example3 example4 example5 example6)
set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c") add_executable(${X} "examples/${X}.c")
set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c") target_link_libraries(${X} miniz)
set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c") endforeach(X)
set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c") if(UNIX)
set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c")
set(MINIZ_TESTER_SRC_LIST
"${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp")
add_executable(example1 ${EXAMPLE1_SRC_LIST})
target_link_libraries(example1 miniz)
add_executable(example2 ${EXAMPLE2_SRC_LIST})
target_link_libraries(example2 miniz)
add_executable(example3 ${EXAMPLE3_SRC_LIST})
target_link_libraries(example3 miniz)
add_executable(example4 ${EXAMPLE4_SRC_LIST})
target_link_libraries(example4 miniz)
add_executable(example5 ${EXAMPLE5_SRC_LIST})
target_link_libraries(example5 miniz)
add_executable(example6 ${EXAMPLE6_SRC_LIST})
target_link_libraries(example6 miniz)
if(${UNIX})
target_link_libraries(example6 m) target_link_libraries(example6 m)
endif() endif()
# add_executable(miniz_tester tests/miniz_tester.cpp tests/timer.cpp)
# add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST})
# target_link_libraries(miniz_tester miniz) # target_link_libraries(miniz_tester miniz)
endif(BUILD_EXAMPLES) endif(BUILD_EXAMPLES)
if(BUILD_FUZZERS) if(BUILD_FUZZERS)
set(FUZZ_MAIN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/tests/fuzz_main.c") set(FUZZERS
checksum_fuzzer flush_fuzzer uncompress_fuzzer uncompress2_fuzzer
set(CHECKSUM_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/checksum_fuzzer.c") compress_fuzzer small_fuzzer large_fuzzer zip_fuzzer
set(FLUSH_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/flush_fuzzer.c") )
set(UNCOMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress_fuzzer.c") foreach(X ${FUZZERS})
set(UNCOMPRESS2_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress2_fuzzer.c") add_executable(${X} "tests/fuzz_main.c" "tests/${X}.c")
set(COMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/compress_fuzzer.c") target_link_libraries(${X} miniz)
set(SMALL_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/small_fuzzer.c") endforeach(X)
set(LARGE_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/large_fuzzer.c") endif(BUILD_FUZZERS)
set(ZIP_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/zip_fuzzer.c")
add_executable(checksum_fuzzer ${CHECKSUM_FUZZER_SRC_LIST})
target_link_libraries(checksum_fuzzer miniz)
add_executable(flush_fuzzer ${FLUSH_FUZZER_SRC_LIST})
target_link_libraries(flush_fuzzer miniz)
add_executable(uncompress_fuzzer ${UNCOMPRESS_FUZZER_SRC_LIST})
target_link_libraries(uncompress_fuzzer miniz)
add_executable(uncompress2_fuzzer ${UNCOMPRESS2_FUZZER_SRC_LIST})
target_link_libraries(uncompress2_fuzzer miniz)
add_executable(compress_fuzzer ${COMPRESS_FUZZER_SRC_LIST})
target_link_libraries(compress_fuzzer miniz)
add_executable(small_fuzzer ${SMALL_FUZZER_SRC_LIST})
target_link_libraries(small_fuzzer miniz)
add_executable(large_fuzzer ${LARGE_FUZZER_SRC_LIST})
target_link_libraries(large_fuzzer miniz)
add_executable(zip_fuzzer ${ZIP_FUZZER_SRC_LIST})
target_link_libraries(zip_fuzzer miniz)
endif()
set(INCLUDE_INSTALL_DIR "include") set(INCLUDE_INSTALL_DIR "include")