Skip to content

Commit

Permalink
cmake: new option BUILD_NO_STDIO to enable MINIZ_NO_STDIO
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed Jul 10, 2024
1 parent bf7a1f0 commit ac9dae7
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand All @@ -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})

Expand Down Expand Up @@ -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 $<$<C_COMPILER_ID:GNU>:_GNU_SOURCE>)
set_property(TARGET ${PROJECT_NAME} APPEND

set_property(TARGET ${PROJECT_NAME} APPEND
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation>
$<INSTALL_INTERFACE:include>
Expand All @@ -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})
Expand All @@ -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}"
Expand All @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)

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 $<$<C_COMPILER_ID:GNU>:_GNU_SOURCE>)

# pkg-config file
Expand All @@ -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
Expand Down Expand Up @@ -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 $<TARGET_FILE:catch_tests>)
endif()
Expand Down

0 comments on commit ac9dae7

Please sign in to comment.