Skip to content

Commit

Permalink
define CPPHTTPLIB_ZLIB_SUPPORT (#13)
Browse files Browse the repository at this point in the history
* define CPPHTTPLIB_ZLIB_SUPPORT

required to support gzip content

* Update CMakeLists.txt

* Conditional ZLIB support

* Update http_client_extension.cpp
  • Loading branch information
lmangani authored Nov 16, 2024
1 parent 9b00634 commit d3a3dee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
60 changes: 42 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,66 @@ cmake_minimum_required(VERSION 3.5)
# Set extension name here
set(TARGET_NAME http_client)

# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it..
# Make ZLIB support optional with default ON for desktop platforms and OFF for WASM
if(EMSCRIPTEN)
option(USE_ZLIB "Enable ZLIB compression support" OFF)
else()
option(USE_ZLIB "Enable ZLIB compression support" ON)
endif()

# Find OpenSSL before building extensions
find_package(OpenSSL REQUIRED)

set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)

project(${TARGET_NAME})

include_directories(src/include duckdb/third_party/httplib)

set(EXTENSION_SOURCES src/http_client_extension.cpp)

if(MINGW)
set(OPENSSL_USE_STATIC_LIBS TRUE)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()

# Find OpenSSL before building extensions
find_package(OpenSSL REQUIRED)
# Common libraries needed for both targets
set(COMMON_LIBS
duckdb_mbedtls
${OPENSSL_LIBRARIES}
)

# Handle ZLIB support
if(USE_ZLIB)
find_package(ZLIB)
if(ZLIB_FOUND)
add_compile_definitions(CPPHTTPLIB_ZLIB_SUPPORT)
list(APPEND COMMON_LIBS ZLIB::ZLIB)
message(STATUS "Building with ZLIB support")
else()
message(STATUS "ZLIB not found, building without ZLIB support")
endif()
endif()

# Windows-specific libraries
if(MINGW)
set(WIN_LIBS crypt32 ws2_32 wsock32)
list(APPEND COMMON_LIBS ${WIN_LIBS})
endif()

# Build extensions
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})

# Include directories
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(${LOADABLE_EXTENSION_NAME} duckdb_mbedtls ${OPENSSL_LIBRARIES})
target_link_libraries(${EXTENSION_NAME} duckdb_mbedtls ${OPENSSL_LIBRARIES})

if(MINGW)
set(WIN_LIBS crypt32 ws2_32 wsock32)
find_package(ZLIB)
target_link_libraries(${LOADABLE_EXTENSION_NAME} ZLIB::ZLIB ${WIN_LIBS})
target_link_libraries(${EXTENSION_NAME} ZLIB::ZLIB ${WIN_LIBS})
endif()
# Link libraries
target_link_libraries(${LOADABLE_EXTENSION_NAME} ${COMMON_LIBS})
target_link_libraries(${EXTENSION_NAME} ${COMMON_LIBS})

install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")
4 changes: 4 additions & 0 deletions src/http_client_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "duckdb/common/exception/http_exception.hpp"
#include <duckdb/parser/parsed_data/create_scalar_function_info.hpp>

#ifdef USE_ZLIB
#define CPPHTTPLIB_ZLIB_SUPPORT
#endif

#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.hpp"

Expand Down

0 comments on commit d3a3dee

Please sign in to comment.