Skip to content

Commit e0007b7

Browse files
committed
fix build of bundled zlib
Ensure that the target for the bundled zlib is only built when the bundled target is needed. Also ensure that the build always correctly finds the necessary headers. For instance, even if there is a zlib installed on the system and the build specifies the bundled zlib, ensure that bundled headers are located before the system headers.
1 parent 1bc7a46 commit e0007b7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,6 @@ if (ENABLE_MONGOC)
287287
${SOURCE_DIR}/src/zlib-1.2.11/gzread.c
288288
${SOURCE_DIR}/src/zlib-1.2.11/gzwrite.c
289289
)
290-
add_library (zlib_obj OBJECT "${ZLIB_SOURCES}")
291-
set_property (TARGET zlib_obj PROPERTY POSITION_INDEPENDENT_CODE TRUE)
292-
# Disable all warnings for compiling Zlib
293-
target_compile_options (zlib_obj PRIVATE -w)
294290

295291
set (MONGOC_ENABLE_ICU 0)
296292

src/libmongoc/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,18 @@ endif ()
7575
if ( (ENABLE_ZLIB STREQUAL "BUNDLED")
7676
OR (ENABLE_ZLIB STREQUAL "AUTO" AND NOT ZLIB_FOUND) )
7777
message (STATUS "Enabling zlib compression (bundled)")
78+
add_library (zlib_obj OBJECT "${ZLIB_SOURCES}")
79+
set_property (TARGET zlib_obj PROPERTY POSITION_INDEPENDENT_CODE TRUE)
80+
# This tells the bundled zlib where to find its generated headers
81+
target_include_directories (zlib_obj
82+
BEFORE PUBLIC
83+
"${SOURCE_DIR}/src/zlib-1.2.11"
84+
"${CMAKE_BINARY_DIR}/src/zlib-1.2.11"
85+
)
86+
# Disable all warnings for compiling Zlib
87+
target_compile_options (zlib_obj PRIVATE -w)
7888
set (SOURCES ${SOURCES} $<TARGET_OBJECTS:zlib_obj>)
89+
# This tells mongoc_shared/mongoc_static where to find generated zlib headers
7990
set (
8091
ZLIB_INCLUDE_DIRS
8192
"${SOURCE_DIR}/src/zlib-1.2.11"

0 commit comments

Comments
 (0)