cmake-server.7.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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 Message Types
  138. ----------------------
  139. Type "hello"
  140. ^^^^^^^^^^^^
  141. The initial message send by the cmake server on startup is of type "hello".
  142. This is the only message ever sent by the server that is not of type "reply",
  143. "progress" or "error".
  144. It will contain "supportedProtocolVersions" with an array of server protocol
  145. versions supported by the cmake server. These are JSON objects with "major" and
  146. "minor" keys containing non-negative integer values.
  147. Example::
  148. [== CMake Server ==[
  149. {"supportedProtocolVersions":[{"major":0,"minor":1}],"type":"hello"}
  150. ]== CMake Server ==]
  151. Type "handshake"
  152. ^^^^^^^^^^^^^^^^
  153. The first request that the client may send to the server is of type "handshake".
  154. This request needs to pass one of the "supportedProtocolVersions" of the "hello"
  155. type response received earlier back to the server in the "protocolVersion" field.
  156. Each protocol version may request additional attributes to be present.
  157. Protocol version 1.0 requires the following attributes to be set:
  158. * "sourceDirectory" with a path to the sources
  159. * "buildDirectory" with a path to the build directory
  160. * "generator" with the generator name
  161. * "extraGenerator" (optional!) with the extra generator to be used.
  162. Example::
  163. [== CMake Server ==[
  164. {"cookie":"zimtstern","type":"handshake","protocolVersion":{"major":0},
  165. "sourceDirectory":"/home/code/cmake", "buildDirectory":"/tmp/testbuild",
  166. "generator":"Ninja"}
  167. ]== CMake Server ==]
  168. which will result in a response type "reply"::
  169. [== CMake Server ==[
  170. {"cookie":"zimtstern","inReplyTo":"handshake","type":"reply"}
  171. ]== CMake Server ==]
  172. indicating that the server is ready for action.
  173. Type "globalSettings"
  174. ^^^^^^^^^^^^^^^^^^^^^
  175. This request can be sent after the initial handshake. It will return a
  176. JSON structure with information on cmake state.
  177. Example::
  178. [== CMake Server ==[
  179. {"type":"globalSettings"}
  180. ]== CMake Server ==]
  181. which will result in a response type "reply"::
  182. [== CMake Server ==[
  183. {
  184. "buildDirectory": "/tmp/test-build",
  185. "capabilities": {
  186. "generators": [
  187. {
  188. "extraGenerators": [],
  189. "name": "Watcom WMake",
  190. "platformSupport": false,
  191. "toolsetSupport": false
  192. },
  193. <...>
  194. ],
  195. "serverMode": false,
  196. "version": {
  197. "isDirty": false,
  198. "major": 3,
  199. "minor": 6,
  200. "patch": 20160830,
  201. "string": "3.6.20160830-gd6abad",
  202. "suffix": "gd6abad"
  203. }
  204. },
  205. "checkSystemVars": false,
  206. "cookie": "",
  207. "extraGenerator": "",
  208. "generator": "Ninja",
  209. "debugOutput": false,
  210. "inReplyTo": "globalSettings",
  211. "sourceDirectory": "/home/code/cmake",
  212. "trace": false,
  213. "traceExpand": false,
  214. "type": "reply",
  215. "warnUninitialized": false,
  216. "warnUnused": false,
  217. "warnUnusedCli": true
  218. }
  219. ]== CMake Server ==]
  220. Type "setGlobalSettings"
  221. ^^^^^^^^^^^^^^^^^^^^^^^^
  222. This request can be sent to change the global settings attributes. Unknown
  223. attributes are going to be ignored. Read-only attributes reported by
  224. "globalSettings" are all capabilities, buildDirectory, generator,
  225. extraGenerator and sourceDirectory. Any attempt to set these will be ignored,
  226. too.
  227. All other settings will be changed.
  228. The server will respond with an empty reply message or an error.
  229. Example::
  230. [== CMake Server ==[
  231. {"type":"setGlobalSettings","debugOutput":true}
  232. ]== CMake Server ==]
  233. CMake will reply to this with::
  234. [== CMake Server ==[
  235. {"inReplyTo":"setGlobalSettings","type":"reply"}
  236. ]== CMake Server ==]
  237. Type "configure"
  238. ^^^^^^^^^^^^^^^^
  239. This request will configure a project for build.
  240. To configure a build directory already containing cmake files, it is enough to
  241. set "buildDirectory" via "setGlobalSettings". To create a fresh build directory
  242. you also need to set "currentGenerator" and "sourceDirectory" via "setGlobalSettings"
  243. in addition to "buildDirectory".
  244. You may a list of strings to "configure" via the "cacheArguments" key. These
  245. strings will be interpreted similar to command line arguments related to
  246. cache handling that are passed to the cmake command line client.
  247. Example::
  248. [== CMake Server ==[
  249. {"type":"configure", "cacheArguments":["-Dsomething=else"]}
  250. ]== CMake Server ==]
  251. CMake will reply like this (after reporting progress for some time)::
  252. [== CMake Server ==[
  253. {"cookie":"","inReplyTo":"configure","type":"reply"}
  254. ]== CMake Server ==]
  255. Type "compute"
  256. ^^^^^^^^^^^^^^
  257. This requist will generate build system files in the build directory and
  258. is only available after a project was successfully "configure"d.
  259. Example::
  260. [== CMake Server ==[
  261. {"type":"compute"}
  262. ]== CMake Server ==]
  263. CMake will reply (after reporting progress information)::
  264. [== CMake Server ==[
  265. {"cookie":"","inReplyTo":"compute","type":"reply"}
  266. ]== CMake Server ==]
  267. Type "codemodel"
  268. ^^^^^^^^^^^^^^^^
  269. The "codemodel" request can be used after a project was "compute"d successfully.
  270. It will list the complete project structure as it is known to cmake.
  271. The reply will contain a key "projects", which will contain a list of
  272. project objects, one for each (sub-)project defined in the cmake build system.
  273. Each project object can have the following keys:
  274. "name"
  275. contains the (sub-)projects name.
  276. "sourceDirectory"
  277. contains the current source directory
  278. "buildDirectory"
  279. contains the current build directory.
  280. "configurations"
  281. contains a list of configuration objects.
  282. Configuration objects are used to destinquish between different
  283. configurations the build directory might have enabled. While most generators
  284. only support one configuration, others support several.
  285. Each configuration object can have the following keys:
  286. "name"
  287. contains the name of the configuration. The name may be empty.
  288. "targets"
  289. contains a list of target objects, one for each build target.
  290. Target objects define individual build targets for a certain configuration.
  291. Each target object can have the following keys:
  292. "name"
  293. contains the name of the target.
  294. "type"
  295. defines the type of build of the target. Possible values are
  296. "STATIC_LIBRARY", "MODULE_LIBRARY", "SHARED_LIBRARY", "OBJECT_LIBRARY",
  297. "EXECUTABLE", "UTILITY" and "INTERFACE_LIBRARY".
  298. "fullName"
  299. contains the full name of the build result (incl. extensions, etc.).
  300. "sourceDirectory"
  301. contains the current source directory.
  302. "buildDirectory"
  303. contains the current build directory.
  304. "artifacts"
  305. with a list of build artifacts. The list is sorted with the most
  306. important artifacts first (e.g. a .DLL file is listed before a
  307. .PDB file on windows).
  308. "linkerLanguage"
  309. contains the language of the linker used to produce the artifact.
  310. "linkLibraries"
  311. with a list of libraries to link to. This value is encoded in the
  312. system's native shell format.
  313. "linkFlags"
  314. with a list of flags to pass to the linker. This value is encoded in
  315. the system's native shell format.
  316. "linkLanguageFlags"
  317. with the flags for a compiler using the linkerLanguage. This value is
  318. encoded in the system's native shell format.
  319. "frameworkPath"
  320. with the framework path (on Apple computers). This value is encoded
  321. in the system's native shell format.
  322. "linkPath"
  323. with the link path. This value is encoded in the system's native shell
  324. format.
  325. "sysroot"
  326. with the sysroot path.
  327. "fileGroups"
  328. contains the source files making up the target.
  329. FileGroups are used to group sources using similar settings together.
  330. Each fileGroup object may contain the following keys:
  331. "language"
  332. contains the programming language used by all files in the group.
  333. "compileFlags"
  334. with a string containing all the flags passed to the compiler
  335. when building any of the files in this group. This value is encoded in
  336. the system's native shell format.
  337. "includePath"
  338. with a list of include paths. Each include path is an object
  339. containing a "path" with the actual include path and "isSystem" with a bool
  340. value informing whether this is a normal include or a system include. This
  341. value is encoded in the system's native shell format.
  342. "defines"
  343. with a list of defines in the form "SOMEVALUE" or "SOMEVALUE=42". This
  344. value is encoded in the system's native shell format.
  345. "sources"
  346. with a list of source files.
  347. All file paths in the fileGroup are either absolute or relative to the
  348. sourceDirectory of the target.
  349. Example::
  350. [== CMake Server ==[
  351. {"type":"project"}
  352. ]== CMake Server ==]
  353. CMake will reply::
  354. [== CMake Server ==[
  355. {
  356. "cookie":"",
  357. "type":"reply",
  358. "inReplyTo":"project",
  359. "projects":
  360. [
  361. {
  362. "name":"CMAKE_FORM",
  363. "sourceDirectory":"/home/code/src/cmake/Source/CursesDialog/form"
  364. "buildDirectory":"/tmp/cmake-build-test/Source/CursesDialog/form",
  365. "configurations":
  366. [
  367. {
  368. "name":"",
  369. "targets":
  370. [
  371. {
  372. "artifactDirectory":"/tmp/cmake/Source/CursesDialog/form",
  373. "fileGroups":
  374. [
  375. {
  376. "compileFlags":" -std=gnu11",
  377. "defines":
  378. [
  379. "SOMETHING=1",
  380. "LIBARCHIVE_STATIC"
  381. ],
  382. "includePath":
  383. [
  384. { "path":"/tmp/cmake-build-test/Utilities" },
  385. { "isSystem": true, "path":"/usr/include/something" },
  386. ...
  387. ]
  388. "language":"C",
  389. "sources":
  390. [
  391. "fld_arg.c",
  392. ...
  393. "fty_regex.c"
  394. ]
  395. }
  396. ],
  397. "fullName":"libcmForm.a",
  398. "linkerLanguage":"C",
  399. "name":"cmForm",
  400. "type":"STATIC_LIBRARY"
  401. }
  402. ]
  403. }
  404. ],
  405. },
  406. ...
  407. ]
  408. }
  409. ]== CMake Server ==]
  410. The output can be tailored to the specific needs via parameter passed when
  411. requesting "project" information.
  412. You can have a "depth" key, which accepts "project", "configuration" and
  413. "target" as string values. These cause the output to be trimmed at the
  414. appropriate depth of the output tree.
  415. You can also set "configurations" to an array of strings with configuration
  416. names to list. This will cause any configuration that is not listed to be
  417. trimmed from the output.
  418. Generated files can be included in the listing by setting "includeGeneratedFiles"
  419. to "true". This setting defaults to "false", so generated files are not
  420. listed by default.
  421. Finally you can limit the target types that are going to be listed. This is
  422. done by providing a list of target types as an array of strings to the
  423. "targetTypes" key.
  424. Type "cmakeInputs"
  425. ^^^^^^^^^^^^^^^^^^
  426. The "cmakeInputs" requests will report files used by CMake as part
  427. of the build system itself.
  428. This request is only available after a project was successfully
  429. "configure"d.
  430. Example::
  431. [== CMake Server ==[
  432. {"type":"cmakeInputs"}
  433. ]== CMake Server ==]
  434. CMake will reply with the following information::
  435. [== CMake Server ==[
  436. {"buildFiles":
  437. [
  438. {"isCMake":true,"isTemporary":false,"sources":["/usr/lib/cmake/...", ... ]},
  439. {"isCMake":false,"isTemporary":false,"sources":["CMakeLists.txt", ...]},
  440. {"isCMake":false,"isTemporary":true,"sources":["/tmp/build/CMakeFiles/...", ...]}
  441. ],
  442. "cmakeRootDirectory":"/usr/lib/cmake",
  443. "sourceDirectory":"/home/code/src/cmake",
  444. "cookie":"",
  445. "inReplyTo":"cmakeInputs",
  446. "type":"reply"
  447. }
  448. ]== CMake Server ==]
  449. All file names are either relative to the top level source directory or
  450. absolute.
  451. The list of files which "isCMake" set to true are part of the cmake installation.
  452. The list of files witch "isTemporary" set to true are part of the build directory
  453. and will not survive the build directory getting cleaned out.