CMakeLists.txt
上传用户:shengde
上传日期:2021-02-21
资源大小:638k
文件大小:6k
源码类别:

压缩解压

开发平台:

Visual C++

  1. cmake_minimum_required(VERSION 2.4.4)
  2. set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
  3. project(zlib C)
  4. if(NOT DEFINED BUILD_SHARED_LIBS)
  5.     option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
  6. endif()
  7. include(CheckTypeSize)
  8. include(CheckFunctionExists)
  9. include(CheckIncludeFile)
  10. include(CheckCSourceCompiles)
  11. enable_testing()
  12. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  13. check_include_file(stdint.h    HAVE_STDINT_H)
  14. check_include_file(stddef.h    HAVE_STDDEF_H)
  15. #
  16. # Check to see if we have large file support
  17. #
  18. set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE)
  19. # We add these other definitions here because CheckTypeSize.cmake
  20. # in CMake 2.4.x does not automatically do so and we want
  21. # compatibility with CMake 2.4.x.
  22. if(HAVE_SYS_TYPES_H)
  23.     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
  24. endif()
  25. if(HAVE_STDINT_H)
  26.     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
  27. endif()
  28. if(HAVE_STDDEF_H)
  29.     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
  30. endif()
  31. check_type_size(off64_t OFF64_T)
  32. if(HAVE_OFF64_T)
  33.    add_definitions(-D_LARGEFILE64_SOURCE)
  34. endif()
  35. set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
  36. #
  37. # Check for fseeko
  38. #
  39. check_function_exists(fseeko HAVE_FSEEKO)
  40. if(NOT HAVE_FSEEKO)
  41.     add_definitions(-DNO_FSEEKO)
  42. endif()
  43. #
  44. # Check for unistd.h
  45. #
  46. check_include_file(unistd.h Z_HAVE_UNISTD_H)
  47. #
  48. # Check for errno.h
  49. check_include_file(errno.h HAVE_ERRNO_H)
  50. if(NOT HAVE_ERRNO_H)
  51.    add_definitions(-DNO_ERRNO_H)
  52. endif()
  53. if(MSVC)
  54.     set(CMAKE_DEBUG_POSTFIX "d")
  55.     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  56.     add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
  57. endif()
  58. if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
  59.     # If we're doing an out of source build and the user has a zconf.h
  60.     # in their source tree...
  61.     if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
  62.         message(FATAL_ERROR
  63.             "You must remove ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h "
  64.             "from the source tree.  This file is included with zlib "
  65.             "but CMake generates this file for you automatically "
  66.             "in the build directory.")
  67.   endif()
  68. endif()
  69. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
  70.                ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
  71. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  72. #============================================================================
  73. # zlib
  74. #============================================================================
  75. set(ZLIB_PUBLIC_HDRS
  76.     ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
  77.     zlib.h
  78. )
  79. set(ZLIB_PRIVATE_HDRS
  80.     crc32.h
  81.     deflate.h
  82.     gzguts.h
  83.     inffast.h
  84.     inffixed.h
  85.     inflate.h
  86.     inftrees.h
  87.     trees.h
  88.     zutil.h
  89. )
  90. set(ZLIB_SRCS
  91.     adler32.c
  92.     compress.c
  93.     crc32.c
  94.     deflate.c
  95.     gzclose.c
  96.     gzlib.c
  97.     gzread.c
  98.     gzwrite.c
  99.     inflate.c
  100.     infback.c
  101.     inftrees.c
  102.     inffast.c
  103.     trees.c
  104.     uncompr.c
  105.     zutil.c
  106.     win32/zlib1.rc
  107. )
  108. # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
  109. file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
  110. string(REGEX REPLACE ".*#define[ t]+ZLIB_VERSION[ t]+"([0-9A-Za-z.]+)".*"
  111.     "\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
  112. if(MINGW)
  113.     # This gets us DLL resource information when compiling on MinGW.
  114.     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
  115.                        COMMAND windres.exe
  116.                             -D GCC_WINDRES
  117.                             -I ${CMAKE_CURRENT_SOURCE_DIR}
  118.                             -I ${CMAKE_CURRENT_BINARY_DIR}
  119.                             -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
  120.                             -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
  121.     set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
  122. endif(MINGW)
  123. add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
  124. set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
  125. set_target_properties(zlib PROPERTIES SOVERSION 1)
  126. if(NOT CYGWIN)
  127.     # This property causes shared libraries on Linux to have the full version
  128.     # encoded into their final filename.  We disable this on Cygwin because
  129.     # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
  130.     # seems to be the default.
  131.     #
  132.     # This has no effect with MSVC, on that platform the version info for
  133.     # the DLL comes from the resource file win32/zlib1.rc
  134.     set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
  135. endif()
  136. if(UNIX)
  137.     # On unix-like platforms the library is almost always called libz
  138.    set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
  139. elseif(BUILD_SHARED_LIBS AND WIN32)
  140.     # Creates zlib1.dll when building shared library version
  141.     set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
  142. endif()
  143. if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
  144.     install(TARGETS zlib
  145.         RUNTIME DESTINATION bin
  146.         ARCHIVE DESTINATION lib
  147.         LIBRARY DESTINATION lib )
  148. endif()
  149. if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
  150.     install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
  151. endif()
  152. if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
  153.     install(FILES zlib.3 DESTINATION share/man/man3)
  154. endif()
  155. #============================================================================
  156. # Example binaries
  157. #============================================================================
  158. add_executable(example example.c)
  159. target_link_libraries(example zlib)
  160. add_test(example example)
  161. add_executable(minigzip minigzip.c)
  162. target_link_libraries(minigzip zlib)
  163. if(HAVE_OFF64_T)
  164.     add_executable(example64 example.c)
  165.     target_link_libraries(example64 zlib)
  166.     set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
  167.     add_test(example64 example64)
  168.     add_executable(minigzip64 minigzip.c)
  169.     target_link_libraries(minigzip64 zlib)
  170.     set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
  171. endif()