-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
314 lines (271 loc) · 11.5 KB
/
CMakeLists.txt
File metadata and controls
314 lines (271 loc) · 11.5 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
cmake_minimum_required(VERSION 3.14)
project(agent-cpp VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(AGENT_CPP_BUILD_TESTS "Build agent.cpp tests" OFF)
option(AGENT_CPP_BUILD_EXAMPLES "Build agent.cpp examples" OFF)
option(AGENT_CPP_BUNDLED_LLAMA "Bundle llama.cpp (vs. find installed)" ON)
set(LLAMA_CPP_DIR "" CACHE PATH "Path to existing llama.cpp directory (leave empty to use submodule)")
if(AGENT_CPP_BUNDLED_LLAMA)
# Use bundled llama.cpp (submodule or custom path)
if(LLAMA_CPP_DIR)
if(NOT EXISTS "${LLAMA_CPP_DIR}/CMakeLists.txt")
message(FATAL_ERROR "LLAMA_CPP_DIR is set to '${LLAMA_CPP_DIR}' but no CMakeLists.txt found there.")
endif()
set(LLAMA_SOURCE_DIR "${LLAMA_CPP_DIR}")
message(STATUS "Using custom llama.cpp from: ${LLAMA_SOURCE_DIR}")
else()
set(LLAMA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/llama.cpp")
if(NOT EXISTS "${LLAMA_SOURCE_DIR}/CMakeLists.txt")
message(FATAL_ERROR
"llama.cpp submodule not found at ${LLAMA_SOURCE_DIR}\n"
"Please initialize submodules with:\n"
" git submodule update --init --recursive\n"
"Or provide a custom path with -DLLAMA_CPP_DIR=/path/to/llama.cpp"
)
endif()
message(STATUS "Using llama.cpp submodule from: ${LLAMA_SOURCE_DIR}")
endif()
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_COMMON ON CACHE BOOL "" FORCE)
set(LLAMA_CURL OFF CACHE BOOL "" FORCE)
set(LLAMA_HTTPLIB OFF CACHE BOOL "" FORCE)
set(LLAMA_LLGUIDANCE OFF CACHE BOOL "" FORCE)
add_subdirectory(${LLAMA_SOURCE_DIR} ${CMAKE_BINARY_DIR}/llama.cpp)
else()
# Use system-installed llama.cpp
find_package(llama REQUIRED)
message(STATUS "Using system-installed llama.cpp")
endif()
add_library(model STATIC src/model.cpp)
add_library(agent-cpp::model ALIAS model)
target_include_directories(model
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/common>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/ggml/include>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/agent-cpp>
)
target_link_libraries(model PUBLIC common llama)
target_compile_features(model PUBLIC cxx_std_17)
add_library(agent STATIC src/agent.cpp)
add_library(agent-cpp::agent ALIAS agent)
target_include_directories(agent
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/common>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/ggml/include>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/vendor>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/agent-cpp>
)
target_link_libraries(agent PUBLIC model common llama)
target_compile_features(agent PUBLIC cxx_std_17)
# MCP Client library for connecting to MCP servers via HTTP
option(AGENT_CPP_BUILD_MCP "Build MCP client (requires OpenSSL for HTTPS)" OFF)
if(AGENT_CPP_BUILD_MCP)
find_package(OpenSSL REQUIRED)
add_library(mcp_client STATIC
src/mcp/mcp_client.cpp
src/mcp/mcp_tool.cpp
)
add_library(agent-cpp::mcp_client ALIAS mcp_client)
target_include_directories(mcp_client
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/cpp-httplib>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/common>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/agent-cpp>
)
target_link_libraries(mcp_client PUBLIC common OpenSSL::SSL OpenSSL::Crypto)
target_compile_features(mcp_client PUBLIC cxx_std_17)
message(STATUS "MCP client enabled (using cpp-httplib)")
endif()
# OAuth library for handling OAuth 2.0 authorization flows
option(AGENT_CPP_BUILD_OAUTH "Build OAuth client (requires OpenSSL)" OFF)
if(AGENT_CPP_BUILD_OAUTH)
find_package(OpenSSL REQUIRED)
add_library(oauth STATIC
src/oauth/oauth.cpp
src/oauth/token_storage.cpp
)
add_library(agent-cpp::oauth ALIAS oauth)
target_include_directories(oauth
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/cpp-httplib>
$<BUILD_INTERFACE:${LLAMA_SOURCE_DIR}/common>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/agent-cpp>
)
target_link_libraries(oauth PUBLIC common OpenSSL::SSL OpenSSL::Crypto)
target_compile_features(oauth PUBLIC cxx_std_17)
message(STATUS "OAuth client enabled (using cpp-httplib)")
endif()
if(AGENT_CPP_BUILD_TESTS)
enable_testing()
add_executable(test_tool tests/test_tool.cpp)
target_include_directories(test_tool PRIVATE src tests)
target_link_libraries(test_tool PRIVATE common llama)
target_compile_features(test_tool PRIVATE cxx_std_17)
add_executable(test_callbacks tests/test_callbacks.cpp)
target_include_directories(test_callbacks PRIVATE
src
tests
${LLAMA_SOURCE_DIR}/common
${LLAMA_SOURCE_DIR}/ggml/include
${LLAMA_SOURCE_DIR}/include
${LLAMA_SOURCE_DIR}/vendor
)
target_link_libraries(test_callbacks PRIVATE agent model common llama)
target_compile_features(test_callbacks PRIVATE cxx_std_17)
add_test(NAME ToolTests COMMAND test_tool)
add_test(NAME CallbacksTests COMMAND test_callbacks)
if(AGENT_CPP_BUILD_MCP)
add_executable(test_mcp_client tests/test_mcp_client.cpp)
target_include_directories(test_mcp_client PRIVATE
src
tests
${LLAMA_SOURCE_DIR}/common
)
target_link_libraries(test_mcp_client PRIVATE mcp_client common)
target_compile_features(test_mcp_client PRIVATE cxx_std_17)
add_test(NAME MCPClientTests COMMAND test_mcp_client)
endif()
# On Windows, DLLs are placed in the bin/ directory by llama.cpp
# We need to add this directory to PATH so tests can find the DLLs
if(WIN32)
set_tests_properties(ToolTests CallbacksTests PROPERTIES
ENVIRONMENT "PATH=${CMAKE_BINARY_DIR}/bin\;$ENV{PATH}"
)
endif()
message(STATUS "Tests enabled. Run with: ctest or ./test_tool")
endif()
if(AGENT_CPP_BUILD_EXAMPLES)
# Shell example
add_executable(shell-example examples/shell/shell.cpp)
target_include_directories(shell-example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
${LLAMA_SOURCE_DIR}/common
${LLAMA_SOURCE_DIR}/ggml/include
${LLAMA_SOURCE_DIR}/include
${LLAMA_SOURCE_DIR}/vendor
)
target_link_libraries(shell-example PRIVATE agent model common llama)
target_compile_features(shell-example PRIVATE cxx_std_17)
# Memory example
add_executable(memory-example examples/memory/memory.cpp)
target_include_directories(memory-example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
${LLAMA_SOURCE_DIR}/common
${LLAMA_SOURCE_DIR}/ggml/include
${LLAMA_SOURCE_DIR}/include
${LLAMA_SOURCE_DIR}/vendor
)
target_link_libraries(memory-example PRIVATE agent model common llama)
target_compile_features(memory-example PRIVATE cxx_std_17)
# Multi-agent example
add_executable(multi-agent-example examples/multi-agent/multi-agent.cpp)
target_include_directories(multi-agent-example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
${LLAMA_SOURCE_DIR}/common
${LLAMA_SOURCE_DIR}/ggml/include
${LLAMA_SOURCE_DIR}/include
${LLAMA_SOURCE_DIR}/vendor
)
target_link_libraries(multi-agent-example PRIVATE agent model common llama)
target_compile_features(multi-agent-example PRIVATE cxx_std_17)
# Context engineering example
add_executable(context-engineering-example examples/context-engineering/context-engineering.cpp)
target_include_directories(context-engineering-example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
${LLAMA_SOURCE_DIR}/common
${LLAMA_SOURCE_DIR}/ggml/include
${LLAMA_SOURCE_DIR}/include
${LLAMA_SOURCE_DIR}/vendor
)
target_link_libraries(context-engineering-example PRIVATE agent model common llama)
target_compile_features(context-engineering-example PRIVATE cxx_std_17)
# MCP client example (requires MCP support)
if(AGENT_CPP_BUILD_MCP)
add_executable(mcp-example examples/mcp/mcp.cpp)
target_include_directories(mcp-example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
${LLAMA_SOURCE_DIR}/common
${LLAMA_SOURCE_DIR}/ggml/include
${LLAMA_SOURCE_DIR}/include
${LLAMA_SOURCE_DIR}/vendor
)
target_link_libraries(mcp-example PRIVATE agent model mcp_client common llama)
target_compile_features(mcp-example PRIVATE cxx_std_17)
endif()
# Note: tracing-example is not included here as it requires additional
# dependencies (OpenTelemetry, protobuf, curl). Build it separately from
# examples/tracing/
message(STATUS "Examples enabled.")
endif()
option(AGENT_CPP_INSTALL "Generate install target" OFF)
if(AGENT_CPP_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Install public headers
set(INSTALL_HEADERS
src/agent.h
src/callbacks.h
src/error.h
src/model.h
src/tool.h
)
if(AGENT_CPP_BUILD_MCP)
list(APPEND INSTALL_HEADERS src/mcp/mcp_client.h src/mcp/mcp_tool.h)
endif()
install(FILES ${INSTALL_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/agent-cpp
)
# Install libraries with export set
set(INSTALL_TARGETS agent model)
if(AGENT_CPP_BUILD_MCP)
list(APPEND INSTALL_TARGETS mcp_client)
endif()
install(TARGETS ${INSTALL_TARGETS}
EXPORT agent-cpp-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Generate and install the export targets file
install(EXPORT agent-cpp-targets
FILE agent-cpp-targets.cmake
NAMESPACE agent-cpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/agent-cpp
)
# Generate the version file for find_package version checking
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/agent-cpp-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
# Generate the config file from template
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/agent-cpp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/agent-cpp-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/agent-cpp
)
# Install the CMake config files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/agent-cpp-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/agent-cpp-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/agent-cpp
)
message(STATUS "Install target enabled. Install with: cmake --install build --prefix /your/path")
endif()