CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. cmake_minimum_required(VERSION 2.4.4)
  2. set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
  3. set(VERSION "1.2.7")
  4. set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
  5. set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
  6. set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
  7. set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
  8. set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
  9. include(CheckTypeSize)
  10. include(CheckFunctionExists)
  11. include(CheckIncludeFile)
  12. include(CheckCSourceCompiles)
  13. enable_testing()
  14. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  15. check_include_file(stdint.h HAVE_STDINT_H)
  16. check_include_file(stddef.h HAVE_STDDEF_H)
  17. #
  18. # Check to see if we have large file support
  19. #
  20. set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
  21. # We add these other definitions here because CheckTypeSize.cmake
  22. # in CMake 2.4.x does not automatically do so and we want
  23. # compatibility with CMake 2.4.x.
  24. if(HAVE_SYS_TYPES_H)
  25. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
  26. endif()
  27. if(HAVE_STDINT_H)
  28. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
  29. endif()
  30. if(HAVE_STDDEF_H)
  31. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
  32. endif()
  33. check_type_size(off64_t OFF64_T)
  34. if(HAVE_OFF64_T)
  35. add_definitions(-D_LARGEFILE64_SOURCE=1)
  36. endif()
  37. set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
  38. #
  39. # Check for fseeko
  40. #
  41. check_function_exists(fseeko HAVE_FSEEKO)
  42. if(NOT HAVE_FSEEKO)
  43. add_definitions(-DNO_FSEEKO)
  44. endif()
  45. #
  46. # Check for unistd.h
  47. #
  48. check_include_file(unistd.h Z_HAVE_UNISTD_H)
  49. if(MSVC)
  50. set(CMAKE_DEBUG_POSTFIX "d")
  51. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  52. add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
  53. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  54. endif()
  55. if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
  56. # If we're doing an out of source build and the user has a zconf.h
  57. # in their source tree...
  58. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
  59. message(STATUS "Renaming")
  60. message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
  61. message(STATUS "to 'zconf.h.included' because this file is included with zlib")
  62. message(STATUS "but CMake generates it automatically in the build directory.")
  63. file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
  64. endif()
  65. endif()
  66. set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
  67. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
  68. ${ZLIB_PC} @ONLY)
  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} ${CMAKE_SOURCE_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. )
  107. #if(NOT MINGW)
  108. # set(ZLIB_SRCS ${ZLIB_SRCS}
  109. # win32/zlib1.rc # If present will override custom build rule below.
  110. # )
  111. #endif()
  112. # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
  113. file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
  114. string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
  115. "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
  116. if(MINGW)
  117. # This gets us DLL resource information when compiling on MinGW.
  118. if(NOT CMAKE_RC_COMPILER)
  119. SET(CMAKE_RC_COMPILER windres.exe)
  120. endif()
  121. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
  122. COMMAND ${CMAKE_RC_COMPILER}
  123. -D GCC_WINDRES
  124. -I ${CMAKE_CURRENT_SOURCE_DIR}
  125. -I ${CMAKE_CURRENT_BINARY_DIR}
  126. -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
  127. -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
  128. set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
  129. endif(MINGW)
  130. add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
  131. add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
  132. set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
  133. set_target_properties(zlib PROPERTIES SOVERSION 1)
  134. if(NOT CYGWIN)
  135. # This property causes shared libraries on Linux to have the full version
  136. # encoded into their final filename. We disable this on Cygwin because
  137. # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
  138. # seems to be the default.
  139. #
  140. # This has no effect with MSVC, on that platform the version info for
  141. # the DLL comes from the resource file win32/zlib1.rc
  142. set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
  143. endif()
  144. if(UNIX)
  145. # On unix-like platforms the library is almost always called libz
  146. set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
  147. set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/zlib.map")
  148. elseif(BUILD_SHARED_LIBS AND WIN32)
  149. # Creates zlib1.dll when building shared library version
  150. set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
  151. endif()
  152. if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
  153. install(TARGETS zlib zlibstatic
  154. RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
  155. ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
  156. LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
  157. endif()
  158. if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
  159. install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
  160. endif()
  161. if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
  162. install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
  163. endif()
  164. if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
  165. install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
  166. endif()
  167. #============================================================================
  168. # Example binaries
  169. #============================================================================
  170. #add_executable(example test/example.c)
  171. #target_link_libraries(example zlib)
  172. #add_test(example example)
  173. #add_executable(minigzip test/minigzip.c)
  174. #target_link_libraries(minigzip zlib)
  175. #if(HAVE_OFF64_T)
  176. # add_executable(example64 test/example.c)
  177. # target_link_libraries(example64 zlib)
  178. # set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
  179. # add_test(example64 example64)
  180. # add_executable(minigzip64 test/minigzip.c)
  181. # target_link_libraries(minigzip64 zlib)
  182. # set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
  183. #endif()