if (WIN32 OR BUILD_STATIC_EXTENSION)
    set(DuckDB_USE_STATIC_LIBS ON)
else ()
    set(DuckDB_USE_STATIC_LIBS OFF)
endif ()
find_package(DuckDB REQUIRED)

include_directories(
        ${PROJECT_SOURCE_DIR}/src/include
        ${CMAKE_BINARY_DIR}/src/include
        src/include
        ${PROJECT_SOURCE_DIR}/extension/duckdb/src/include
        ${PROJECT_SOURCE_DIR}/extension/httpfs/src/include
        ${PROJECT_SOURCE_DIR}/extension/delta/src/include
        ${DuckDB_INCLUDE_DIRS}
)

add_subdirectory(src/function)
add_subdirectory(src/connector)
add_subdirectory(src/installer)
add_subdirectory(src/main)

build_extension_lib(${BUILD_STATIC_EXTENSION} "iceberg")

add_library(delta_connector
    ${PROJECT_SOURCE_DIR}/extension/delta/src/connector/delta_connector.cpp
    ${PROJECT_SOURCE_DIR}/extension/duckdb/src/connector/duckdb_secret_manager.cpp
    ${PROJECT_SOURCE_DIR}/extension/duckdb/src/connector/duckdb_connector.cpp
    ${PROJECT_SOURCE_DIR}/extension/duckdb/src/function/duckdb_scan.cpp
    ${PROJECT_SOURCE_DIR}/extension/httpfs/src/s3fs_config.cpp
)

target_include_directories(delta_connector PRIVATE
    ${PROJECT_SOURCE_DIR}/extension/delta/src/include
    ${PROJECT_SOURCE_DIR}/extension/duckdb/src/include
    ${PROJECT_SOURCE_DIR}/extension/httpfs/src/include
)

target_link_libraries(kuzu_${EXTENSION_LIB_NAME}_extension
        PRIVATE
        ${DuckDB_LIBRARIES}
        delta_connector)

if (NOT WIN32 AND NOT BUILD_STATIC_EXTENSION)
    add_library(iceberg_loader
            SHARED
            ../duckdb/src/loader/duckdb_loader.cpp)
    set_extension_properties(iceberg_loader iceberg_loader iceberg)
endif ()

if (APPLE AND NOT BUILD_STATIC_EXTENSION)
    set_apple_dynamic_lookup(iceberg_loader)
endif ()
