Skip to content
Advertisement

Send request to CMake server from the Linux command line

I would like to play around with the CMake server mode from the Linux command line. The documentation tells me to start CMake like the following:

cmake -E server (--debug|--pipe <NAMED_PIPE>)

But for me it works only this way:

cmake -E server --experimental --debug

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

I tried to send a request to the server, but I get only the hello response:

cat request.txt | cmake -E server --experimental --debug
[== "CMake Server" ==[
{"supportedProtocolVersions":[{"isExperimental":true,"major":1,"minor":0}],"type":"hello"}
]== "CMake Server" ==]

How can I send requests to the CMake server?

Advertisement

Answer

The CMake server will be expecting messages of either --debug or --pipe mode in the following format:

[== "CMake Server" ==[

…your message…

 ]== "CMake Server" ==]

The CMake server help page has more examples, but here is something that will help you get started.

For the following examples, I used CMake 3.10, if you are using an older version you may have to modify the "protocolVersion":{"major":1} to {"major":0}.

You’ll also need to have a CMake project and know the source directory where the CMakeLists.txt file is and a build folder where the out of tree files will be placed by cmake.

If you want to try the --debug --experimental flags, the server will be expecting to get input from standard input. So right after you run cmake -E server --debug --experimental, input the following:

[== "CMake Server" ==[

{"cookie":"yummy","type":"handshake","protocolVersion":{"major":1},
    "sourceDirectory":"/path/to/CMakeList.txt","buildDirectory":"/path/to/build/folder",

"generator":"Unix Makefiles"}

]== "CMake Server" ==]

It should respond with a bunch of information and the build folder should containt some files now.

If you want to use a named pipe instead, you’ll have to use something like netcat. Using your command as an example, after running the cmake -E server --pipe=pipe --experimental in the background, you can use the following command:

nc -U pipe

At this point, nc will be expecting input in the standard input as well, so you will be able to input the same json messages as before and get the same response.

Advertisement