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