cmake-file-api.7.rst 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. .. cmake-manual-description: CMake File-Based API
  2. cmake-file-api(7)
  3. *****************
  4. .. only:: html
  5. .. contents::
  6. Introduction
  7. ============
  8. CMake provides a file-based API that clients may use to get semantic
  9. information about the buildsystems CMake generates. Clients may use
  10. the API by writing query files to a specific location in a build tree
  11. to request zero or more `Object Kinds`_. When CMake generates the
  12. buildsystem in that build tree it will read the query files and write
  13. reply files for the client to read.
  14. The file-based API uses a ``<build>/.cmake/api/`` directory at the top
  15. of a build tree. The API is versioned to support changes to the layout
  16. of files within the API directory. API file layout versioning is
  17. orthogonal to the versioning of `Object Kinds`_ used in replies.
  18. This version of CMake supports only one API version, `API v1`_.
  19. API v1
  20. ======
  21. API v1 is housed in the ``<build>/.cmake/api/v1/`` directory.
  22. It has the following subdirectories:
  23. ``query/``
  24. Holds query files written by clients.
  25. These may be `v1 Shared Stateless Query Files`_,
  26. `v1 Client Stateless Query Files`_, or `v1 Client Stateful Query Files`_.
  27. ``reply/``
  28. Holds reply files written by CMake whenever it runs to generate a build
  29. system. These are indexed by a `v1 Reply Index File`_ file that may
  30. reference additional `v1 Reply Files`_. CMake owns all reply files.
  31. Clients must never remove them.
  32. Clients may look for and read a reply index file at any time.
  33. Clients may optionally create the ``reply/`` directory at any time
  34. and monitor it for the appearance of a new reply index file.
  35. v1 Shared Stateless Query Files
  36. -------------------------------
  37. Shared stateless query files allow clients to share requests for
  38. major versions of the `Object Kinds`_ and get all requested versions
  39. recognized by the CMake that runs.
  40. Clients may create shared requests by creating empty files in the
  41. ``v1/query/`` directory. The form is::
  42. <build>/.cmake/api/v1/query/<kind>-v<major>
  43. where ``<kind>`` is one of the `Object Kinds`_, ``-v`` is literal,
  44. and ``<major>`` is the major version number.
  45. Files of this form are stateless shared queries not owned by any specific
  46. client. Once created they should not be removed without external client
  47. coordination or human intervention.
  48. v1 Client Stateless Query Files
  49. -------------------------------
  50. Client stateless query files allow clients to create owned requests for
  51. major versions of the `Object Kinds`_ and get all requested versions
  52. recognized by the CMake that runs.
  53. Clients may create owned requests by creating empty files in
  54. client-specific query subdirectories. The form is::
  55. <build>/.cmake/api/v1/query/client-<client>/<kind>-v<major>
  56. where ``client-`` is literal, ``<client>`` is a string uniquely
  57. identifying the client, ``<kind>`` is one of the `Object Kinds`_,
  58. ``-v`` is literal, and ``<major>`` is the major version number.
  59. Each client must choose a unique ``<client>`` identifier via its
  60. own means.
  61. Files of this form are stateless queries owned by the client ``<client>``.
  62. The owning client may remove them at any time.
  63. v1 Client Stateful Query Files
  64. ------------------------------
  65. Stateful query files allow clients to request a list of versions of
  66. each of the `Object Kinds`_ and get only the most recent version
  67. recognized by the CMake that runs.
  68. Clients may create owned stateful queries by creating ``query.json``
  69. files in client-specific query subdirectories. The form is::
  70. <build>/.cmake/api/v1/query/client-<client>/query.json
  71. where ``client-`` is literal, ``<client>`` is a string uniquely
  72. identifying the client, and ``query.json`` is literal. Each client
  73. must choose a unique ``<client>`` identifier via its own means.
  74. ``query.json`` files are stateful queries owned by the client ``<client>``.
  75. The owning client may update or remove them at any time. When a
  76. given client installation is updated it may then update the stateful
  77. query it writes to build trees to request newer object versions.
  78. This can be used to avoid asking CMake to generate multiple object
  79. versions unnecessarily.
  80. A ``query.json`` file must contain a JSON object:
  81. .. code-block:: json
  82. {
  83. "requests": [
  84. { "kind": "<kind>" , "version": 1 },
  85. { "kind": "<kind>" , "version": { "major": 1, "minor": 2 } },
  86. { "kind": "<kind>" , "version": [2, 1] },
  87. { "kind": "<kind>" , "version": [2, { "major": 1, "minor": 2 }] },
  88. { "kind": "<kind>" , "version": 1, "client": {} },
  89. { "kind": "..." }
  90. ],
  91. "client": {}
  92. }
  93. The members are:
  94. ``requests``
  95. A JSON array containing zero or more requests. Each request is
  96. a JSON object with members:
  97. ``kind``
  98. Specifies one of the `Object Kinds`_ to be included in the reply.
  99. ``version``
  100. Indicates the version(s) of the object kind that the client
  101. understands. Versions have major and minor components following
  102. semantic version conventions. The value must be
  103. * a JSON integer specifying a (non-negative) major version number, or
  104. * a JSON object containing ``major`` and (optionally) ``minor``
  105. members specifying non-negative integer version components, or
  106. * a JSON array whose elements are each one of the above.
  107. ``client``
  108. Optional member reserved for use by the client. This value is
  109. preserved in the reply written for the client in the
  110. `v1 Reply Index File`_ but is otherwise ignored. Clients may use
  111. this to pass custom information with a request through to its reply.
  112. For each requested object kind CMake will choose the *first* version
  113. that it recognizes for that kind among those listed in the request.
  114. The response will use the selected *major* version with the highest
  115. *minor* version known to the running CMake for that major version.
  116. Therefore clients should list all supported major versions in
  117. preferred order along with the minimal minor version required
  118. for each major version.
  119. ``client``
  120. Optional member reserved for use by the client. This value is
  121. preserved in the reply written for the client in the
  122. `v1 Reply Index File`_ but is otherwise ignored. Clients may use
  123. this to pass custom information with a query through to its reply.
  124. Other ``query.json`` top-level members are reserved for future use.
  125. If present they are ignored for forward compatibility.
  126. v1 Reply Index File
  127. -------------------
  128. CMake writes an ``index-*.json`` file to the ``v1/reply/`` directory
  129. whenever it runs to generate a build system. Clients must read the
  130. reply index file first and may read other `v1 Reply Files`_ only by
  131. following references. The form of the reply index file name is::
  132. <build>/.cmake/api/v1/reply/index-<unspecified>.json
  133. where ``index-`` is literal and ``<unspecified>`` is an unspecified
  134. name selected by CMake. Whenever a new index file is generated it
  135. is given a new name and any old one is deleted. During the short
  136. time between these steps there may be multiple index files present;
  137. the one with the largest name in lexicographic order is the current
  138. index file.
  139. The reply index file contains a JSON object:
  140. .. code-block:: json
  141. {
  142. "cmake": {
  143. "version": {
  144. "major": 3, "minor": 14, "patch": 0, "suffix": "",
  145. "string": "3.14.0", "isDirty": false
  146. },
  147. "paths": {
  148. "cmake": "/prefix/bin/cmake",
  149. "ctest": "/prefix/bin/ctest",
  150. "cpack": "/prefix/bin/cpack",
  151. "root": "/prefix/share/cmake-3.14"
  152. },
  153. "generator": {
  154. "multiConfig": false,
  155. "name": "Unix Makefiles"
  156. }
  157. },
  158. "objects": [
  159. { "kind": "<kind>",
  160. "version": { "major": 1, "minor": 0 },
  161. "jsonFile": "<file>" },
  162. { "...": "..." }
  163. ],
  164. "reply": {
  165. "<kind>-v<major>": { "kind": "<kind>",
  166. "version": { "major": 1, "minor": 0 },
  167. "jsonFile": "<file>" },
  168. "<unknown>": { "error": "unknown query file" },
  169. "...": {},
  170. "client-<client>": {
  171. "<kind>-v<major>": { "kind": "<kind>",
  172. "version": { "major": 1, "minor": 0 },
  173. "jsonFile": "<file>" },
  174. "<unknown>": { "error": "unknown query file" },
  175. "...": {},
  176. "query.json": {
  177. "requests": [ {}, {}, {} ],
  178. "responses": [
  179. { "kind": "<kind>",
  180. "version": { "major": 1, "minor": 0 },
  181. "jsonFile": "<file>" },
  182. { "error": "unknown query file" },
  183. { "...": {} }
  184. ],
  185. "client": {}
  186. }
  187. }
  188. }
  189. }
  190. The members are:
  191. ``cmake``
  192. A JSON object containing information about the instance of CMake that
  193. generated the reply. It contains members:
  194. ``version``
  195. A JSON object specifying the version of CMake with members:
  196. ``major``, ``minor``, ``patch``
  197. Integer values specifying the major, minor, and patch version components.
  198. ``suffix``
  199. A string specifying the version suffix, if any, e.g. ``g0abc3``.
  200. ``string``
  201. A string specifying the full version in the format
  202. ``<major>.<minor>.<patch>[-<suffix>]``.
  203. ``isDirty``
  204. A boolean indicating whether the version was built from a version
  205. controlled source tree with local modifications.
  206. ``paths``
  207. A JSON object specifying paths to things that come with CMake.
  208. It has members for ``cmake``, ``ctest``, and ``cpack`` whose values
  209. are JSON strings specifying the absolute path to each tool,
  210. represented with forward slashes. It also has a ``root`` member for
  211. the absolute path to the directory containing CMake resources like the
  212. ``Modules/`` directory (see :variable:`CMAKE_ROOT`).
  213. ``generator``
  214. A JSON object describing the CMake generator used for the build.
  215. It has members:
  216. ``multiConfig``
  217. A boolean specifying whether the generator supports multiple output
  218. configurations.
  219. ``name``
  220. A string specifying the name of the generator.
  221. ``platform``
  222. If the generator supports :variable:`CMAKE_GENERATOR_PLATFORM`,
  223. this is a string specifying the generator platform name.
  224. ``objects``
  225. A JSON array listing all versions of all `Object Kinds`_ generated
  226. as part of the reply. Each array entry is a
  227. `v1 Reply File Reference`_.
  228. ``reply``
  229. A JSON object mirroring the content of the ``query/`` directory
  230. that CMake loaded to produce the reply. The members are of the form
  231. ``<kind>-v<major>``
  232. A member of this form appears for each of the
  233. `v1 Shared Stateless Query Files`_ that CMake recognized as a
  234. request for object kind ``<kind>`` with major version ``<major>``.
  235. The value is a `v1 Reply File Reference`_ to the corresponding
  236. reply file for that object kind and version.
  237. ``<unknown>``
  238. A member of this form appears for each of the
  239. `v1 Shared Stateless Query Files`_ that CMake did not recognize.
  240. The value is a JSON object with a single ``error`` member
  241. containing a string with an error message indicating that the
  242. query file is unknown.
  243. ``client-<client>``
  244. A member of this form appears for each client-owned directory
  245. holding `v1 Client Stateless Query Files`_.
  246. The value is a JSON object mirroring the content of the
  247. ``query/client-<client>/`` directory. The members are of the form:
  248. ``<kind>-v<major>``
  249. A member of this form appears for each of the
  250. `v1 Client Stateless Query Files`_ that CMake recognized as a
  251. request for object kind ``<kind>`` with major version ``<major>``.
  252. The value is a `v1 Reply File Reference`_ to the corresponding
  253. reply file for that object kind and version.
  254. ``<unknown>``
  255. A member of this form appears for each of the
  256. `v1 Client Stateless Query Files`_ that CMake did not recognize.
  257. The value is a JSON object with a single ``error`` member
  258. containing a string with an error message indicating that the
  259. query file is unknown.
  260. ``query.json``
  261. This member appears for clients using
  262. `v1 Client Stateful Query Files`_.
  263. If the ``query.json`` file failed to read or parse as a JSON object,
  264. this member is a JSON object with a single ``error`` member
  265. containing a string with an error message. Otherwise, this member
  266. is a JSON object mirroring the content of the ``query.json`` file.
  267. The members are:
  268. ``client``
  269. A copy of the ``query.json`` file ``client`` member, if it exists.
  270. ``requests``
  271. A copy of the ``query.json`` file ``requests`` member, if it exists.
  272. ``responses``
  273. If the ``query.json`` file ``requests`` member is missing or invalid,
  274. this member is a JSON object with a single ``error`` member
  275. containing a string with an error message. Otherwise, this member
  276. contains a JSON array with a response for each entry of the
  277. ``requests`` array, in the same order. Each response is
  278. * a JSON object with a single ``error`` member containing a string
  279. with an error message, or
  280. * a `v1 Reply File Reference`_ to the corresponding reply file for
  281. the requested object kind and selected version.
  282. After reading the reply index file, clients may read the other
  283. `v1 Reply Files`_ it references.
  284. v1 Reply File Reference
  285. ^^^^^^^^^^^^^^^^^^^^^^^
  286. The reply index file represents each reference to another reply file
  287. using a JSON object with members:
  288. ``kind``
  289. A string specifying one of the `Object Kinds`_.
  290. ``version``
  291. A JSON object with members ``major`` and ``minor`` specifying
  292. integer version components of the object kind.
  293. ``jsonFile``
  294. A JSON string specifying a path relative to the reply index file
  295. to another JSON file containing the object.
  296. v1 Reply Files
  297. --------------
  298. Reply files containing specific `Object Kinds`_ are written by CMake.
  299. The names of these files are unspecified and must not be interpreted
  300. by clients. Clients must first read the `v1 Reply Index File`_ and
  301. and follow references to the names of the desired response objects.
  302. Reply files (including the index file) will never be replaced by
  303. files of the same name but different content. This allows a client
  304. to read the files concurrently with a running CMake that may generate
  305. a new reply. However, after generating a new reply CMake will attempt
  306. to remove reply files from previous runs that it did not just write.
  307. If a client attempts to read a reply file referenced by the index but
  308. finds the file missing, that means a concurrent CMake has generated
  309. a new reply. The client may simply start again by reading the new
  310. reply index file.
  311. .. _`file-api object kinds`:
  312. Object Kinds
  313. ============
  314. The CMake file-based API reports semantic information about the build
  315. system using the following kinds of JSON objects. Each kind of object
  316. is versioned independently using semantic versioning with major and
  317. minor components. Every kind of object has the form:
  318. .. code-block:: json
  319. {
  320. "kind": "<kind>",
  321. "version": { "major": 1, "minor": 0 },
  322. "...": {}
  323. }
  324. The ``kind`` member is a string specifying the object kind name.
  325. The ``version`` member is a JSON object with ``major`` and ``minor``
  326. members specifying integer components of the object kind's version.
  327. Additional top-level members are specific to each object kind.
  328. Object Kind "codemodel"
  329. -----------------------
  330. The ``codemodel`` object kind describes the build system structure as
  331. modeled by CMake.
  332. There is only one ``codemodel`` object major version, version 2.
  333. Version 1 does not exist to avoid confusion with that from
  334. :manual:`cmake-server(7)` mode.
  335. "codemodel" version 2
  336. ^^^^^^^^^^^^^^^^^^^^^
  337. ``codemodel`` object version 2 is a JSON object:
  338. .. code-block:: json
  339. {
  340. "kind": "codemodel",
  341. "version": { "major": 2, "minor": 2 },
  342. "paths": {
  343. "source": "/path/to/top-level-source-dir",
  344. "build": "/path/to/top-level-build-dir"
  345. },
  346. "configurations": [
  347. {
  348. "name": "Debug",
  349. "directories": [
  350. {
  351. "source": ".",
  352. "build": ".",
  353. "childIndexes": [ 1 ],
  354. "projectIndex": 0,
  355. "targetIndexes": [ 0 ],
  356. "hasInstallRule": true,
  357. "minimumCMakeVersion": {
  358. "string": "3.14"
  359. }
  360. },
  361. {
  362. "source": "sub",
  363. "build": "sub",
  364. "parentIndex": 0,
  365. "projectIndex": 0,
  366. "targetIndexes": [ 1 ],
  367. "minimumCMakeVersion": {
  368. "string": "3.14"
  369. }
  370. }
  371. ],
  372. "projects": [
  373. {
  374. "name": "MyProject",
  375. "directoryIndexes": [ 0, 1 ],
  376. "targetIndexes": [ 0, 1 ]
  377. }
  378. ],
  379. "targets": [
  380. {
  381. "name": "MyExecutable",
  382. "directoryIndex": 0,
  383. "projectIndex": 0,
  384. "jsonFile": "<file>"
  385. },
  386. {
  387. "name": "MyLibrary",
  388. "directoryIndex": 1,
  389. "projectIndex": 0,
  390. "jsonFile": "<file>"
  391. }
  392. ]
  393. }
  394. ]
  395. }
  396. The members specific to ``codemodel`` objects are:
  397. ``paths``
  398. A JSON object containing members:
  399. ``source``
  400. A string specifying the absolute path to the top-level source directory,
  401. represented with forward slashes.
  402. ``build``
  403. A string specifying the absolute path to the top-level build directory,
  404. represented with forward slashes.
  405. ``configurations``
  406. A JSON array of entries corresponding to available build configurations.
  407. On single-configuration generators there is one entry for the value
  408. of the :variable:`CMAKE_BUILD_TYPE` variable. For multi-configuration
  409. generators there is an entry for each configuration listed in the
  410. :variable:`CMAKE_CONFIGURATION_TYPES` variable.
  411. Each entry is a JSON object containing members:
  412. ``name``
  413. A string specifying the name of the configuration, e.g. ``Debug``.
  414. ``directories``
  415. A JSON array of entries each corresponding to a build system directory
  416. whose source directory contains a ``CMakeLists.txt`` file. The first
  417. entry corresponds to the top-level directory. Each entry is a
  418. JSON object containing members:
  419. ``source``
  420. A string specifying the path to the source directory, represented
  421. with forward slashes. If the directory is inside the top-level
  422. source directory then the path is specified relative to that
  423. directory (with ``.`` for the top-level source directory itself).
  424. Otherwise the path is absolute.
  425. ``build``
  426. A string specifying the path to the build directory, represented
  427. with forward slashes. If the directory is inside the top-level
  428. build directory then the path is specified relative to that
  429. directory (with ``.`` for the top-level build directory itself).
  430. Otherwise the path is absolute.
  431. ``parentIndex``
  432. Optional member that is present when the directory is not top-level.
  433. The value is an unsigned integer 0-based index of another entry in
  434. the main ``directories`` array that corresponds to the parent
  435. directory that added this directory as a subdirectory.
  436. ``childIndexes``
  437. Optional member that is present when the directory has subdirectories.
  438. The value is a JSON array of entries corresponding to child directories
  439. created by the :command:`add_subdirectory` or :command:`subdirs`
  440. command. Each entry is an unsigned integer 0-based index of another
  441. entry in the main ``directories`` array.
  442. ``projectIndex``
  443. An unsigned integer 0-based index into the main ``projects`` array
  444. indicating the build system project to which the this directory belongs.
  445. ``targetIndexes``
  446. Optional member that is present when the directory itself has targets,
  447. excluding those belonging to subdirectories. The value is a JSON
  448. array of entries corresponding to the targets. Each entry is an
  449. unsigned integer 0-based index into the main ``targets`` array.
  450. ``minimumCMakeVersion``
  451. Optional member present when a minimum required version of CMake is
  452. known for the directory. This is the ``<min>`` version given to the
  453. most local call to the :command:`cmake_minimum_required(VERSION)`
  454. command in the directory itself or one of its ancestors.
  455. The value is a JSON object with one member:
  456. ``string``
  457. A string specifying the minimum required version in the format::
  458. <major>.<minor>[.<patch>[.<tweak>]][<suffix>]
  459. Each component is an unsigned integer and the suffix may be an
  460. arbitrary string.
  461. ``hasInstallRule``
  462. Optional member that is present with boolean value ``true`` when
  463. the directory or one of its subdirectories contains any
  464. :command:`install` rules, i.e. whether a ``make install``
  465. or equivalent rule is available.
  466. ``projects``
  467. A JSON array of entries corresponding to the top-level project
  468. and sub-projects defined in the build system. Each (sub-)project
  469. corresponds to a source directory whose ``CMakeLists.txt`` file
  470. calls the :command:`project` command with a project name different
  471. from its parent directory. The first entry corresponds to the
  472. top-level project.
  473. Each entry is a JSON object containing members:
  474. ``name``
  475. A string specifying the name given to the :command:`project` command.
  476. ``parentIndex``
  477. Optional member that is present when the project is not top-level.
  478. The value is an unsigned integer 0-based index of another entry in
  479. the main ``projects`` array that corresponds to the parent project
  480. that added this project as a sub-project.
  481. ``childIndexes``
  482. Optional member that is present when the project has sub-projects.
  483. The value is a JSON array of entries corresponding to the sub-projects.
  484. Each entry is an unsigned integer 0-based index of another
  485. entry in the main ``projects`` array.
  486. ``directoryIndexes``
  487. A JSON array of entries corresponding to build system directories
  488. that are part of the project. The first entry corresponds to the
  489. top-level directory of the project. Each entry is an unsigned
  490. integer 0-based index into the main ``directories`` array.
  491. ``targetIndexes``
  492. Optional member that is present when the project itself has targets,
  493. excluding those belonging to sub-projects. The value is a JSON
  494. array of entries corresponding to the targets. Each entry is an
  495. unsigned integer 0-based index into the main ``targets`` array.
  496. ``targets``
  497. A JSON array of entries corresponding to the build system targets.
  498. Such targets are created by calls to :command:`add_executable`,
  499. :command:`add_library`, and :command:`add_custom_target`, excluding
  500. imported targets and interface libraries (which do not generate any
  501. build rules). Each entry is a JSON object containing members:
  502. ``name``
  503. A string specifying the target name.
  504. ``id``
  505. A string uniquely identifying the target. This matches the ``id``
  506. field in the file referenced by ``jsonFile``.
  507. ``directoryIndex``
  508. An unsigned integer 0-based index into the main ``directories`` array
  509. indicating the build system directory in which the target is defined.
  510. ``projectIndex``
  511. An unsigned integer 0-based index into the main ``projects`` array
  512. indicating the build system project in which the target is defined.
  513. ``jsonFile``
  514. A JSON string specifying a path relative to the codemodel file
  515. to another JSON file containing a
  516. `"codemodel" version 2 "target" object`_.
  517. "codemodel" version 2 "target" object
  518. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  519. A codemodel "target" object is referenced by a `"codemodel" version 2`_
  520. object's ``targets`` array. Each "target" object is a JSON object
  521. with members:
  522. ``name``
  523. A string specifying the logical name of the target.
  524. ``id``
  525. A string uniquely identifying the target. The format is unspecified
  526. and should not be interpreted by clients.
  527. ``type``
  528. A string specifying the type of the target. The value is one of
  529. ``EXECUTABLE``, ``STATIC_LIBRARY``, ``SHARED_LIBRARY``,
  530. ``MODULE_LIBRARY``, ``OBJECT_LIBRARY``, ``INTERFACE_LIBRARY``,
  531. or ``UTILITY``.
  532. ``backtrace``
  533. Optional member that is present when a CMake language backtrace to
  534. the command in the source code that created the target is available.
  535. The value is an unsigned integer 0-based index into the
  536. ``backtraceGraph`` member's ``nodes`` array.
  537. ``folder``
  538. Optional member that is present when the :prop_tgt:`FOLDER` target
  539. property is set. The value is a JSON object with one member:
  540. ``name``
  541. A string specifying the name of the target folder.
  542. ``paths``
  543. A JSON object containing members:
  544. ``source``
  545. A string specifying the path to the target's source directory,
  546. represented with forward slashes. If the directory is inside the
  547. top-level source directory then the path is specified relative to
  548. that directory (with ``.`` for the top-level source directory itself).
  549. Otherwise the path is absolute.
  550. ``build``
  551. A string specifying the path to the target's build directory,
  552. represented with forward slashes. If the directory is inside the
  553. top-level build directory then the path is specified relative to
  554. that directory (with ``.`` for the top-level build directory itself).
  555. Otherwise the path is absolute.
  556. ``nameOnDisk``
  557. Optional member that is present for executable and library targets
  558. that are linked or archived into a single primary artifact.
  559. The value is a string specifying the file name of that artifact on disk.
  560. ``artifacts``
  561. Optional member that is present for executable and library targets
  562. that produce artifacts on disk meant for consumption by dependents.
  563. The value is a JSON array of entries corresponding to the artifacts.
  564. Each entry is a JSON object containing one member:
  565. ``path``
  566. A string specifying the path to the file on disk, represented with
  567. forward slashes. If the file is inside the top-level build directory
  568. then the path is specified relative to that directory.
  569. Otherwise the path is absolute.
  570. ``isGeneratorProvided``
  571. Optional member that is present with boolean value ``true`` if the
  572. target is provided by CMake's build system generator rather than by
  573. a command in the source code.
  574. ``install``
  575. Optional member that is present when the target has an :command:`install`
  576. rule. The value is a JSON object with members:
  577. ``prefix``
  578. A JSON object specifying the installation prefix. It has one member:
  579. ``path``
  580. A string specifying the value of :variable:`CMAKE_INSTALL_PREFIX`.
  581. ``destinations``
  582. A JSON array of entries specifying an install destination path.
  583. Each entry is a JSON object with members:
  584. ``path``
  585. A string specifying the install destination path. The path may
  586. be absolute or relative to the install prefix.
  587. ``backtrace``
  588. Optional member that is present when a CMake language backtrace to
  589. the :command:`install` command invocation that specified this
  590. destination is available. The value is an unsigned integer 0-based
  591. index into the ``backtraceGraph`` member's ``nodes`` array.
  592. ``link``
  593. Optional member that is present for executables and shared library
  594. targets that link into a runtime binary. The value is a JSON object
  595. with members describing the link step:
  596. ``language``
  597. A string specifying the language (e.g. ``C``, ``CXX``, ``Fortran``)
  598. of the toolchain is used to invoke the linker.
  599. ``commandFragments``
  600. Optional member that is present when fragments of the link command
  601. line invocation are available. The value is a JSON array of entries
  602. specifying ordered fragments. Each entry is a JSON object with members:
  603. ``fragment``
  604. A string specifying a fragment of the link command line invocation.
  605. The value is encoded in the build system's native shell format.
  606. ``role``
  607. A string specifying the role of the fragment's content:
  608. * ``flags``: link flags.
  609. * ``libraries``: link library file paths or flags.
  610. * ``libraryPath``: library search path flags.
  611. * ``frameworkPath``: macOS framework search path flags.
  612. ``lto``
  613. Optional member that is present with boolean value ``true``
  614. when link-time optimization (a.k.a. interprocedural optimization
  615. or link-time code generation) is enabled.
  616. ``sysroot``
  617. Optional member that is present when the :variable:`CMAKE_SYSROOT_LINK`
  618. or :variable:`CMAKE_SYSROOT` variable is defined. The value is a
  619. JSON object with one member:
  620. ``path``
  621. A string specifying the absolute path to the sysroot, represented
  622. with forward slashes.
  623. ``archive``
  624. Optional member that is present for static library targets. The value
  625. is a JSON object with members describing the archive step:
  626. ``commandFragments``
  627. Optional member that is present when fragments of the archiver command
  628. line invocation are available. The value is a JSON array of entries
  629. specifying the fragments. Each entry is a JSON object with members:
  630. ``fragment``
  631. A string specifying a fragment of the archiver command line invocation.
  632. The value is encoded in the build system's native shell format.
  633. ``role``
  634. A string specifying the role of the fragment's content:
  635. * ``flags``: archiver flags.
  636. ``lto``
  637. Optional member that is present with boolean value ``true``
  638. when link-time optimization (a.k.a. interprocedural optimization
  639. or link-time code generation) is enabled.
  640. ``dependencies``
  641. Optional member that is present when the target depends on other targets.
  642. The value is a JSON array of entries corresponding to the dependencies.
  643. Each entry is a JSON object with members:
  644. ``id``
  645. A string uniquely identifying the target on which this target depends.
  646. This matches the main ``id`` member of the other target.
  647. ``backtrace``
  648. Optional member that is present when a CMake language backtrace to
  649. the :command:`add_dependencies`, :command:`target_link_libraries`,
  650. or other command invocation that created this dependency is
  651. available. The value is an unsigned integer 0-based index into
  652. the ``backtraceGraph`` member's ``nodes`` array.
  653. ``sources``
  654. A JSON array of entries corresponding to the target's source files.
  655. Each entry is a JSON object with members:
  656. ``path``
  657. A string specifying the path to the source file on disk, represented
  658. with forward slashes. If the file is inside the top-level source
  659. directory then the path is specified relative to that directory.
  660. Otherwise the path is absolute.
  661. ``compileGroupIndex``
  662. Optional member that is present when the source is compiled.
  663. The value is an unsigned integer 0-based index into the
  664. ``compileGroups`` array.
  665. ``sourceGroupIndex``
  666. Optional member that is present when the source is part of a source
  667. group either via the :command:`source_group` command or by default.
  668. The value is an unsigned integer 0-based index into the
  669. ``sourceGroups`` array.
  670. ``isGenerated``
  671. Optional member that is present with boolean value ``true`` if
  672. the source is :prop_sf:`GENERATED`.
  673. ``backtrace``
  674. Optional member that is present when a CMake language backtrace to
  675. the :command:`target_sources`, :command:`add_executable`,
  676. :command:`add_library`, :command:`add_custom_target`, or other
  677. command invocation that added this source to the target is
  678. available. The value is an unsigned integer 0-based index into
  679. the ``backtraceGraph`` member's ``nodes`` array.
  680. ``sourceGroups``
  681. Optional member that is present when sources are grouped together by
  682. the :command:`source_group` command or by default. The value is a
  683. JSON array of entries corresponding to the groups. Each entry is
  684. a JSON object with members:
  685. ``name``
  686. A string specifying the name of the source group.
  687. ``sourceIndexes``
  688. A JSON array listing the sources belonging to the group.
  689. Each entry is an unsigned integer 0-based index into the
  690. main ``sources`` array for the target.
  691. ``compileGroups``
  692. Optional member that is present when the target has sources that compile.
  693. The value is a JSON array of entries corresponding to groups of sources
  694. that all compile with the same settings. Each entry is a JSON object
  695. with members:
  696. ``sourceIndexes``
  697. A JSON array listing the sources belonging to the group.
  698. Each entry is an unsigned integer 0-based index into the
  699. main ``sources`` array for the target.
  700. ``language``
  701. A string specifying the language (e.g. ``C``, ``CXX``, ``Fortran``)
  702. of the toolchain is used to compile the source file.
  703. ``languageStandard``
  704. Optional member that is present when the language standard is set
  705. explicitly (e.g. via :prop_tgt:`CXX_STANDARD`) or implicitly by
  706. compile features. Each entry is a JSON object with two members:
  707. ``backtraces``
  708. Optional member that is present when a CMake language backtrace to
  709. the ``<LANG>_STANDARD`` setting is available. If the language
  710. standard was set implicitly by compile features those are used as
  711. the backtrace(s). It's possible for multiple compile features to
  712. require the same language standard so there could be multiple
  713. backtraces. The value is a JSON array with each entry being an
  714. unsigned integer 0-based index into the ``backtraceGraph``
  715. member's ``nodes`` array.
  716. ``standard``
  717. String representing the language standard.
  718. This field was added in codemodel version 2.2.
  719. ``compileCommandFragments``
  720. Optional member that is present when fragments of the compiler command
  721. line invocation are available. The value is a JSON array of entries
  722. specifying ordered fragments. Each entry is a JSON object with
  723. one member:
  724. ``fragment``
  725. A string specifying a fragment of the compile command line invocation.
  726. The value is encoded in the build system's native shell format.
  727. ``includes``
  728. Optional member that is present when there are include directories.
  729. The value is a JSON array with an entry for each directory. Each
  730. entry is a JSON object with members:
  731. ``path``
  732. A string specifying the path to the include directory,
  733. represented with forward slashes.
  734. ``isSystem``
  735. Optional member that is present with boolean value ``true`` if
  736. the include directory is marked as a system include directory.
  737. ``backtrace``
  738. Optional member that is present when a CMake language backtrace to
  739. the :command:`target_include_directories` or other command invocation
  740. that added this include directory is available. The value is
  741. an unsigned integer 0-based index into the ``backtraceGraph``
  742. member's ``nodes`` array.
  743. ``precompileHeaders``
  744. Optional member that is present when :command:`target_precompile_headers`
  745. or other command invocations set :prop_tgt:`PRECOMPILE_HEADERS` on the
  746. target. The value is a JSON array with an entry for each header. Each
  747. entry is a JSON object with members:
  748. ``header``
  749. Full path to the precompile header file.
  750. ``backtrace``
  751. Optional member that is present when a CMake language backtrace to
  752. the :command:`target_precompile_headers` or other command invocation
  753. that added this precompiled header is available. The value is an
  754. unsigned integer 0-based index into the ``backtraceGraph`` member's
  755. ``nodes`` array.
  756. This field was added in codemodel version 2.1.
  757. ``defines``
  758. Optional member that is present when there are preprocessor definitions.
  759. The value is a JSON array with an entry for each definition. Each
  760. entry is a JSON object with members:
  761. ``define``
  762. A string specifying the preprocessor definition in the format
  763. ``<name>[=<value>]``, e.g. ``DEF`` or ``DEF=1``.
  764. ``backtrace``
  765. Optional member that is present when a CMake language backtrace to
  766. the :command:`target_compile_definitions` or other command invocation
  767. that added this preprocessor definition is available. The value is
  768. an unsigned integer 0-based index into the ``backtraceGraph``
  769. member's ``nodes`` array.
  770. ``sysroot``
  771. Optional member that is present when the
  772. :variable:`CMAKE_SYSROOT_COMPILE` or :variable:`CMAKE_SYSROOT`
  773. variable is defined. The value is a JSON object with one member:
  774. ``path``
  775. A string specifying the absolute path to the sysroot, represented
  776. with forward slashes.
  777. ``backtraceGraph``
  778. A `"codemodel" version 2 "backtrace graph"`_ whose nodes are referenced
  779. from ``backtrace`` members elsewhere in this "target" object.
  780. "codemodel" version 2 "backtrace graph"
  781. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  782. The ``backtraceGraph`` member of a `"codemodel" version 2 "target" object`_
  783. is a JSON object describing a graph of backtraces. Its nodes are referenced
  784. from ``backtrace`` members elsewhere in the containing object.
  785. The backtrace graph object members are:
  786. ``nodes``
  787. A JSON array listing nodes in the backtrace graph. Each entry
  788. is a JSON object with members:
  789. ``file``
  790. An unsigned integer 0-based index into the backtrace ``files`` array.
  791. ``line``
  792. An optional member present when the node represents a line within
  793. the file. The value is an unsigned integer 1-based line number.
  794. ``command``
  795. An optional member present when the node represents a command
  796. invocation within the file. The value is an unsigned integer
  797. 0-based index into the backtrace ``commands`` array.
  798. ``parent``
  799. An optional member present when the node is not the bottom of
  800. the call stack. The value is an unsigned integer 0-based index
  801. of another entry in the backtrace ``nodes`` array.
  802. ``commands``
  803. A JSON array listing command names referenced by backtrace nodes.
  804. Each entry is a string specifying a command name.
  805. ``files``
  806. A JSON array listing CMake language files referenced by backtrace nodes.
  807. Each entry is a string specifying the path to a file, represented
  808. with forward slashes. If the file is inside the top-level source
  809. directory then the path is specified relative to that directory.
  810. Otherwise the path is absolute.
  811. Object Kind "cache"
  812. -------------------
  813. The ``cache`` object kind lists cache entries. These are the
  814. :ref:`CMake Language Variables` stored in the persistent cache
  815. (``CMakeCache.txt``) for the build tree.
  816. There is only one ``cache`` object major version, version 2.
  817. Version 1 does not exist to avoid confusion with that from
  818. :manual:`cmake-server(7)` mode.
  819. "cache" version 2
  820. ^^^^^^^^^^^^^^^^^
  821. ``cache`` object version 2 is a JSON object:
  822. .. code-block:: json
  823. {
  824. "kind": "cache",
  825. "version": { "major": 2, "minor": 0 },
  826. "entries": [
  827. {
  828. "name": "BUILD_SHARED_LIBS",
  829. "value": "ON",
  830. "type": "BOOL",
  831. "properties": [
  832. {
  833. "name": "HELPSTRING",
  834. "value": "Build shared libraries"
  835. }
  836. ]
  837. },
  838. {
  839. "name": "CMAKE_GENERATOR",
  840. "value": "Unix Makefiles",
  841. "type": "INTERNAL",
  842. "properties": [
  843. {
  844. "name": "HELPSTRING",
  845. "value": "Name of generator."
  846. }
  847. ]
  848. }
  849. ]
  850. }
  851. The members specific to ``cache`` objects are:
  852. ``entries``
  853. A JSON array whose entries are each a JSON object specifying a
  854. cache entry. The members of each entry are:
  855. ``name``
  856. A string specifying the name of the entry.
  857. ``value``
  858. A string specifying the value of the entry.
  859. ``type``
  860. A string specifying the type of the entry used by
  861. :manual:`cmake-gui(1)` to choose a widget for editing.
  862. ``properties``
  863. A JSON array of entries specifying associated
  864. :ref:`cache entry properties <Cache Entry Properties>`.
  865. Each entry is a JSON object containing members:
  866. ``name``
  867. A string specifying the name of the cache entry property.
  868. ``value``
  869. A string specifying the value of the cache entry property.
  870. Object Kind "cmakeFiles"
  871. ------------------------
  872. The ``cmakeFiles`` object kind lists files used by CMake while
  873. configuring and generating the build system. These include the
  874. ``CMakeLists.txt`` files as well as included ``.cmake`` files.
  875. There is only one ``cmakeFiles`` object major version, version 1.
  876. "cmakeFiles" version 1
  877. ^^^^^^^^^^^^^^^^^^^^^^
  878. ``cmakeFiles`` object version 1 is a JSON object:
  879. .. code-block:: json
  880. {
  881. "kind": "cmakeFiles",
  882. "version": { "major": 1, "minor": 0 },
  883. "paths": {
  884. "build": "/path/to/top-level-build-dir",
  885. "source": "/path/to/top-level-source-dir"
  886. },
  887. "inputs": [
  888. {
  889. "path": "CMakeLists.txt"
  890. },
  891. {
  892. "isGenerated": true,
  893. "path": "/path/to/top-level-build-dir/.../CMakeSystem.cmake"
  894. },
  895. {
  896. "isExternal": true,
  897. "path": "/path/to/external/third-party/module.cmake"
  898. },
  899. {
  900. "isCMake": true,
  901. "isExternal": true,
  902. "path": "/path/to/cmake/Modules/CMakeGenericSystem.cmake"
  903. }
  904. ]
  905. }
  906. The members specific to ``cmakeFiles`` objects are:
  907. ``paths``
  908. A JSON object containing members:
  909. ``source``
  910. A string specifying the absolute path to the top-level source directory,
  911. represented with forward slashes.
  912. ``build``
  913. A string specifying the absolute path to the top-level build directory,
  914. represented with forward slashes.
  915. ``inputs``
  916. A JSON array whose entries are each a JSON object specifying an input
  917. file used by CMake when configuring and generating the build system.
  918. The members of each entry are:
  919. ``path``
  920. A string specifying the path to an input file to CMake, represented
  921. with forward slashes. If the file is inside the top-level source
  922. directory then the path is specified relative to that directory.
  923. Otherwise the path is absolute.
  924. ``isGenerated``
  925. Optional member that is present with boolean value ``true``
  926. if the path specifies a file that is under the top-level
  927. build directory and the build is out-of-source.
  928. This member is not available on in-source builds.
  929. ``isExternal``
  930. Optional member that is present with boolean value ``true``
  931. if the path specifies a file that is not under the top-level
  932. source or build directories.
  933. ``isCMake``
  934. Optional member that is present with boolean value ``true``
  935. if the path specifies a file in the CMake installation.
  936. Object Kind "toolchains"
  937. ------------------------
  938. The ``toolchains`` object kind lists properties of the toolchains used during
  939. the build. These include the language, compiler path, ID, and version.
  940. There is only one ``toolchains`` object major version, version 1.
  941. "toolchains" version 1
  942. ^^^^^^^^^^^^^^^^^^^^^^
  943. ``toolchains`` object version 1 is a JSON object:
  944. .. code-block:: json
  945. {
  946. "kind": "toolchains",
  947. "version": { "major": 1, "minor": 0 },
  948. "toolchains": [
  949. {
  950. "language": "C",
  951. "compiler": {
  952. "path": "/usr/bin/cc",
  953. "id": "GNU",
  954. "version": "9.3.0",
  955. "implicit": {
  956. "includeDirectories": [
  957. "/usr/lib/gcc/x86_64-linux-gnu/9/include",
  958. "/usr/local/include",
  959. "/usr/include/x86_64-linux-gnu",
  960. "/usr/include"
  961. ],
  962. "linkDirectories": [
  963. "/usr/lib/gcc/x86_64-linux-gnu/9",
  964. "/usr/lib/x86_64-linux-gnu",
  965. "/usr/lib",
  966. "/lib/x86_64-linux-gnu",
  967. "/lib"
  968. ],
  969. "linkFrameworkDirectories": [],
  970. "linkLibraries": [ "gcc", "gcc_s", "c", "gcc", "gcc_s" ]
  971. }
  972. },
  973. "sourceFileExtensions": [ "c", "m" ]
  974. },
  975. {
  976. "language": "CXX",
  977. "compiler": {
  978. "path": "/usr/bin/c++",
  979. "id": "GNU",
  980. "version": "9.3.0",
  981. "implicit": {
  982. "includeDirectories": [
  983. "/usr/include/c++/9",
  984. "/usr/include/x86_64-linux-gnu/c++/9",
  985. "/usr/include/c++/9/backward",
  986. "/usr/lib/gcc/x86_64-linux-gnu/9/include",
  987. "/usr/local/include",
  988. "/usr/include/x86_64-linux-gnu",
  989. "/usr/include"
  990. ],
  991. "linkDirectories": [
  992. "/usr/lib/gcc/x86_64-linux-gnu/9",
  993. "/usr/lib/x86_64-linux-gnu",
  994. "/usr/lib",
  995. "/lib/x86_64-linux-gnu",
  996. "/lib"
  997. ],
  998. "linkFrameworkDirectories": [],
  999. "linkLibraries": [
  1000. "stdc++", "m", "gcc_s", "gcc", "c", "gcc_s", "gcc"
  1001. ]
  1002. }
  1003. },
  1004. "sourceFileExtensions": [
  1005. "C", "M", "c++", "cc", "cpp", "cxx", "mm", "CPP"
  1006. ]
  1007. }
  1008. ]
  1009. }
  1010. The members specific to ``toolchains`` objects are:
  1011. ``toolchains``
  1012. A JSON array whose entries are each a JSON object specifying a toolchain
  1013. associated with a particular language. The members of each entry are:
  1014. ``language``
  1015. A JSON string specifying the toolchain language, like C or CXX. Language
  1016. names are the same as langauge names that can be passed to the
  1017. :command:`project` command. Because CMake only supports a single toolchain
  1018. per language, this field can be used as a key.
  1019. ``compiler``
  1020. A JSON object containing members:
  1021. ``path``
  1022. Optional member that is present when the
  1023. :variable:`CMAKE_<LANG>_COMPILER` variable is defined for the current
  1024. language. Its value is a JSON string holding the path to the compiler.
  1025. ``id``
  1026. Optional member that is present when the
  1027. :variable:`CMAKE_<LANG>_COMPILER_ID` variable is defined for the current
  1028. language. Its value is a JSON string holding the ID (GNU, MSVC, etc.) of
  1029. the compiler.
  1030. ``version``
  1031. Optional member that is present when the
  1032. :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable is defined for the
  1033. current language. Its value is a JSON string holding the version of the
  1034. compiler.
  1035. ``target``
  1036. Optional member that is present when the
  1037. :variable:`CMAKE_<LANG>_COMPILER_TARGET` variable is defined for the
  1038. current language. Its value is a JSON string holding the cross-compiling
  1039. target of the compiler.
  1040. ``implicit``
  1041. A JSON object containing members:
  1042. ``includeDirectories``
  1043. Optional member that is present when the
  1044. :variable:`CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES` variable is
  1045. defined for the current language. Its value is a JSON array of JSON
  1046. strings where each string holds a path to an implicit include
  1047. directory for the compiler.
  1048. ``linkDirectories``
  1049. Optional member that is present when the
  1050. :variable:`CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES` variable is
  1051. defined for the current language. Its value is a JSON array of JSON
  1052. strings where each string holds a path to an implicit link directory
  1053. for the compiler.
  1054. ``linkFrameworkDirectories``
  1055. Optional member that is present when the
  1056. :variable:`CMAKE_<LANG>_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES` variable
  1057. is defined for the current language. Its value is a JSON array of JSON
  1058. strings where each string holds a path to an implicit link framework
  1059. directory for the compiler.
  1060. ``linkLibraries``
  1061. Optional member that is present when the
  1062. :variable:`CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES` variable is defined
  1063. for the current language. Its value is a JSON array of JSON strings
  1064. where each string holds a path to an implicit link library for the
  1065. compiler.
  1066. ``sourceFileExtensions``
  1067. Optional member that is present when the
  1068. :variable:`CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS` variable is defined for
  1069. the current language. Its value is a JSON array of JSON strings where each
  1070. each string holds a file extension (without the leading dot) for the
  1071. language.