Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install uv
uses: astral-sh/setup-uv@v6
Expand Down
18 changes: 18 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[submodule "third_party/nlohmann_json"]
path = third_party/nlohmann_json
url = https://github.com/nlohmann/json.git
[submodule "third_party/concurrentqueue"]
path = third_party/concurrentqueue
url = https://github.com/cameron314/concurrentqueue.git
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://github.com/madler/zlib.git
[submodule "third_party/brotli"]
path = third_party/brotli
url = https://github.com/google/brotli.git
[submodule "third_party/httplib"]
path = third_party/httplib
url = https://github.com/yhirose/cpp-httplib.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
251 changes: 109 additions & 142 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,48 @@ option(BUILD_TESTS "Build tests" OFF)
option(BUILD_EXAMPLES "Build example applications" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

# Include CPM package manager
include(cmake/CPM.cmake)

# Include all dependencies
include(cmake/dependencies/nlohmann_json.cmake)
include(cmake/dependencies/openssl.cmake)
include(cmake/dependencies/httplib.cmake) # This will include zlib and brotli
include(cmake/dependencies/concurrentqueue.cmake)
# Add third party directory with submodules
add_subdirectory(third_party)

# Find system OpenSSL
find_package(OpenSSL REQUIRED)

# Helper function to configure component libraries
function(configure_ai_component target_name)
target_include_directories(${target_name}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
endfunction()

# Common compile definitions for HTTP support
set(HTTPLIB_COMPILE_DEFS
CPPHTTPLIB_OPENSSL_SUPPORT=1
CPPHTTPLIB_BROTLI_SUPPORT=1
CPPHTTPLIB_THREAD_POOL_COUNT=8
)

# Core library target (always built)
# Create libraries
add_library(ai-sdk-cpp-core)

# OpenAI component library
add_library(ai-sdk-cpp-openai)

# Anthropic component library
add_library(ai-sdk-cpp-anthropic)

# Main library target (includes all components) - interface library
add_library(ai-sdk-cpp INTERFACE)

# Set library aliases for consistent naming
# Set library aliases
add_library(ai::sdk ALIAS ai-sdk-cpp)
add_library(ai::core ALIAS ai-sdk-cpp-core)
add_library(ai::openai ALIAS ai-sdk-cpp-openai)
add_library(ai::anthropic ALIAS ai-sdk-cpp-anthropic)

# Configure core library
target_include_directories(ai-sdk-cpp-core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Configure all component libraries
configure_ai_component(ai-sdk-cpp-core)
configure_ai_component(ai-sdk-cpp-openai)
configure_ai_component(ai-sdk-cpp-anthropic)

# Configure OpenAI component library
target_include_directories(ai-sdk-cpp-openai
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# Configure Anthropic component library
target_include_directories(ai-sdk-cpp-anthropic
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# Configure main library (includes all components) - interface only
# Configure main interface library
target_include_directories(ai-sdk-cpp
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -96,131 +83,110 @@ target_sources(ai-sdk-cpp-core
src/tools/multi_step_coordinator.cpp
)

# OpenAI component sources
target_sources(ai-sdk-cpp-openai
PRIVATE
# OpenAI provider implementations
src/providers/openai/openai_client.cpp
src/providers/openai/openai_request_builder.cpp
src/providers/openai/openai_response_parser.cpp
src/providers/openai/openai_stream.cpp
src/providers/openai/openai_factory.cpp
# Provider-specific sources
set(OPENAI_SOURCES
src/providers/openai/openai_client.cpp
src/providers/openai/openai_request_builder.cpp
src/providers/openai/openai_response_parser.cpp
src/providers/openai/openai_stream.cpp
src/providers/openai/openai_factory.cpp
)

# Anthropic component sources
target_sources(ai-sdk-cpp-anthropic
PRIVATE
# Anthropic provider implementations
src/providers/anthropic/anthropic_client.cpp
src/providers/anthropic/anthropic_request_builder.cpp
src/providers/anthropic/anthropic_response_parser.cpp
src/providers/anthropic/anthropic_stream.cpp
src/providers/anthropic/anthropic_factory.cpp
set(ANTHROPIC_SOURCES
src/providers/anthropic/anthropic_client.cpp
src/providers/anthropic/anthropic_request_builder.cpp
src/providers/anthropic/anthropic_response_parser.cpp
src/providers/anthropic/anthropic_stream.cpp
src/providers/anthropic/anthropic_factory.cpp
)

# Link dependencies for core component
target_link_libraries(ai-sdk-cpp-core
PUBLIC
nlohmann_json::nlohmann_json
PRIVATE
httplib::httplib
OpenSSL::SSL
OpenSSL::Crypto
concurrentqueue
)
target_sources(ai-sdk-cpp-openai PRIVATE ${OPENAI_SOURCES})
target_sources(ai-sdk-cpp-anthropic PRIVATE ${ANTHROPIC_SOURCES})

# Link dependencies for OpenAI component
target_link_libraries(ai-sdk-cpp-openai
# Link dependencies
target_link_libraries(ai-sdk-cpp-core
PUBLIC
ai::core
nlohmann_json::nlohmann_json
PRIVATE
httplib::httplib
concurrentqueue
$<BUILD_INTERFACE:httplib::httplib>
$<BUILD_INTERFACE:OpenSSL::SSL>
$<BUILD_INTERFACE:OpenSSL::Crypto>
$<BUILD_INTERFACE:concurrentqueue>
)

# Define component availability for OpenAI
target_compile_definitions(ai-sdk-cpp-openai
PUBLIC
AI_SDK_HAS_OPENAI=1
PRIVATE
${HTTPLIB_DEFINITIONS}
)

# Link dependencies for Anthropic component
target_link_libraries(ai-sdk-cpp-anthropic
PUBLIC
ai::core
nlohmann_json::nlohmann_json
PRIVATE
httplib::httplib
concurrentqueue
)
# Provider components link to core and share common dependencies
foreach(provider openai anthropic)
target_link_libraries(ai-sdk-cpp-${provider}
PUBLIC
ai::core
nlohmann_json::nlohmann_json
PRIVATE
$<BUILD_INTERFACE:httplib::httplib>
$<BUILD_INTERFACE:concurrentqueue>
)

# Set component availability and HTTP definitions
string(TOUPPER ${provider} PROVIDER_UPPER)
target_compile_definitions(ai-sdk-cpp-${provider}
PUBLIC
AI_SDK_HAS_${PROVIDER_UPPER}=1
PRIVATE
${HTTPLIB_COMPILE_DEFS}
)
endforeach()

# Define component availability for Anthropic
target_compile_definitions(ai-sdk-cpp-anthropic
PUBLIC
AI_SDK_HAS_ANTHROPIC=1
# Core needs HTTP definitions too
target_compile_definitions(ai-sdk-cpp-core
PRIVATE
${HTTPLIB_DEFINITIONS}
${HTTPLIB_COMPILE_DEFS}
)

# Main library links all components (interface)
# Main library links all components
target_link_libraries(ai-sdk-cpp
INTERFACE
ai::core
ai::openai
ai::anthropic
)

# Define all component availability for main library (interface)
# Define all component availability for main library
target_compile_definitions(ai-sdk-cpp
INTERFACE
AI_SDK_HAS_OPENAI=1
AI_SDK_HAS_ANTHROPIC=1
)

# Define httplib configuration for core (where HTTP is used)
target_compile_definitions(ai-sdk-cpp-core
PRIVATE
${HTTPLIB_DEFINITIONS}
)

# Compiler-specific options for concrete components
target_compile_features(ai-sdk-cpp-core PRIVATE cxx_std_20)
target_compile_features(ai-sdk-cpp-openai PRIVATE cxx_std_20)
target_compile_features(ai-sdk-cpp-anthropic PRIVATE cxx_std_20)

# Set appropriate compile options for concrete components (not interface library)
foreach(target ai-sdk-cpp-core ai-sdk-cpp-openai ai-sdk-cpp-anthropic)
if(MSVC)
target_compile_options(${target} PRIVATE /W4)
# Add Windows-specific definitions for better compatibility
target_compile_definitions(${target} PRIVATE
WIN32_LEAN_AND_MEAN
NOMINMAX
_WIN32_WINNT=0x0601 # Windows 7+
)
else()
target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic)
# Add Unix-specific compile options for better compatibility
if(APPLE)
target_compile_options(${target} PRIVATE -stdlib=libc++)
endif()
# List of all concrete component targets
set(COMPONENT_TARGETS ai-sdk-cpp-core ai-sdk-cpp-openai ai-sdk-cpp-anthropic)

# Common compile options
if(MSVC)
set(COMMON_WARNINGS /W4)
set(COMMON_PLATFORM_DEFS WIN32_LEAN_AND_MEAN NOMINMAX _WIN32_WINNT=0x0601)
set(DEBUG_FLAGS)
set(RELEASE_FLAGS)
else()
set(COMMON_WARNINGS -Wall -Wextra -Wpedantic)
set(DEBUG_FLAGS -g -O0)
set(RELEASE_FLAGS -O3)
if(APPLE)
list(APPEND COMMON_WARNINGS -stdlib=libc++)
endif()
endif()

# Apply common options to all components
foreach(target ${COMPONENT_TARGETS})
target_compile_options(${target} PRIVATE
${COMMON_WARNINGS}
$<$<CONFIG:Debug>:${DEBUG_FLAGS}>
$<$<CONFIG:Release>:${RELEASE_FLAGS}>
)

# Set build-specific options
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${target} PRIVATE AI_SDK_DEBUG=1)
if(NOT MSVC)
target_compile_options(${target} PRIVATE -g -O0)
endif()
else()
target_compile_definitions(${target} PRIVATE AI_SDK_RELEASE=1)
if(NOT MSVC)
target_compile_options(${target} PRIVATE -O3 -DNDEBUG)
endif()
endif()
target_compile_definitions(${target} PRIVATE
$<$<CONFIG:Debug>:AI_SDK_DEBUG=1>
$<$<CONFIG:Release>:AI_SDK_RELEASE=1;NDEBUG>
$<$<BOOL:${MSVC}>:${COMMON_PLATFORM_DEFS}>
)
endforeach()

# Examples
Expand All @@ -230,15 +196,16 @@ endif()

# Tests
if(BUILD_TESTS)
include(cmake/dependencies/googletest.cmake)
enable_testing()
add_subdirectory(tests)
endif()

# Installation rules
include(GNUInstallDirs)

# Install all library components
install(TARGETS ai-sdk-cpp-core ai-sdk-cpp-openai ai-sdk-cpp-anthropic ai-sdk-cpp
# Install all targets (httplib is internal only, not installed)
set(ALL_TARGETS ${COMPONENT_TARGETS} ai-sdk-cpp nlohmann_json)
install(TARGETS ${ALL_TARGETS}
EXPORT ai-sdk-cpp-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
24 changes: 0 additions & 24 deletions cmake/CPM.cmake

This file was deleted.

14 changes: 0 additions & 14 deletions cmake/dependencies/concurrentqueue.cmake

This file was deleted.

Loading