There are four ways to include LibMCP in your project example.
example
├ CMakeLists.txt
└ example.cpp
Option 1: Using FetchContent (Recommended)
This is the modern, recommended approach for CMake projects. CMake will automatically download and build LibMCP as part of your project configuration. No manual installation or cloning required.
cmake_minimum_required(VERSION 3.14)
# Create project and add executable target
project(exampleProject VERSION 0.0.1 LANGUAGES CXX)
add_executable(example example.cpp)
# Fetch and include LibMCP
include(FetchContent)
FetchContent_Declare(
MCP
GIT_REPOSITORY https://gitlab.mekra-coding.de/mcpnet/libmcp.git
GIT_TAG main
)
FetchContent_MakeAvailable(MCP)
# Link LibMCP
target_link_libraries(example PRIVATE MCP::MCP)
Option 2: Install LibMCP globally with find_package
Install LibMCP system-wide (Linux/macOS) or to a known location (Windows), then use find_package to locate it. This is preferred for system-wide library installations.
Installation:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
sudo cmake --install build # Linux/macOS; w/o sudo on Windows
CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
# Create project and add executable target
project(exampleProject VERSION 0.0.1 LANGUAGES CXX)
add_executable(example example.cpp)
# Find and link LibMCP
find_package(MCP REQUIRED)
target_link_libraries(example PRIVATE MCP::MCP)
Option 3: Install LibMCP locally with CMAKE_PREFIX_PATH
Install LibMCP to a custom location and point CMake to it. Useful when you don't have system-wide install permissions or want project-specific library versions.
Installation:
cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to/install
cmake --build build
cmake --install build
CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
# Create project and add executable target
project(exampleProject VERSION 0.0.1 LANGUAGES CXX)
add_executable(example example.cpp)
# Point CMake to the local installation
list(APPEND CMAKE_PREFIX_PATH "/path/to/install")
# Find and link LibMCP
find_package(MCP REQUIRED)
target_link_libraries(example PRIVATE MCP::MCP)
Option 4: Include LibMCP as a subdirectory
Manually clone or add LibMCP to your project structure and include it directly. Useful for active development or when you need to modify the library.
example
├ CMakeLists.txt
├ example.cpp
└ libmcp
├ CMakeLists.txt
└ ...
CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
# Create project and add executable target
project(exampleProject VERSION 0.0.1 LANGUAGES CXX)
add_executable(example example.cpp)
# Include LibMCP subdirectory
add_subdirectory(libmcp)
# Link LibMCP
target_link_libraries(example PRIVATE MCP::MCP)