Skip to content

Commit

Permalink
Conditional ZLIB support
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani authored Nov 16, 2024
1 parent c40258c commit fad98fa
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ cmake_minimum_required(VERSION 3.5)
# Set extension name here
set(TARGET_NAME http_client)

# Add ZLIB definition for httplib
add_compile_definitions(CPPHTTPLIB_ZLIB_SUPPORT)
# 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 required packages
# Find OpenSSL before building extensions
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)

set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
Expand All @@ -20,35 +23,46 @@ 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()

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

# Include directories
include_directories(${OPENSSL_INCLUDE_DIR})

# Common libraries needed for both targets
set(COMMON_LIBS
duckdb_mbedtls
${OPENSSL_LIBRARIES}
ZLIB::ZLIB
)

# 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})
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})

# 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}")

0 comments on commit fad98fa

Please sign in to comment.