1
- # Copyright (c) 2006, 2024, Oracle and/or its affiliates.
2
- #
3
- # This program is free software; you can redistribute it and/or modify
4
- # it under the terms of the GNU General Public License, version 2.0,
5
- # as published by the Free Software Foundation.
6
- #
7
- # This program is designed to work with certain software (including
8
- # but not limited to OpenSSL) that is licensed under separate terms, as
9
- # designated in a particular file or component or in included license
10
- # documentation. The authors of MySQL hereby grant you an additional
11
- # permission to link the program and your derivative works with the
12
- # separately licensed software that they have either included with
13
- # the program or referenced in the documentation.
14
- #
15
- # This program is distributed in the hope that it will be useful, but
16
- # WITHOUT ANY WARRANTY; without even the implied warranty of
17
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18
- # the GNU General Public License, version 2.0, for more details.
19
- #
20
- # You should have received a copy of the GNU General Public License
21
- # along with this program; if not, write to the Free Software Foundation, Inc.,
22
- # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
-
24
- cmake_minimum_required (VERSION 2.4.4 )
1
+ cmake_minimum_required (VERSION 3.5 )
2
+ cmake_policy (SET CMP0048 NEW ) # allow VERSION specification in project()
25
3
set (CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON )
26
4
27
- set ( VERSION "1.2.13" )
5
+ # project(zlib C )
28
6
29
- IF (POLICY CMP0048 )
30
- CMAKE_POLICY (SET CMP0048 NEW )
31
- project (zlib VERSION ${VERSION} LANGUAGES C )
32
- ELSE ()
33
- project (zlib C )
34
- ENDIF ()
7
+ set (VERSION "1.3.1" )
35
8
36
- IF (POLICY CMP0075 )
37
- CMAKE_POLICY (SET CMP0075 OLD )
38
- ENDIF ()
9
+ project (zlib VERSION ${VERSION} LANGUAGES C )
39
10
40
- include (../setup.cmake )
41
- include (platform )
11
+ option (ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON )
42
12
43
- enable_pic ()
13
+ IF (DISABLE_THESE_LINES )
14
+ set (INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX} /bin" CACHE PATH "Installation directory for executables" )
15
+ set (INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX} /lib" CACHE PATH "Installation directory for libraries" )
16
+ set (INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX} /include" CACHE PATH "Installation directory for headers" )
17
+ set (INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX} /share/man" CACHE PATH "Installation directory for manual pages" )
18
+ set (INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX} /share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files" )
19
+ ENDIF (DISABLE_THESE_LINES )
44
20
45
21
include (CheckTypeSize )
46
22
include (CheckFunctionExists )
47
23
include (CheckIncludeFile )
48
24
include (CheckCSourceCompiles )
25
+ # enable_testing()
49
26
50
27
check_include_file (sys/types.h HAVE_SYS_TYPES_H )
51
28
check_include_file (stdint.h HAVE_STDINT_H )
@@ -86,13 +63,40 @@ endif()
86
63
#
87
64
check_include_file (unistd.h Z_HAVE_UNISTD_H )
88
65
66
+ IF (DISABLE_THESE_LINES )
67
+ if (MSVC )
68
+ set (CMAKE_DEBUG_POSTFIX "d" )
69
+ add_definitions (-D_CRT_SECURE_NO_DEPRECATE )
70
+ add_definitions (-D_CRT_NONSTDC_NO_DEPRECATE )
71
+ include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
72
+ endif ()
73
+
74
+ if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR )
75
+ # If we're doing an out of source build and the user has a zconf.h
76
+ # in their source tree...
77
+ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /zconf.h )
78
+ message (STATUS "Renaming" )
79
+ message (STATUS " ${CMAKE_CURRENT_SOURCE_DIR} /zconf.h" )
80
+ message (STATUS "to 'zconf.h.included' because this file is included with zlib" )
81
+ message (STATUS "but CMake generates it automatically in the build directory." )
82
+ file (RENAME ${CMAKE_CURRENT_SOURCE_DIR} /zconf.h ${CMAKE_CURRENT_SOURCE_DIR} /zconf.h.included )
83
+ endif ()
84
+ endif ()
85
+
86
+ set (ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR} /zlib.pc )
87
+ configure_file ( ${CMAKE_CURRENT_SOURCE_DIR} /zlib.pc.cmakein
88
+ ${ZLIB_PC} @ONLY )
89
+ configure_file ( ${CMAKE_CURRENT_SOURCE_DIR} /zconf.h.cmakein
90
+ ${CMAKE_CURRENT_BINARY_DIR} /zconf.h @ONLY )
91
+ include_directories (${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
92
+ ENDIF (DISABLE_THESE_LINES )
89
93
90
- configure_file (
94
+ CONFIGURE_FILE (
91
95
${CMAKE_CURRENT_SOURCE_DIR} /zconf.h.cmakein
92
96
${CMAKE_CURRENT_BINARY_DIR} /zconf.h @ONLY
93
97
)
94
- include_directories (
95
- SYSTEM ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
98
+ INCLUDE_DIRECTORIES (
99
+ BEFORE SYSTEM ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
96
100
)
97
101
98
102
@@ -144,33 +148,9 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
144
148
string (REGEX REPLACE ".*#define[ \t ]+ZLIB_VERSION[ \t ]+\" ([-0-9A-Za-z.]+)\" .*"
145
149
"\\ 1" ZLIB_FULL_VERSION ${_zlib_h_contents} )
146
150
147
- # -------------------------------------------------------------------------
148
- # Disable compile warnings
149
-
150
- if (MSVC )
151
-
152
- add_compile_options (
153
- /wd4996
154
- /wd4267
155
- /wd4131 # old style declarator
156
- /wd4127 # conditional expression is constant
157
- /wd4244 # possible loss of data during conversion
158
- /wd4245 # signed/unsigned missmatch
159
- )
151
+ add_compile_options (-fPIC )
160
152
161
- endif ()
162
-
163
- if (APPLE )
164
- # Disable warning for zlib 1.2.13.
165
- # In zlib version 1.3 this problem should be fixed:
166
- # https://github.com/madler/zlib/issues/633
167
- add_compile_options (-Wno-deprecated-non-prototype )
168
- endif ()
169
-
170
- # -------------------------------------------------------------------------
171
-
172
- ADD_LIBRARY (zlib STATIC
173
- ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS} )
153
+ add_library (zlib STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS} )
174
154
175
155
target_include_directories (zlib PUBLIC
176
156
${PROJECT_BINARY_DIR}
@@ -179,6 +159,36 @@ target_include_directories(zlib PUBLIC
179
159
180
160
set_target_properties (zlib PROPERTIES FOLDER "Misc" )
181
161
162
+ export (TARGETS zlib NAMESPACE ext_ FILE ${PROJECT_BINARY_DIR} /exports.cmake )
163
+
164
+ RETURN ()
165
+
166
+ # Skip anything below.
167
+ ################################################################
168
+
169
+ if (MINGW )
170
+ # This gets us DLL resource information when compiling on MinGW.
171
+ if (NOT CMAKE_RC_COMPILER )
172
+ set (CMAKE_RC_COMPILER windres.exe )
173
+ endif ()
174
+
175
+ add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /zlib1rc.obj
176
+ COMMAND ${CMAKE_RC_COMPILER}
177
+ -D GCC_WINDRES
178
+ -I ${CMAKE_CURRENT_SOURCE_DIR}
179
+ -I ${CMAKE_CURRENT_BINARY_DIR}
180
+ -o ${CMAKE_CURRENT_BINARY_DIR} /zlib1rc.obj
181
+ -i ${CMAKE_CURRENT_SOURCE_DIR} /win32/zlib1.rc )
182
+ set (ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR} /zlib1rc.obj )
183
+ endif (MINGW )
184
+
185
+ add_library (zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS} )
186
+ target_include_directories (zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} )
187
+ add_library (zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS} )
188
+ target_include_directories (zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} )
189
+ set_target_properties (zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL )
190
+ set_target_properties (zlib PROPERTIES SOVERSION 1 )
191
+
182
192
if (NOT CYGWIN )
183
193
# This property causes shared libraries on Linux to have the full version
184
194
# encoded into their final filename. We disable this on Cygwin because
@@ -190,18 +200,52 @@ if(NOT CYGWIN)
190
200
set_target_properties (zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION} )
191
201
endif ()
192
202
193
- if (CMAKE_SYSTEM_NAME MATCHES "SunOS" )
203
+ if (UNIX )
194
204
# On unix-like platforms the library is almost always called libz
195
- set_target_properties (zlib PROPERTIES OUTPUT_NAME z )
196
- elseif (UNIX )
197
- # On unix-like platforms the library is almost always called libz
198
- set_target_properties (zlib PROPERTIES OUTPUT_NAME z )
199
- if (NOT APPLE )
205
+ set_target_properties (zlib zlibstatic PROPERTIES OUTPUT_NAME z )
206
+ if (NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX ))
200
207
set_target_properties (zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\" ${CMAKE_CURRENT_SOURCE_DIR} /zlib.map\" " )
201
208
endif ()
209
+ elseif (BUILD_SHARED_LIBS AND WIN32 )
210
+ # Creates zlib1.dll when building shared library version
211
+ set_target_properties (zlib PROPERTIES SUFFIX "1.dll" )
202
212
endif ()
203
213
204
- #ADD_EXECUTABLE(try_zlib try.cc)
205
- #TARGET_LINK_LIBRARIES(try_zlib zlib)
214
+ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
215
+ install (TARGETS zlib zlibstatic
216
+ RUNTIME DESTINATION "${INSTALL_BIN_DIR} "
217
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR} "
218
+ LIBRARY DESTINATION "${INSTALL_LIB_DIR} " )
219
+ endif ()
220
+ if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
221
+ install (FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR} " )
222
+ endif ()
223
+ if (NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
224
+ install (FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR} /man3" )
225
+ endif ()
226
+ if (NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
227
+ install (FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR} " )
228
+ endif ()
206
229
207
- export (TARGETS zlib NAMESPACE ext_ FILE ${PROJECT_BINARY_DIR} /exports.cmake )
230
+ #============================================================================
231
+ # Example binaries
232
+ #============================================================================
233
+ if (ZLIB_BUILD_EXAMPLES )
234
+ add_executable (example test /example.c )
235
+ target_link_libraries (example zlib )
236
+ add_test (example example )
237
+
238
+ add_executable (minigzip test /minigzip.c )
239
+ target_link_libraries (minigzip zlib )
240
+
241
+ if (HAVE_OFF64_T )
242
+ add_executable (example64 test /example.c )
243
+ target_link_libraries (example64 zlib )
244
+ set_target_properties (example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64" )
245
+ add_test (example64 example64 )
246
+
247
+ add_executable (minigzip64 test /minigzip.c )
248
+ target_link_libraries (minigzip64 zlib )
249
+ set_target_properties (minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64" )
250
+ endif ()
251
+ endif ()
0 commit comments