-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
293 lines (253 loc) · 8.02 KB
/
CMakeLists.txt
File metadata and controls
293 lines (253 loc) · 8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
cmake_minimum_required(VERSION 3.16)
# Project definition
project(ai-sdk-cpp
VERSION 0.1.0
DESCRIPTION "A unified C++ SDK for multiple AI/LLM providers"
LANGUAGES CXX
)
# C++20 requirement
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Build options
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_EXAMPLES "Build example applications" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
# 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
)
# Create libraries
add_library(ai-sdk-cpp-core)
add_library(ai-sdk-cpp-openai)
add_library(ai-sdk-cpp-anthropic)
add_library(ai-sdk-cpp-langfuse)
add_library(ai-sdk-cpp INTERFACE)
# 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)
add_library(ai::langfuse ALIAS ai-sdk-cpp-langfuse)
# 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_ai_component(ai-sdk-cpp-langfuse)
# Configure main interface library
target_include_directories(ai-sdk-cpp
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Core component sources
target_sources(ai-sdk-cpp-core
PRIVATE
# Type implementations
src/types/generate_options.cpp
src/types/stream_options.cpp
src/types/stream_result.cpp
src/types/message.cpp
# HTTP and base provider infrastructure
src/http/http_request_handler.cpp
src/providers/base_provider_client.cpp
# Tool calling implementations
src/tools/tool_executor.cpp
src/tools/multi_step_coordinator.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
)
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
)
target_sources(ai-sdk-cpp-openai PRIVATE ${OPENAI_SOURCES})
target_sources(ai-sdk-cpp-anthropic PRIVATE ${ANTHROPIC_SOURCES})
# Langfuse tracing component
target_sources(ai-sdk-cpp-langfuse
PRIVATE
src/langfuse/tracer.cpp
)
# Link dependencies
target_link_libraries(ai-sdk-cpp-core
PUBLIC
nlohmann_json::nlohmann_json
PRIVATE
$<BUILD_INTERFACE:httplib::httplib>
$<BUILD_INTERFACE:OpenSSL::SSL>
$<BUILD_INTERFACE:OpenSSL::Crypto>
$<BUILD_INTERFACE: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()
# Langfuse tracing component links to core and uses httplib + OpenSSL +
# stduuid (header-only, vendored under third_party/stduuid-header-only).
target_link_libraries(ai-sdk-cpp-langfuse
PUBLIC
ai::core
nlohmann_json::nlohmann_json
PRIVATE
$<BUILD_INTERFACE:httplib::httplib>
$<BUILD_INTERFACE:OpenSSL::SSL>
$<BUILD_INTERFACE:OpenSSL::Crypto>
$<BUILD_INTERFACE:stduuid::stduuid>
)
target_compile_definitions(ai-sdk-cpp-langfuse
PUBLIC
AI_SDK_HAS_LANGFUSE=1
PRIVATE
${HTTPLIB_COMPILE_DEFS}
)
# Core needs HTTP definitions too
target_compile_definitions(ai-sdk-cpp-core
PRIVATE
${HTTPLIB_COMPILE_DEFS}
)
# Main library links all components
target_link_libraries(ai-sdk-cpp
INTERFACE
ai::core
ai::openai
ai::anthropic
ai::langfuse
)
# Define all component availability for main library
target_compile_definitions(ai-sdk-cpp
INTERFACE
AI_SDK_HAS_OPENAI=1
AI_SDK_HAS_ANTHROPIC=1
AI_SDK_HAS_LANGFUSE=1
)
# List of all concrete component targets
set(COMPONENT_TARGETS
ai-sdk-cpp-core
ai-sdk-cpp-openai
ai-sdk-cpp-anthropic
ai-sdk-cpp-langfuse
)
# 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}>
)
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
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Tests
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# Installation rules
include(GNUInstallDirs)
# 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}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Install headers
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
# Export targets
install(EXPORT ai-sdk-cpp-targets
FILE ai-sdk-cpp-targets.cmake
NAMESPACE ai::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ai-sdk-cpp
)
# Create and install config file
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/ai-sdk-cpp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ai-sdk-cpp-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ai-sdk-cpp
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ai-sdk-cpp-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ai-sdk-cpp-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ai-sdk-cpp-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ai-sdk-cpp
)
# Print configuration summary
message(STATUS "")
message(STATUS "ai-sdk-cpp ${PROJECT_VERSION} Configuration Summary")
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS " C++ standard: ${CMAKE_CXX_STANDARD}")
message(STATUS " Build examples: ${BUILD_EXAMPLES}")
message(STATUS " Build tests: ${BUILD_TESTS}")
message(STATUS " Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "")