Skip to content

Commit d3a3dee

Browse files
authored
define CPPHTTPLIB_ZLIB_SUPPORT (#13)
* define CPPHTTPLIB_ZLIB_SUPPORT required to support gzip content * Update CMakeLists.txt * Conditional ZLIB support * Update http_client_extension.cpp
1 parent 9b00634 commit d3a3dee

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

CMakeLists.txt

+42-18
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,66 @@ cmake_minimum_required(VERSION 3.5)
33
# Set extension name here
44
set(TARGET_NAME http_client)
55

6-
# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
7-
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
8-
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it..
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()
12+
13+
# Find OpenSSL before building extensions
914
find_package(OpenSSL REQUIRED)
1015

1116
set(EXTENSION_NAME ${TARGET_NAME}_extension)
1217
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
1318

1419
project(${TARGET_NAME})
20+
1521
include_directories(src/include duckdb/third_party/httplib)
1622

1723
set(EXTENSION_SOURCES src/http_client_extension.cpp)
1824

1925
if(MINGW)
20-
set(OPENSSL_USE_STATIC_LIBS TRUE)
26+
set(OPENSSL_USE_STATIC_LIBS TRUE)
2127
endif()
2228

23-
# Find OpenSSL before building extensions
24-
find_package(OpenSSL REQUIRED)
29+
# Common libraries needed for both targets
30+
set(COMMON_LIBS
31+
duckdb_mbedtls
32+
${OPENSSL_LIBRARIES}
33+
)
2534

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+
47+
# Windows-specific libraries
48+
if(MINGW)
49+
set(WIN_LIBS crypt32 ws2_32 wsock32)
50+
list(APPEND COMMON_LIBS ${WIN_LIBS})
51+
endif()
52+
53+
# Build extensions
2654
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
2755
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
2856

57+
# Include directories
2958
include_directories(${OPENSSL_INCLUDE_DIR})
30-
target_link_libraries(${LOADABLE_EXTENSION_NAME} duckdb_mbedtls ${OPENSSL_LIBRARIES})
31-
target_link_libraries(${EXTENSION_NAME} duckdb_mbedtls ${OPENSSL_LIBRARIES})
3259

33-
if(MINGW)
34-
set(WIN_LIBS crypt32 ws2_32 wsock32)
35-
find_package(ZLIB)
36-
target_link_libraries(${LOADABLE_EXTENSION_NAME} ZLIB::ZLIB ${WIN_LIBS})
37-
target_link_libraries(${EXTENSION_NAME} ZLIB::ZLIB ${WIN_LIBS})
38-
endif()
60+
# Link libraries
61+
target_link_libraries(${LOADABLE_EXTENSION_NAME} ${COMMON_LIBS})
62+
target_link_libraries(${EXTENSION_NAME} ${COMMON_LIBS})
3963

4064
install(
41-
TARGETS ${EXTENSION_NAME}
42-
EXPORT "${DUCKDB_EXPORT_SET}"
43-
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
44-
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}")

src/http_client_extension.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "duckdb/common/exception/http_exception.hpp"
1010
#include <duckdb/parser/parsed_data/create_scalar_function_info.hpp>
1111

12+
#ifdef USE_ZLIB
13+
#define CPPHTTPLIB_ZLIB_SUPPORT
14+
#endif
15+
1216
#define CPPHTTPLIB_OPENSSL_SUPPORT
1317
#include "httplib.hpp"
1418

0 commit comments

Comments
 (0)