2024-05-27 14:19:48 +00:00
|
|
|
cmake_minimum_required(VERSION 3.14)
|
2019-11-19 19:30:40 +00:00
|
|
|
|
|
|
|
project(zip
|
|
|
|
LANGUAGES C
|
2024-05-27 14:19:48 +00:00
|
|
|
VERSION "0.3.0")
|
2019-03-27 02:45:20 +00:00
|
|
|
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
2021-04-30 14:49:15 +00:00
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
2024-05-27 14:19:48 +00:00
|
|
|
|
|
|
|
# Enable building tests only if the project is being built as a standalone one
|
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
option(CMAKE_DISABLE_TESTING "Disable test creation" OFF)
|
|
|
|
else ()
|
|
|
|
option(CMAKE_DISABLE_TESTING "Disable test creation" ON)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
option(CMAKE_ENABLE_SANITIZERS "Enable zip sanitizers" OFF)
|
|
|
|
option(ZIP_STATIC_PIC "Build static zip with PIC" ON)
|
|
|
|
option(ZIP_BUILD_DOCS "Generate API documentation with Doxygen" OFF)
|
|
|
|
|
|
|
|
if(ZIP_ENABLE_SHARABLE_FILE_OPEN)
|
|
|
|
add_definitions(-DZIP_ENABLE_SHARABLE_FILE_OPEN)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
|
|
|
# large file support
|
|
|
|
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64)
|
|
|
|
endif()
|
2019-11-19 19:30:40 +00:00
|
|
|
|
2017-11-27 20:48:33 +00:00
|
|
|
# zip
|
|
|
|
set(SRC src/miniz.h src/zip.h src/zip.c)
|
2021-04-30 14:49:15 +00:00
|
|
|
|
2024-05-27 14:19:48 +00:00
|
|
|
add_library(${PROJECT_NAME} ${SRC})
|
|
|
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
|
|
|
|
|
|
|
if(ZIP_STATIC_PIC)
|
|
|
|
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}
|
|
|
|
PUBLIC ZIP_SHARED
|
|
|
|
PRIVATE ZIP_BUILD_SHARED
|
|
|
|
)
|
2021-04-30 14:49:15 +00:00
|
|
|
endif()
|
|
|
|
|
2019-11-19 19:30:40 +00:00
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
|
|
|
$<INSTALL_INTERFACE:include>
|
|
|
|
)
|
2017-11-27 20:48:33 +00:00
|
|
|
|
|
|
|
# test
|
2019-03-27 02:45:20 +00:00
|
|
|
if (NOT CMAKE_DISABLE_TESTING)
|
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(test)
|
2024-05-27 14:19:48 +00:00
|
|
|
endif()
|
|
|
|
if (CMAKE_ENABLE_SANITIZERS)
|
2019-03-27 02:45:20 +00:00
|
|
|
find_package(Sanitizers)
|
2024-05-27 14:19:48 +00:00
|
|
|
add_sanitizers(${PROJECT_NAME})
|
2019-03-27 02:45:20 +00:00
|
|
|
endif()
|
2017-11-27 20:48:33 +00:00
|
|
|
|
2024-05-27 14:19:48 +00:00
|
|
|
set(CMAKE_C_STANDARD 90)
|
2021-04-30 14:49:15 +00:00
|
|
|
if (MSVC)
|
|
|
|
# Use secure functions by default and suppress warnings about "deprecated" functions
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
|
2024-05-27 14:19:48 +00:00
|
|
|
|
2021-04-30 14:49:15 +00:00
|
|
|
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
|
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
|
2024-05-27 14:19:48 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic")
|
2021-04-30 14:49:15 +00:00
|
|
|
endif (MSVC)
|
|
|
|
|
2019-11-19 19:30:40 +00:00
|
|
|
####
|
|
|
|
set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
|
|
|
|
set(INCLUDE_INSTALL_DIR "include")
|
|
|
|
|
|
|
|
set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
set(VERSION_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
|
|
|
set(PROJECT_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}Config.cmake")
|
|
|
|
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
|
|
|
set(NAMESPACE "${PROJECT_NAME}::")
|
|
|
|
|
2024-05-27 14:19:48 +00:00
|
|
|
# Include module with function 'write_basic_package_version_file'
|
2019-11-19 19:30:40 +00:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
|
|
|
# Note: PROJECT_VERSION is used as a VERSION
|
|
|
|
write_basic_package_version_file(
|
|
|
|
"${VERSION_CONFIG}" COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
|
|
|
|
# Use variables:
|
|
|
|
# * TARGETS_EXPORT_NAME
|
|
|
|
# * PROJECT_NAME
|
|
|
|
configure_package_config_file(
|
|
|
|
"cmake/Config.cmake.in"
|
|
|
|
"${PROJECT_CONFIG}"
|
|
|
|
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
|
|
|
|
)
|
|
|
|
|
|
|
|
install(
|
|
|
|
FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}"
|
|
|
|
DESTINATION "${CONFIG_INSTALL_DIR}"
|
|
|
|
)
|
|
|
|
|
|
|
|
install(
|
|
|
|
EXPORT "${TARGETS_EXPORT_NAME}"
|
|
|
|
NAMESPACE "${NAMESPACE}"
|
|
|
|
DESTINATION "${CONFIG_INSTALL_DIR}"
|
|
|
|
)
|
|
|
|
|
2019-03-27 02:45:20 +00:00
|
|
|
install(TARGETS ${PROJECT_NAME}
|
2019-11-19 19:30:40 +00:00
|
|
|
EXPORT ${TARGETS_EXPORT_NAME}
|
2019-03-27 02:45:20 +00:00
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib
|
2019-11-19 19:30:40 +00:00
|
|
|
INCLUDES DESTINATION ${INCLUDE_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
install(FILES ${PROJECT_SOURCE_DIR}/src/zip.h DESTINATION ${INCLUDE_INSTALL_DIR}/zip)
|
2019-03-27 02:45:20 +00:00
|
|
|
|
|
|
|
# uninstall target (https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake)
|
|
|
|
if(NOT TARGET uninstall)
|
|
|
|
configure_file(
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
|
|
|
|
IMMEDIATE @ONLY)
|
|
|
|
|
|
|
|
add_custom_target(uninstall
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
|
|
|
|
endif()
|
2019-11-19 19:30:40 +00:00
|
|
|
|
2024-05-27 14:19:48 +00:00
|
|
|
if(ZIP_BUILD_DOCS)
|
|
|
|
find_package(Doxygen REQUIRED)
|
2019-11-19 19:30:40 +00:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
|
|
|
add_custom_target(doc
|
|
|
|
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMENT "Generating API documentation with Doxygen" VERBATIM)
|
|
|
|
endif()
|