Skip to content

Commit fad98fa

Browse files
authored
Conditional ZLIB support
1 parent c40258c commit fad98fa

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

CMakeLists.txt

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ cmake_minimum_required(VERSION 3.5)
33
# Set extension name here
44
set(TARGET_NAME http_client)
55

6-
# Add ZLIB definition for httplib
7-
add_compile_definitions(CPPHTTPLIB_ZLIB_SUPPORT)
6+
# Make ZLIB support optional with default ON for desktop platforms and OFF for WASM
7+
if(EMSCRIPTEN)
8+
option(USE_ZLIB "Enable ZLIB compression support" OFF)
9+
else()
10+
option(USE_ZLIB "Enable ZLIB compression support" ON)
11+
endif()
812

9-
# Find required packages
13+
# Find OpenSSL before building extensions
1014
find_package(OpenSSL REQUIRED)
11-
find_package(ZLIB REQUIRED)
1215

1316
set(EXTENSION_NAME ${TARGET_NAME}_extension)
1417
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
@@ -20,35 +23,46 @@ include_directories(src/include duckdb/third_party/httplib)
2023
set(EXTENSION_SOURCES src/http_client_extension.cpp)
2124

2225
if(MINGW)
23-
set(OPENSSL_USE_STATIC_LIBS TRUE)
26+
set(OPENSSL_USE_STATIC_LIBS TRUE)
2427
endif()
2528

26-
# Build extensions
27-
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
28-
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
29-
30-
# Include directories
31-
include_directories(${OPENSSL_INCLUDE_DIR})
32-
3329
# Common libraries needed for both targets
3430
set(COMMON_LIBS
3531
duckdb_mbedtls
3632
${OPENSSL_LIBRARIES}
37-
ZLIB::ZLIB
3833
)
3934

35+
# Handle ZLIB support
36+
if(USE_ZLIB)
37+
find_package(ZLIB)
38+
if(ZLIB_FOUND)
39+
add_compile_definitions(CPPHTTPLIB_ZLIB_SUPPORT)
40+
list(APPEND COMMON_LIBS ZLIB::ZLIB)
41+
message(STATUS "Building with ZLIB support")
42+
else()
43+
message(STATUS "ZLIB not found, building without ZLIB support")
44+
endif()
45+
endif()
46+
4047
# Windows-specific libraries
4148
if(MINGW)
42-
set(WIN_LIBS crypt32 ws2_32 wsock32)
43-
list(APPEND COMMON_LIBS ${WIN_LIBS})
49+
set(WIN_LIBS crypt32 ws2_32 wsock32)
50+
list(APPEND COMMON_LIBS ${WIN_LIBS})
4451
endif()
4552

53+
# Build extensions
54+
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
55+
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
56+
57+
# Include directories
58+
include_directories(${OPENSSL_INCLUDE_DIR})
59+
4660
# Link libraries
4761
target_link_libraries(${LOADABLE_EXTENSION_NAME} ${COMMON_LIBS})
4862
target_link_libraries(${EXTENSION_NAME} ${COMMON_LIBS})
4963

5064
install(
51-
TARGETS ${EXTENSION_NAME}
52-
EXPORT "${DUCKDB_EXPORT_SET}"
53-
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
54-
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")
65+
TARGETS ${EXTENSION_NAME}
66+
EXPORT "${DUCKDB_EXPORT_SET}"
67+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
68+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")

0 commit comments

Comments
 (0)