1
0

CMakeLists.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. cmake_minimum_required(VERSION 3.8)
  2. project(minizip VERSION 1.2.13 LANGUAGES C)
  3. if(MSVC)
  4. add_compile_options(/W3 /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
  5. endif()
  6. find_package(ZLIB REQUIRED)
  7. set(MIN_SRC contrib/minizip)
  8. include_directories(${MIN_SRC} ${ZLIB_INCLUDE_DIRS})
  9. set(MINIZIP_LIBRARIES ZLIB::ZLIB)
  10. if(ENABLE_BZIP2)
  11. message(STATUS "Building with bzip2 support")
  12. find_package(BZip2)
  13. include_directories(${BZIP2_INCLUDE_DIR})
  14. set(MINIZIP_LIBRARIES ${MINIZIP_LIBRARIES} ${BZIP2_LIBRARIES})
  15. else()
  16. message(STATUS "Building without bzip2 support")
  17. endif()
  18. set(SRC
  19. ${MIN_SRC}/ioapi.c
  20. ${MIN_SRC}/unzip.c
  21. ${MIN_SRC}/zip.c
  22. ${MIN_SRC}/mztools.c
  23. )
  24. if(WIN32)
  25. list(APPEND SRC ${MIN_SRC}/iowin32.c)
  26. endif()
  27. set(HEADERS
  28. ${MIN_SRC}/crypt.h
  29. ${MIN_SRC}/ioapi.h
  30. ${MIN_SRC}/unzip.h
  31. ${MIN_SRC}/zip.h
  32. ${MIN_SRC}/mztools.h
  33. )
  34. if(WIN32)
  35. list(APPEND HEADERS ${MIN_SRC}/iowin32.h)
  36. endif()
  37. add_library(minizip ${SRC})
  38. target_link_libraries(minizip PRIVATE ZLIB::ZLIB)
  39. target_compile_definitions(minizip PRIVATE -D_ZLIB_H)
  40. if(ENABLE_BZIP2)
  41. target_link_libraries(minizip PUBLIC ${BZIP2_LIBRARIES})
  42. target_compile_definitions(minizip PRIVATE -DHAVE_BZIP2=1)
  43. endif()
  44. if(ANDROID)
  45. target_compile_definitions(minizip PRIVATE IOAPI_NO_64)
  46. endif()
  47. if(NOT DISABLE_INSTALL_TOOLS)
  48. add_executable(minizip_bin ${MIN_SRC}/minizip.c)
  49. add_executable(miniunz_bin ${MIN_SRC}/miniunz.c)
  50. target_link_libraries(minizip_bin minizip ${MINIZIP_LIBRARIES})
  51. target_link_libraries(miniunz_bin minizip ${MINIZIP_LIBRARIES})
  52. set_target_properties(minizip_bin PROPERTIES OUTPUT_NAME minizip)
  53. set_target_properties(miniunz_bin PROPERTIES OUTPUT_NAME miniunz)
  54. endif()
  55. install(
  56. TARGETS minizip
  57. EXPORT minizipTargets
  58. RUNTIME DESTINATION bin
  59. LIBRARY DESTINATION lib
  60. ARCHIVE DESTINATION lib
  61. )
  62. include(CMakePackageConfigHelpers)
  63. write_basic_package_version_file("${PROJECT_BINARY_DIR}/minizipConfigVersion.cmake"
  64. COMPATIBILITY SameMajorVersion)
  65. configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/minizipConfig.cmake.in
  66. minizipConfig.cmake
  67. INSTALL_DESTINATION share/minizip)
  68. install(FILES
  69. "${PROJECT_BINARY_DIR}/minizipConfig.cmake"
  70. "${PROJECT_BINARY_DIR}/minizipConfigVersion.cmake"
  71. DESTINATION share/minizip
  72. )
  73. install(EXPORT minizipTargets
  74. NAMESPACE minizip::
  75. DESTINATION share/minizip
  76. )
  77. if(NOT DISABLE_INSTALL_TOOLS)
  78. install (
  79. TARGETS minizip_bin miniunz_bin
  80. RUNTIME DESTINATION tools/minizip
  81. )
  82. endif()
  83. if(NOT DISABLE_INSTALL_HEADERS)
  84. install(FILES ${HEADERS} DESTINATION include/minizip)
  85. endif()