1
0

cmake-file-api.7.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. ``reply/``
  27. Holds reply files written by CMake whenever it runs to generate a build
  28. system. These are indexed by a `v1 Reply Index File`_ file that may
  29. reference additional `v1 Reply Files`_. CMake owns all reply files.
  30. Clients must never remove them.
  31. Clients may look for and read a reply index file at any time.
  32. Clients may optionally create the ``reply/`` directory at any time
  33. and monitor it for the appearance of a new reply index file.
  34. v1 Shared Stateless Query Files
  35. -------------------------------
  36. Shared stateless query files allow clients to share requests for
  37. major versions of the `Object Kinds`_ and get all requested versions
  38. recognized by the CMake that runs.
  39. Clients may create shared requests by creating empty files in the
  40. ``v1/query/`` directory. The form is::
  41. <build>/.cmake/api/v1/query/<kind>-v<major>
  42. where ``<kind>`` is one of the `Object Kinds`_, ``-v`` is literal,
  43. and ``<major>`` is the major version number.
  44. Files of this form are stateless shared queries not owned by any specific
  45. client. Once created they should not be removed without external client
  46. coordination or human intervention.
  47. v1 Reply Index File
  48. -------------------
  49. CMake writes an ``index-*.json`` file to the ``v1/reply/`` directory
  50. whenever it runs to generate a build system. Clients must read the
  51. reply index file first and may read other `v1 Reply Files`_ only by
  52. following references. The form of the reply index file name is::
  53. <build>/.cmake/api/v1/reply/index-<unspecified>.json
  54. where ``index-`` is literal and ``<unspecified>`` is an unspecified
  55. name selected by CMake. Whenever a new index file is generated it
  56. is given a new name and any old one is deleted. During the short
  57. time between these steps there may be multiple index files present;
  58. the one with the largest name in lexicographic order is the current
  59. index file.
  60. The reply index file contains a JSON object:
  61. .. code-block:: json
  62. {
  63. "cmake": {
  64. "version": {
  65. "major": 3, "minor": 14, "patch": 0, "suffix": "",
  66. "string": "3.14.0", "isDirty": false
  67. },
  68. "paths": {
  69. "cmake": "/prefix/bin/cmake",
  70. "ctest": "/prefix/bin/ctest",
  71. "cpack": "/prefix/bin/cpack",
  72. "root": "/prefix/share/cmake-3.14"
  73. }
  74. },
  75. "objects": [
  76. { "kind": "<kind>",
  77. "version": { "major": 1, "minor": 0 },
  78. "jsonFile": "<file>" },
  79. { "...": "..." }
  80. ],
  81. "reply": {
  82. "<kind>-v<major>": { "kind": "<kind>",
  83. "version": { "major": 1, "minor": 0 },
  84. "jsonFile": "<file>" },
  85. "<unknown>": { "error": "unknown query file" },
  86. "...": {}
  87. }
  88. }
  89. The members are:
  90. ``cmake``
  91. A JSON object containing information about the instance of CMake that
  92. generated the reply. It contains members:
  93. ``version``
  94. A JSON object specifying the version of CMake with members:
  95. ``major``, ``minor``, ``patch``
  96. Integer values specifying the major, minor, and patch version components.
  97. ``suffix``
  98. A string specifying the version suffix, if any, e.g. ``g0abc3``.
  99. ``string``
  100. A string specifying the full version in the format
  101. ``<major>.<minor>.<patch>[-<suffix>]``.
  102. ``isDirty``
  103. A boolean indicating whether the version was built from a version
  104. controlled source tree with local modifications.
  105. ``paths``
  106. A JSON object specifying paths to things that come with CMake.
  107. It has members for ``cmake``, ``ctest``, and ``cpack`` whose values
  108. are JSON strings specifying the absolute path to each tool,
  109. represented with forward slashes. It also has a ``root`` member for
  110. the absolute path to the directory containing CMake resources like the
  111. ``Modules/`` directory (see :variable:`CMAKE_ROOT`).
  112. ``objects``
  113. A JSON array listing all versions of all `Object Kinds`_ generated
  114. as part of the reply. Each array entry is a
  115. `v1 Reply File Reference`_.
  116. ``reply``
  117. A JSON object mirroring the content of the ``query/`` directory
  118. that CMake loaded to produce the reply. The members are of the form
  119. ``<kind>-v<major>``
  120. A member of this form appears for each of the
  121. `v1 Shared Stateless Query Files`_ that CMake recognized as a
  122. request for object kind ``<kind>`` with major version ``<major>``.
  123. The value is a `v1 Reply File Reference`_ to the corresponding
  124. reply file for that object kind and version.
  125. ``<unknown>``
  126. A member of this form appears for each of the
  127. `v1 Shared Stateless Query Files`_ that CMake did not recognize.
  128. The value is a JSON object with a single ``error`` member
  129. containing a string with an error message indicating that the
  130. query file is unknown.
  131. After reading the reply index file, clients may read the other
  132. `v1 Reply Files`_ it references.
  133. v1 Reply File Reference
  134. ^^^^^^^^^^^^^^^^^^^^^^^
  135. The reply index file represents each reference to another reply file
  136. using a JSON object with members:
  137. ``kind``
  138. A string specifying one of the `Object Kinds`_.
  139. ``version``
  140. A JSON object with members ``major`` and ``minor`` specifying
  141. integer version components of the object kind.
  142. ``jsonFile``
  143. A JSON string specifying a path relative to the reply index file
  144. to another JSON file containing the object.
  145. v1 Reply Files
  146. --------------
  147. Reply files containing specific `Object Kinds`_ are written by CMake.
  148. The names of these files are unspecified and must not be interpreted
  149. by clients. Clients must first read the `v1 Reply Index File`_ and
  150. and follow references to the names of the desired response objects.
  151. Reply files (including the index file) will never be replaced by
  152. files of the same name but different content. This allows a client
  153. to read the files concurrently with a running CMake that may generate
  154. a new reply. However, after generating a new reply CMake will attempt
  155. to remove reply files from previous runs that it did not just write.
  156. If a client attempts to read a reply file referenced by the index but
  157. finds the file missing, that means a concurrent CMake has generated
  158. a new reply. The client may simply start again by reading the new
  159. reply index file.
  160. Object Kinds
  161. ============
  162. The CMake file-based API reports semantic information about the build
  163. system using the following kinds of JSON objects. Each kind of object
  164. is versioned independently using semantic versioning with major and
  165. minor components. Every kind of object has the form:
  166. .. code-block:: json
  167. {
  168. "kind": "<kind>",
  169. "version": { "major": 1, "minor": 0 },
  170. "...": {}
  171. }
  172. The ``kind`` member is a string specifying the object kind name.
  173. The ``version`` member is a JSON object with ``major`` and ``minor``
  174. members specifying integer components of the object kind's version.
  175. Additional top-level members are specific to each object kind.