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
/amalgamation
/bin
/build-cmake/

View File

@ -16,8 +16,9 @@ else()
# set(CMAKE_C_VISIBILITY_PRESET hidden)
# 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)
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 ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wformat=2 -Wall -Wno-overlength-strings -pedantic")
endif ()
@ -26,8 +27,7 @@ endif()
set(MINIZ_API_VERSION 3)
set(MINIZ_MINOR_VERSION 0)
set(MINIZ_PATCH_VERSION 0)
set(MINIZ_VERSION
${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION})
set(MINIZ_VERSION ${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION})
if(CMAKE_BUILD_TYPE STREQUAL "")
# 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)
include(GNUInstallDirs)
if(MSVC)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
endif()
endif()
if(BUILD_HEADER_ONLY)
@ -143,8 +146,7 @@ else(AMALGAMATE_SOURCES)
if(NOT BUILD_SHARED_LIBS)
string(TOUPPER ${PROJECT_NAME} PROJECT_UPPER)
set_target_properties(${PROJECT_NAME}
PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE)
set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE)
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden)
endif()
@ -229,72 +231,27 @@ if(INSTALL_PROJECT)
endif()
if(BUILD_EXAMPLES)
set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c")
set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c")
set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c")
set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c")
set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c")
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})
foreach(X example1 example2 example3 example4 example5 example6)
add_executable(${X} "examples/${X}.c")
target_link_libraries(${X} miniz)
endforeach(X)
if(UNIX)
target_link_libraries(example6 m)
endif()
# add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST})
# add_executable(miniz_tester tests/miniz_tester.cpp tests/timer.cpp)
# target_link_libraries(miniz_tester miniz)
endif(BUILD_EXAMPLES)
if(BUILD_FUZZERS)
set(FUZZ_MAIN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/tests/fuzz_main.c")
set(CHECKSUM_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/checksum_fuzzer.c")
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")
set(UNCOMPRESS2_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress2_fuzzer.c")
set(COMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/compress_fuzzer.c")
set(SMALL_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/small_fuzzer.c")
set(LARGE_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/large_fuzzer.c")
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(FUZZERS
checksum_fuzzer flush_fuzzer uncompress_fuzzer uncompress2_fuzzer
compress_fuzzer small_fuzzer large_fuzzer zip_fuzzer
)
foreach(X ${FUZZERS})
add_executable(${X} "tests/fuzz_main.c" "tests/${X}.c")
target_link_libraries(${X} miniz)
endforeach(X)
endif(BUILD_FUZZERS)
set(INCLUDE_INSTALL_DIR "include")