I’ve been use cmake+vscode workflow happily for years. Both cpptool and cmake-tool work well and they interlope perfectly. Recently, I started heavy development of embedded device. It seems cmake-tool is buggy here, but I cannot abandon cmake. So I started reading the document of cmake server to extract the configuration of the project especially includePath.

You can start server by following command

cmake -E server --debug --experimental

When you start the server, it will print its protocol version to standard output. notice an empty line before the response text.


[== "CMake Server" ==[
{"supportedProtocolVersions":[{"isExperimental":true,"major":1,"minor":2}],"type":"hello"}
]== "CMake Server" ==]

Now do a handshake to continue, send the following request to the server via stdin. Note that the protocolVersion should match the previous response.

[== "CMake Server" ==[
{"cookie":"zimtstern","type":"handshake","protocolVersion":{"major":1, "minor": 2},
"sourceDirectory":"C:/Users/xxxx/Desktop/Test", "buildDirectory":"C:/Users/xxxx/Desktop/Test/build",
"generator":"Ninja"}
]== "CMake Server" ==]

We can fetch cmake cache with the following command “cache”. This is the general form of a command with no argument.

[== "CMake Server" ==[
{"type":"cache"}
]== "CMake Server" ==]

for extracting predefined macro and include path. Sequentially send configure, compute, codemodel. You can find macro and include path in the response of codemodel. Note that cmake server will send progress asynchronously during configure and compute stage.

Here I provide a python script for dumping codemodel. Don’t blame me for the code structure, I wrote this in 10 minutes only for retrieving data…