Skip to content

Commit 61c7c7e

Browse files
committed
CDRIVER-2505 fix zlib
1 parent b8634c7 commit 61c7c7e

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed

CMakeLists.txt

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,6 @@ endif ()
171171

172172
set (SOURCE_DIR "${PROJECT_SOURCE_DIR}/")
173173

174-
if (ENABLE_MONGOC STREQUAL ON)
175-
add_subdirectory (src/libmongoc)
176-
endif ()
177-
178-
set (CPACK_RESOURCE_FILE_LICENSE "${SOURCE_DIR}/COPYING")
179-
180-
include (CPack)
181-
182-
if (NOT ENABLE_ZLIB MATCHES "SYSTEM|AUTO|BUNDLED|OFF")
183-
message (FATAL_ERROR
184-
"ENABLE_ZLIB option must be SYSTEM, BUNDLED, AUTO, or OFF"
185-
)
186-
endif ()
187-
188174
set (ZLIB_SOURCES
189175
${SOURCE_DIR}/src/zlib-1.2.11/adler32.c
190176
${SOURCE_DIR}/src/zlib-1.2.11/crc32.c
@@ -203,59 +189,13 @@ set (ZLIB_SOURCES
203189
${SOURCE_DIR}/src/zlib-1.2.11/gzwrite.c
204190
)
205191

206-
# Disable warnings on bundled zlib source files.
207-
set_source_files_properties (${ZLIB_SOURCES} PROPERTIES COMPILE_FLAGS -w)
208-
209-
# Copy zconf.h.in to zconf.h; even when using system zlib, the 'dist' target
210-
# will look for zconf.h in that location.
211-
configure_file (
212-
"${SOURCE_DIR}/src/zlib-1.2.11/zconf.h.in"
213-
"${PROJECT_BINARY_DIR}/src/zlib-1.2.11/zconf.h"
214-
COPYONLY
215-
)
216-
if (ENABLE_ZLIB MATCHES "SYSTEM|AUTO")
217-
message (STATUS "Searching for zlib CMake packages")
218-
include (FindZLIB)
219-
if (ZLIB_FOUND)
220-
message ("-- zlib found version \"${ZLIB_VERSION_STRING}\"")
221-
message ("-- zlib include path \"${ZLIB_INCLUDE_DIRS}\"")
222-
message ("-- zlib libraries \"${ZLIB_LIBRARIES}\"")
223-
include_directories ("${ZLIB_INCLUDE_DIRS}")
224-
else ()
225-
if (ENABLE_ZLIB STREQUAL "SYSTEM")
226-
message (FATAL_ERROR
227-
"Unable to find system zlib package. Either specify the zlib \
228-
location by setting ZLIB_ROOT, or else set ENABLE_ZLIB=BUNDLED or \
229-
set ENABLE_ZLIB=OFF."
230-
)
231-
endif ()
232-
set (ZLIB_LIBRARIES "")
233-
endif ()
192+
if (ENABLE_MONGOC STREQUAL ON)
193+
add_subdirectory (src/libmongoc)
234194
endif ()
235195

236-
if ( (ENABLE_ZLIB STREQUAL "BUNDLED")
237-
OR (ENABLE_ZLIB STREQUAL "AUTO" AND NOT ZLIB_FOUND) )
238-
message (STATUS "Enabling zlib compression (bundled)")
239-
set (SOURCES ${SOURCES} ${ZLIB_SOURCES})
240-
241-
list (
242-
APPEND
243-
MONGOC_INTERNAL_INCLUDE_DIRS
244-
"${SOURCE_DIR}/src/zlib-1.2.11"
245-
"${PROJECT_BINARY_DIR}/src/zlib-1.2.11"
246-
)
247-
endif ()
196+
set (CPACK_RESOURCE_FILE_LICENSE "${SOURCE_DIR}/COPYING")
248197

249-
if (NOT ENABLE_ZLIB STREQUAL "OFF")
250-
# At this point the system zlib was found, or the bundled library was used
251-
include (CheckIncludeFiles)
252-
check_include_files ("unistd.h" HAVE_UNISTD_H)
253-
check_include_files ("stdarg.h" HAVE_STDARG_H)
254-
set (MONGOC_ENABLE_COMPRESSION 1)
255-
set (MONGOC_ENABLE_COMPRESSION_ZLIB 1)
256-
else ()
257-
message (STATUS "Disabling zlib compression")
258-
endif ()
198+
include (CPack)
259199

260200
# Ensure the default behavior: don't ignore RPATH settings.
261201
set (CMAKE_SKIP_BUILD_RPATH OFF)

src/libmongoc/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,66 @@ if (ENABLE_COVERAGE)
3434
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g --coverage")
3535
endif ()
3636

37+
if (NOT ENABLE_ZLIB MATCHES "SYSTEM|AUTO|BUNDLED|OFF")
38+
message (FATAL_ERROR
39+
"ENABLE_ZLIB option must be SYSTEM, BUNDLED, AUTO, or OFF"
40+
)
41+
endif ()
42+
43+
# Disable warnings on bundled zlib source files.
44+
set_source_files_properties (${ZLIB_SOURCES} PROPERTIES COMPILE_FLAGS -w)
45+
46+
# Copy zconf.h.in to zconf.h; even when using system zlib, the 'dist' target
47+
# will look for zconf.h in that location.
48+
configure_file (
49+
"${SOURCE_DIR}/src/zlib-1.2.11/zconf.h.in"
50+
"${CMAKE_BINARY_DIR}/src/zlib-1.2.11/zconf.h"
51+
COPYONLY
52+
)
53+
if (ENABLE_ZLIB MATCHES "SYSTEM|AUTO")
54+
message (STATUS "Searching for zlib CMake packages")
55+
include (FindZLIB)
56+
if (ZLIB_FOUND)
57+
message ("-- zlib found version \"${ZLIB_VERSION_STRING}\"")
58+
message ("-- zlib include path \"${ZLIB_INCLUDE_DIRS}\"")
59+
message ("-- zlib libraries \"${ZLIB_LIBRARIES}\"")
60+
include_directories ("${ZLIB_INCLUDE_DIRS}")
61+
else ()
62+
if (ENABLE_ZLIB STREQUAL "SYSTEM")
63+
message (FATAL_ERROR
64+
"Unable to find system zlib package. Either specify the zlib \
65+
location by setting ZLIB_ROOT, or else set ENABLE_ZLIB=BUNDLED or \
66+
set ENABLE_ZLIB=OFF."
67+
)
68+
endif ()
69+
set (ZLIB_LIBRARIES "")
70+
endif ()
71+
endif ()
72+
73+
if ( (ENABLE_ZLIB STREQUAL "BUNDLED")
74+
OR (ENABLE_ZLIB STREQUAL "AUTO" AND NOT ZLIB_FOUND) )
75+
message (STATUS "Enabling zlib compression (bundled)")
76+
set (SOURCES ${SOURCES} ${ZLIB_SOURCES})
77+
78+
list (
79+
APPEND
80+
MONGOC_INTERNAL_INCLUDE_DIRS
81+
"${SOURCE_DIR}/src/zlib-1.2.11"
82+
"${CMAKE_BINARY_DIR}/src/zlib-1.2.11"
83+
)
84+
endif ()
85+
86+
if (NOT ENABLE_ZLIB STREQUAL "OFF")
87+
# At this point the system zlib was found, or the bundled library was used
88+
include (CheckIncludeFiles)
89+
check_include_files ("unistd.h" HAVE_UNISTD_H)
90+
check_include_files ("stdarg.h" HAVE_STDARG_H)
91+
set (MONGOC_ENABLE_COMPRESSION 1)
92+
set (MONGOC_ENABLE_COMPRESSION_ZLIB 1)
93+
else ()
94+
message (STATUS "Disabling zlib compression")
95+
endif ()
96+
3797
if (NOT ENABLE_SSL STREQUAL OFF)
3898
# Try OpenSSL automatically everywhere but Mac and Windows.
3999
if (ENABLE_SSL STREQUAL "OPENSSL"

0 commit comments

Comments
 (0)