From 9177a7340980b7ef870802b385a340846fc6517a Mon Sep 17 00:00:00 2001 From: donington Date: Sun, 31 May 2026 10:54:56 -0400 Subject: [PATCH] feat: external cpp-httplib and nlohmann-json support - define CPP_HTTPLIB_PATH and NLOHMAN_JSON_PATH to override where the headers are pulled in from - optionally uses git submodule to pull headers from lib/ - fallback to builtin libraries in common/ --- .gitignore | 1 + .gitmodules | 2 +- CMakeLists.txt | 30 ++++++++++++++++++++ common/{ => cpp-httplib}/httplib.h | 0 common/{ => nlohmann-json/nlohmann}/json.hpp | 0 include/mcp_message.h | 4 +-- 6 files changed, 34 insertions(+), 3 deletions(-) rename common/{ => cpp-httplib}/httplib.h (100%) rename common/{ => nlohmann-json/nlohmann}/json.hpp (100%) diff --git a/.gitignore b/.gitignore index 1013fc6..fe6d6b4 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ build* !build-info.sh !build.zig !docs/build.md +lib/** /libllama.so /llama-* /vulkan-shaders-gen diff --git a/.gitmodules b/.gitmodules index 42dd527..6889aed 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "test/googletest"] path = test/googletest - url = https://github.com/google/googletest.git \ No newline at end of file + url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d9e026..7337ea2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,36 @@ endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common) +if(DEFINED CPP_HTTPLIB_PATH) + if (IS_DIRECTORY ${CPP_HTTPLIB_PATH} AND EXISTS ${CPP_HTTPLIB_PATH}/httplib.h) + message(STATUS "Using user provided cpp-httplib: ${CPP_HTTPLIB_PATH}") + include_directories(${CPP_HTTPLIB_PATH}) + else() + message(FATAL_ERROR "user provided cpp-httplib not found") + endif() +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp-httplib) + message(STATUS "Using git submodule provided cpp-httplib") + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp-httplib) +else() + message(STATUS "Using builtin provided cpp-httplib") + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/cpp-httplib) +endif() + +if(DEFINED NLOHMANN_JSON_PATH) + if (IS_DIRECTORY ${NLOHMANN_JSON_PATH}/include) #AND EXISTS ${NLOHMANN_JSON_PATH}/include/nlohmann/json.hpp) + message(STATUS "Using user provided nlohmann-json: ${NLOHMANN_JSON_PATH}") + include_directories(${NLOHMANN_JSON_PATH}/include) + else() + message(FATAL_ERROR "user provided nlohmann-json not found") + endif() +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/nlohmann-json) + message(STATUS "Using git submodule provided nlohmann-json") + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/nlohmann-json/include) +else() + message(STATUS "Using builtin provided nlohmann-json") + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/nlohmann-json) +endif() + # Add MCP library add_subdirectory(src) diff --git a/common/httplib.h b/common/cpp-httplib/httplib.h similarity index 100% rename from common/httplib.h rename to common/cpp-httplib/httplib.h diff --git a/common/json.hpp b/common/nlohmann-json/nlohmann/json.hpp similarity index 100% rename from common/json.hpp rename to common/nlohmann-json/nlohmann/json.hpp diff --git a/include/mcp_message.h b/include/mcp_message.h index c98d8eb..ad99c17 100644 --- a/include/mcp_message.h +++ b/include/mcp_message.h @@ -17,7 +17,7 @@ #include // Include the JSON library for parsing and generating JSON -#include "json.hpp" +#include "nlohmann/json.hpp" namespace mcp { @@ -193,4 +193,4 @@ struct response { } // namespace mcp -#endif // MCP_MESSAGE_H \ No newline at end of file +#endif // MCP_MESSAGE_H