Pārlūkot izejas kodu

cpp-mcp: add new package (#7354)

* cpp-mcp: new package

* re-check MinGW

* retry for MinGW

* NDK guard

* `add_syslinks("pthread")` fixup BSD

* try to mirror `pkgconf`
Saikari 1 mēnesi atpakaļ
vecāks
revīzija
ac164dca8e

+ 63 - 0
packages/c/cpp-mcp/patches/2025.05.24/install.diff

@@ -0,0 +1,63 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 6e26b16..e99830d 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -40,13 +40,18 @@ if(MCP_SSL)
+ endif()
+ 
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
+-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
++include(FindPkgConfig)
++pkg_check_modules(nlohmann_json REQUIRED nlohmann_json)
++pkg_check_modules(base64_terrakuh REQUIRED base64-terrakuh)
++pkg_check_modules(cpp_httplib REQUIRED cpp-httplib)
++include_directories(${nlohmann_json_INCLUDE_DIRS})
++include_directories(${base64_terrakuh_INCLUDE_DIRS})
++include_directories(${cpp_httplib_INCLUDE_DIRS})
+ 
+ # Add MCP library
+ add_subdirectory(src)
+ 
+ # Add examples
+-add_subdirectory(examples)
+ 
+ # Add test directory
+ option(MCP_BUILD_TESTS "Build the tests" OFF)
+diff --git a/include/mcp_message.h b/include/mcp_message.h
+index d477f93..7b54a2a 100644
+--- a/include/mcp_message.h
++++ b/include/mcp_message.h
+@@ -17,7 +17,7 @@
+ #include <stdexcept>
+ 
+ // Include the JSON library for parsing and generating JSON
+-#include "json.hpp"
++#include <nlohmann/json.hpp>
+ 
+ namespace mcp {
+ 
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 2a50d21..d2c1bb4 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -1,6 +1,6 @@
+ set(TARGET mcp)
+ 
+-add_library(${TARGET} STATIC
++add_library(${TARGET}
+     ../include/mcp_client.h
+     mcp_message.cpp
+     ../include/mcp_message.h
+@@ -22,3 +22,12 @@ target_link_libraries(${TARGET} PUBLIC ${CMAKE_THREAD_LIBS_INIT})
+ if(OPENSSL_FOUND)
+     target_link_libraries(${TARGET} PUBLIC ${OPENSSL_LIBRARIES})
+ endif()
++
++if(MINGW)
++    target_link_libraries(${TARGET} PRIVATE ws2_32)
++endif()
++
++install(TARGETS ${TARGET}
++    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

+ 57 - 0
packages/c/cpp-mcp/xmake.lua

@@ -0,0 +1,57 @@
+package("cpp-mcp")
+    set_homepage("https://github.com/hkr04/cpp-mcp")
+    set_description("Lightweight C++ MCP (Model Context Protocol) SDK")
+    set_license("MIT")
+
+    add_urls("https://github.com/hkr04/cpp-mcp.git")
+    add_versions("2025.05.24", "86856a2fcc038e05675f0649e51cd4f9d3692263")
+    add_patches("2025.05.24", "patches/2025.05.24/install.diff", "81944d0bd25899834876f5f4cf99d10f8f45fb8d31dd7838d6500c08956d5941")
+
+    add_configs("openssl", {description = "Enable openssl", default = false, type = "boolean"})
+
+    add_deps("cmake")
+    add_deps("pkgconf")
+    add_deps("base64-terrakuh", "cpp-httplib", "nlohmann_json")
+
+    if is_plat("linux", "bsd") then
+        add_syslinks("pthread")
+    elseif is_plat("windows", "mingw") then
+        add_syslinks("ws2_32")
+    end
+
+    if on_check then
+        on_check("android", function (package)
+            local ndk = package:toolchain("ndk")
+            local ndk_sdkver = ndk:config("ndk_sdkver")
+            assert(ndk_sdkver and tonumber(ndk_sdkver) >= 24, "package(cpp-mcp): need ndk api level >= 24 for android")
+        end)
+    end
+
+    on_load(function (package)
+        if package:config("openssl") then
+            package:add("deps", "openssl3")
+        end
+    end)
+
+    on_install(function (package)
+        os.rm("common")
+        os.cp("include", package:installdir())
+        local configs = {}
+        if package:is_plat("windows") and package:config("shared") then
+            table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
+        end
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DMCP_SSL=" .. (package:config("openssl") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include "mcp_server.h"
+            void test() {
+                mcp::server server("localhost", 8080);
+                server.set_server_info("MCP Example Server", "0.1.0");
+            }
+        ]]}, {configs = {languages = "c++17"}}))
+    end)

+ 1 - 0
packages/p/pkgconf/xmake.lua

@@ -4,6 +4,7 @@ package("pkgconf")
     set_description("A program which helps to configure compiler and linker flags for development frameworks.")
 
     add_urls("https://distfiles.dereferenced.org/pkgconf/pkgconf-$(version).tar.xz",
+             "https://mirror.umd.edu/gentoo/distfiles/2d/pkgconf-$(version).tar.xz",
              "https://distfiles.ariadne.space/pkgconf/pkgconf-$(version).tar.xz", {alias = "tarball"})
     add_urls("https://github.com/pkgconf/pkgconf.git", {alias = "git"})
     add_versions("tarball:1.7.4", "d73f32c248a4591139a6b17777c80d4deab6b414ec2b3d21d0a24be348c476ab")