cmake-server.7.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. .. cmake-manual-description: CMake Server
  2. cmake-server(7)
  3. ***************
  4. .. only:: html
  5. .. contents::
  6. Introduction
  7. ============
  8. :manual:`cmake(1)` is capable of providing semantic information about
  9. CMake code it executes to generate a buildsystem. If executed with
  10. the ``-E server`` command line options, it starts in a long running mode
  11. and allows a client to request the available information via a JSON protocol.
  12. The protocol is designed to be useful to IDEs, refactoring tools, and
  13. other tools which have a need to understand the buildsystem in entirety.
  14. A single :manual:`cmake-buildsystem(7)` may describe buildsystem contents
  15. and build properties which differ based on
  16. :manual:`generation-time context <cmake-generator-expressions(7)>`
  17. including:
  18. * The Platform (eg, Windows, APPLE, Linux).
  19. * The build configuration (eg, Debug, Release, Coverage).
  20. * The Compiler (eg, MSVC, GCC, Clang) and compiler version.
  21. * The language of the source files compiled.
  22. * Available compile features (eg CXX variadic templates).
  23. * CMake policies.
  24. The protocol aims to provide information to tooling to satisfy several
  25. needs:
  26. #. Provide a complete and easily parsed source of all information relevant
  27. to the tooling as it relates to the source code. There should be no need
  28. for tooling to parse generated buildsystems to access include directories
  29. or compile definitions for example.
  30. #. Semantic information about the CMake buildsystem itself.
  31. #. Provide a stable interface for reading the information in the CMake cache.
  32. #. Information for determining when cmake needs to be re-run as a result of
  33. file changes.
  34. Operation
  35. =========
  36. Start :manual:`cmake(1)` in the server command mode, supplying the path to
  37. the build directory to process::
  38. cmake -E server (--debug|--pipe <NAMED_PIPE>)
  39. The server will communicate using stdin/stdout (with the ``--debug`` parameter)
  40. or using a named pipe (with the ``--pipe <NAMED_PIPE>`` parameter).
  41. When connecting to the server (via named pipe or by starting it in ``--debug``
  42. mode), the server will reply with a hello message::
  43. [== "CMake Server" ==[
  44. {"supportedProtocolVersions":[{"major":1,"minor":0}],"type":"hello"}
  45. ]== "CMake Server" ==]
  46. Messages sent to and from the process are wrapped in magic strings::
  47. [== "CMake Server" ==[
  48. {
  49. ... some JSON message ...
  50. }
  51. ]== "CMake Server" ==]
  52. The server is now ready to accept further requests via the named pipe
  53. or stdin.
  54. Debugging
  55. =========
  56. CMake server mode can be asked to provide statistics on execution times, etc.
  57. or to dump a copy of the response into a file. This is done passing a "debug"
  58. JSON object as a child of the request.
  59. The debug object supports the "showStats" key, which takes a boolean and makes
  60. the server mode return a "zzzDebug" object with stats as part of its response.
  61. "dumpToFile" takes a string value and will cause the cmake server to copy
  62. the response into the given filename.
  63. This is a response from the cmake server with "showStats" set to true::
  64. [== "CMake Server" ==[
  65. {
  66. "cookie":"",
  67. "errorMessage":"Waiting for type \"handshake\".",
  68. "inReplyTo":"unknown",
  69. "type":"error",
  70. "zzzDebug": {
  71. "dumpFile":"/tmp/error.txt",
  72. "jsonSerialization":0.011016,
  73. "size":111,
  74. "totalTime":0.025995
  75. }
  76. }
  77. ]== "CMake Server" ==]
  78. The server has made a copy of this response into the file /tmp/error.txt and
  79. took 0.011 seconds to turn the JSON response into a string, and it took 0.025
  80. seconds to process the request in total. The reply has a size of 111 bytes.
  81. Protocol API
  82. ============
  83. General Message Layout
  84. ----------------------
  85. All messages need to have a "type" value, which identifies the type of
  86. message that is passed back or forth. E.g. the initial message sent by the
  87. server is of type "hello". Messages without a type will generate an response
  88. of type "error".
  89. All requests sent to the server may contain a "cookie" value. This value
  90. will he handed back unchanged in all responses triggered by the request.
  91. All responses will contain a value "inReplyTo", which may be empty in
  92. case of parse errors, but will contain the type of the request message
  93. in all other cases.
  94. Type "reply"
  95. ^^^^^^^^^^^^
  96. This type is used by the server to reply to requests.
  97. The message may -- depending on the type of the original request --
  98. contain values.
  99. Example::
  100. [== "CMake Server" ==[
  101. {"cookie":"zimtstern","inReplyTo":"handshake","type":"reply"}
  102. ]== "CMake Server" ==]
  103. Type "error"
  104. ^^^^^^^^^^^^
  105. This type is used to return an error condition to the client. It will
  106. contain an "errorMessage".
  107. Example::
  108. [== "CMake Server" ==[
  109. {"cookie":"","errorMessage":"Protocol version not supported.","inReplyTo":"handshake","type":"error"}
  110. ]== "CMake Server" ==]
  111. Type "progress"
  112. ^^^^^^^^^^^^^^^
  113. When the server is busy for a long time, it is polite to send back replies of
  114. type "progress" to the client. These will contain a "progressMessage" with a
  115. string describing the action currently taking place as well as
  116. "progressMinimum", "progressMaximum" and "progressCurrent" with integer values
  117. describing the range of progess.
  118. Messages of type "progress" will be followed by more "progress" messages or with
  119. a message of type "reply" or "error" that complete the request.
  120. "progress" messages may not be emitted after the "reply" or "error" message for
  121. the request that triggered the responses was delivered.
  122. Type "message"
  123. ^^^^^^^^^^^^^^
  124. A message is triggered when the server processes a request and produces some
  125. form of output that should be displayed to the user. A Message has a "message"
  126. with the actual text to display as well as a "title" with a suggested dialog
  127. box title.
  128. Example::
  129. [== "CMake Server" ==[
  130. {"cookie":"","message":"Something happened.","title":"Title Text","inReplyTo":"handshake","type":"message"}
  131. ]== "CMake Server" ==]
  132. Type "signal"
  133. ^^^^^^^^^^^^^
  134. The server can send signals when it detects changes in the system state. Signals
  135. are of type "signal", have an empty "cookie" and "inReplyTo" field and always
  136. have a "name" set to show which signal was sent.
  137. Specific Signals
  138. ----------------
  139. The cmake server may sent signals with the following names:
  140. "dirty" Signal
  141. ^^^^^^^^^^^^^^
  142. The "dirty" signal is sent whenever the server determines that the configuration
  143. of the project is no longer up-to-date. This happens when any of the files that have
  144. an influence on the build system is changed.
  145. The "dirty" signal may look like this::
  146. [== "CMake Server" ==[
  147. {
  148. "cookie":"",
  149. "inReplyTo":"",
  150. "name":"dirty",
  151. "type":"signal"}
  152. ]== "CMake Server" ==]
  153. "fileChange" Signal
  154. ^^^^^^^^^^^^^^^^^^^
  155. The "fileChange" signal is sent whenever a watched file is changed. It contains
  156. the "path" that has changed and a list of "properties" with the kind of change
  157. that was detected. Possible changes are "change" and "rename".
  158. The "fileChange" signal looks like this::
  159. [== "CMake Server" ==[
  160. {
  161. "cookie":"",
  162. "inReplyTo":"",
  163. "name":"fileChange",
  164. "path":"/absolute/CMakeLists.txt",
  165. "properties":["change"],
  166. "type":"signal"}
  167. ]== "CMake Server" ==]
  168. Specific Message Types
  169. ----------------------
  170. Type "hello"
  171. ^^^^^^^^^^^^
  172. The initial message send by the cmake server on startup is of type "hello".
  173. This is the only message ever sent by the server that is not of type "reply",
  174. "progress" or "error".
  175. It will contain "supportedProtocolVersions" with an array of server protocol
  176. versions supported by the cmake server. These are JSON objects with "major" and
  177. "minor" keys containing non-negative integer values. Some versions may be marked
  178. as experimental. These will contain the "isExperimental" key set to true. Enabling
  179. these requires a special command line argument when starting the cmake server mode.
  180. Example::
  181. [== "CMake Server" ==[
  182. {"supportedProtocolVersions":[{"major":0,"minor":1}],"type":"hello"}
  183. ]== "CMake Server" ==]
  184. Type "handshake"
  185. ^^^^^^^^^^^^^^^^
  186. The first request that the client may send to the server is of type "handshake".
  187. This request needs to pass one of the "supportedProtocolVersions" of the "hello"
  188. type response received earlier back to the server in the "protocolVersion" field.
  189. Each protocol version may request additional attributes to be present.
  190. Protocol version 1.0 requires the following attributes to be set:
  191. * "sourceDirectory" with a path to the sources
  192. * "buildDirectory" with a path to the build directory
  193. * "generator" with the generator name
  194. * "extraGenerator" (optional!) with the extra generator to be used
  195. * "platform" with the generator platform (if supported by the generator)
  196. * "toolset" with the generator toolset (if supported by the generator)
  197. Example::
  198. [== "CMake Server" ==[
  199. {"cookie":"zimtstern","type":"handshake","protocolVersion":{"major":0},
  200. "sourceDirectory":"/home/code/cmake", "buildDirectory":"/tmp/testbuild",
  201. "generator":"Ninja"}
  202. ]== "CMake Server" ==]
  203. which will result in a response type "reply"::
  204. [== "CMake Server" ==[
  205. {"cookie":"zimtstern","inReplyTo":"handshake","type":"reply"}
  206. ]== "CMake Server" ==]
  207. indicating that the server is ready for action.
  208. Type "globalSettings"
  209. ^^^^^^^^^^^^^^^^^^^^^
  210. This request can be sent after the initial handshake. It will return a
  211. JSON structure with information on cmake state.
  212. Example::
  213. [== "CMake Server" ==[
  214. {"type":"globalSettings"}
  215. ]== "CMake Server" ==]
  216. which will result in a response type "reply"::
  217. [== "CMake Server" ==[
  218. {
  219. "buildDirectory": "/tmp/test-build",
  220. "capabilities": {
  221. "generators": [
  222. {
  223. "extraGenerators": [],
  224. "name": "Watcom WMake",
  225. "platformSupport": false,
  226. "toolsetSupport": false
  227. },
  228. <...>
  229. ],
  230. "serverMode": false,
  231. "version": {
  232. "isDirty": false,
  233. "major": 3,
  234. "minor": 6,
  235. "patch": 20160830,
  236. "string": "3.6.20160830-gd6abad",
  237. "suffix": "gd6abad"
  238. }
  239. },
  240. "checkSystemVars": false,
  241. "cookie": "",
  242. "extraGenerator": "",
  243. "generator": "Ninja",
  244. "debugOutput": false,
  245. "inReplyTo": "globalSettings",
  246. "sourceDirectory": "/home/code/cmake",
  247. "trace": false,
  248. "traceExpand": false,
  249. "type": "reply",
  250. "warnUninitialized": false,
  251. "warnUnused": false,
  252. "warnUnusedCli": true
  253. }
  254. ]== "CMake Server" ==]
  255. Type "setGlobalSettings"
  256. ^^^^^^^^^^^^^^^^^^^^^^^^
  257. This request can be sent to change the global settings attributes. Unknown
  258. attributes are going to be ignored. Read-only attributes reported by
  259. "globalSettings" are all capabilities, buildDirectory, generator,
  260. extraGenerator and sourceDirectory. Any attempt to set these will be ignored,
  261. too.
  262. All other settings will be changed.
  263. The server will respond with an empty reply message or an error.
  264. Example::
  265. [== "CMake Server" ==[
  266. {"type":"setGlobalSettings","debugOutput":true}
  267. ]== "CMake Server" ==]
  268. CMake will reply to this with::
  269. [== "CMake Server" ==[
  270. {"inReplyTo":"setGlobalSettings","type":"reply"}
  271. ]== "CMake Server" ==]
  272. Type "configure"
  273. ^^^^^^^^^^^^^^^^
  274. This request will configure a project for build.
  275. To configure a build directory already containing cmake files, it is enough to
  276. set "buildDirectory" via "setGlobalSettings". To create a fresh build directory
  277. you also need to set "currentGenerator" and "sourceDirectory" via "setGlobalSettings"
  278. in addition to "buildDirectory".
  279. You may a list of strings to "configure" via the "cacheArguments" key. These
  280. strings will be interpreted similar to command line arguments related to
  281. cache handling that are passed to the cmake command line client.
  282. Example::
  283. [== "CMake Server" ==[
  284. {"type":"configure", "cacheArguments":["-Dsomething=else"]}
  285. ]== "CMake Server" ==]
  286. CMake will reply like this (after reporting progress for some time)::
  287. [== "CMake Server" ==[
  288. {"cookie":"","inReplyTo":"configure","type":"reply"}
  289. ]== "CMake Server" ==]
  290. Type "compute"
  291. ^^^^^^^^^^^^^^
  292. This request will generate build system files in the build directory and
  293. is only available after a project was successfully "configure"d.
  294. Example::
  295. [== "CMake Server" ==[
  296. {"type":"compute"}
  297. ]== "CMake Server" ==]
  298. CMake will reply (after reporting progress information)::
  299. [== "CMake Server" ==[
  300. {"cookie":"","inReplyTo":"compute","type":"reply"}
  301. ]== "CMake Server" ==]
  302. Type "codemodel"
  303. ^^^^^^^^^^^^^^^^
  304. The "codemodel" request can be used after a project was "compute"d successfully.
  305. It will list the complete project structure as it is known to cmake.
  306. The reply will contain a key "configurations", which will contain a list of
  307. configuration objects. Configuration objects are used to destinquish between
  308. different configurations the build directory might have enabled. While most
  309. generators only support one configuration, others might support several.
  310. Each configuration object can have the following keys:
  311. "name"
  312. contains the name of the configuration. The name may be empty.
  313. "projects"
  314. contains a list of project objects, one for each build project.
  315. Project objects define one (sub-)project defined in the cmake build system.
  316. Each project object can have the following keys:
  317. "name"
  318. contains the (sub-)projects name.
  319. "sourceDirectory"
  320. contains the current source directory
  321. "buildDirectory"
  322. contains the current build directory.
  323. "targets"
  324. contains a list of build system target objects.
  325. Target objects define individual build targets for a certain configuration.
  326. Each target object can have the following keys:
  327. "name"
  328. contains the name of the target.
  329. "type"
  330. defines the type of build of the target. Possible values are
  331. "STATIC_LIBRARY", "MODULE_LIBRARY", "SHARED_LIBRARY", "OBJECT_LIBRARY",
  332. "EXECUTABLE", "UTILITY" and "INTERFACE_LIBRARY".
  333. "fullName"
  334. contains the full name of the build result (incl. extensions, etc.).
  335. "sourceDirectory"
  336. contains the current source directory.
  337. "buildDirectory"
  338. contains the current build directory.
  339. "artifacts"
  340. with a list of build artifacts. The list is sorted with the most
  341. important artifacts first (e.g. a .DLL file is listed before a
  342. .PDB file on windows).
  343. "linkerLanguage"
  344. contains the language of the linker used to produce the artifact.
  345. "linkLibraries"
  346. with a list of libraries to link to. This value is encoded in the
  347. system's native shell format.
  348. "linkFlags"
  349. with a list of flags to pass to the linker. This value is encoded in
  350. the system's native shell format.
  351. "linkLanguageFlags"
  352. with the flags for a compiler using the linkerLanguage. This value is
  353. encoded in the system's native shell format.
  354. "frameworkPath"
  355. with the framework path (on Apple computers). This value is encoded
  356. in the system's native shell format.
  357. "linkPath"
  358. with the link path. This value is encoded in the system's native shell
  359. format.
  360. "sysroot"
  361. with the sysroot path.
  362. "fileGroups"
  363. contains the source files making up the target.
  364. FileGroups are used to group sources using similar settings together.
  365. Each fileGroup object may contain the following keys:
  366. "language"
  367. contains the programming language used by all files in the group.
  368. "compileFlags"
  369. with a string containing all the flags passed to the compiler
  370. when building any of the files in this group. This value is encoded in
  371. the system's native shell format.
  372. "includePath"
  373. with a list of include paths. Each include path is an object
  374. containing a "path" with the actual include path and "isSystem" with a bool
  375. value informing whether this is a normal include or a system include. This
  376. value is encoded in the system's native shell format.
  377. "defines"
  378. with a list of defines in the form "SOMEVALUE" or "SOMEVALUE=42". This
  379. value is encoded in the system's native shell format.
  380. "sources"
  381. with a list of source files.
  382. All file paths in the fileGroup are either absolute or relative to the
  383. sourceDirectory of the target.
  384. Example::
  385. [== "CMake Server" ==[
  386. {"type":"codemodel"}
  387. ]== "CMake Server" ==]
  388. CMake will reply::
  389. [== "CMake Server" ==[
  390. {
  391. "configurations": [
  392. {
  393. "name": "",
  394. "projects": [
  395. {
  396. "buildDirectory": "/tmp/build/Source/CursesDialog/form",
  397. "name": "CMAKE_FORM",
  398. "sourceDirectory": "/home/code/src/cmake/Source/CursesDialog/form",
  399. "targets": [
  400. {
  401. "artifacts": [ "/tmp/build/Source/CursesDialog/form/libcmForm.a" ],
  402. "buildDirectory": "/tmp/build/Source/CursesDialog/form",
  403. "fileGroups": [
  404. {
  405. "compileFlags": " -std=gnu11",
  406. "defines": [ "CURL_STATICLIB", "LIBARCHIVE_STATIC" ],
  407. "includePath": [ { "path": "/tmp/build/Utilities" }, <...> ],
  408. "isGenerated": false,
  409. "language": "C",
  410. "sources": [ "fld_arg.c", <...> ]
  411. }
  412. ],
  413. "fullName": "libcmForm.a",
  414. "linkerLanguage": "C",
  415. "name": "cmForm",
  416. "sourceDirectory": "/home/code/src/cmake/Source/CursesDialog/form",
  417. "type": "STATIC_LIBRARY"
  418. }
  419. ]
  420. },
  421. <...>
  422. ]
  423. }
  424. ],
  425. "cookie": "",
  426. "inReplyTo": "codemodel",
  427. "type": "reply"
  428. }
  429. ]== "CMake Server" ==]
  430. Type "cmakeInputs"
  431. ^^^^^^^^^^^^^^^^^^
  432. The "cmakeInputs" requests will report files used by CMake as part
  433. of the build system itself.
  434. This request is only available after a project was successfully
  435. "configure"d.
  436. Example::
  437. [== "CMake Server" ==[
  438. {"type":"cmakeInputs"}
  439. ]== "CMake Server" ==]
  440. CMake will reply with the following information::
  441. [== "CMake Server" ==[
  442. {"buildFiles":
  443. [
  444. {"isCMake":true,"isTemporary":false,"sources":["/usr/lib/cmake/...", ... ]},
  445. {"isCMake":false,"isTemporary":false,"sources":["CMakeLists.txt", ...]},
  446. {"isCMake":false,"isTemporary":true,"sources":["/tmp/build/CMakeFiles/...", ...]}
  447. ],
  448. "cmakeRootDirectory":"/usr/lib/cmake",
  449. "sourceDirectory":"/home/code/src/cmake",
  450. "cookie":"",
  451. "inReplyTo":"cmakeInputs",
  452. "type":"reply"
  453. }
  454. ]== "CMake Server" ==]
  455. All file names are either relative to the top level source directory or
  456. absolute.
  457. The list of files which "isCMake" set to true are part of the cmake installation.
  458. The list of files witch "isTemporary" set to true are part of the build directory
  459. and will not survive the build directory getting cleaned out.
  460. Type "cache"
  461. ^^^^^^^^^^^^
  462. The "cache" request can be used once a project is configured and will
  463. list the cached configuration values.
  464. Example::
  465. [== "CMake Server" ==[
  466. {"type":"cache"}
  467. ]== "CMake Server" ==]
  468. CMake will respond with the following output::
  469. [== "CMake Server" ==[
  470. {
  471. "cookie":"","inReplyTo":"cache","type":"reply",
  472. "cache":
  473. [
  474. {
  475. "key":"SOMEVALUE",
  476. "properties":
  477. {
  478. "ADVANCED":"1",
  479. "HELPSTRING":"This is not helpful"
  480. }
  481. "type":"STRING",
  482. "value":"TEST"}
  483. ]
  484. }
  485. ]== "CMake Server" ==]
  486. The output can be limited to a list of keys by passing an array of key names
  487. to the "keys" optional field of the "cache" request.
  488. Type "fileSystemWatchers"
  489. ^^^^^^^^^^^^^^^^^^^^^^^^^
  490. The server can watch the filesystem for changes. The "fileSystemWatchers"
  491. command will report on the files and directories watched.
  492. Example::
  493. [== "CMake Server" ==[
  494. {"type":"fileSystemWatchers"}
  495. ]== "CMake Server" ==]
  496. CMake will respond with the following output::
  497. [== "CMake Server" ==[
  498. {
  499. "cookie":"","inReplyTo":"fileSystemWatchers","type":"reply",
  500. "watchedFiles": [ "/absolute/path" ],
  501. "watchedDirectories": [ "/absolute" ]
  502. }
  503. ]== "CMake Server" ==]