cmake_instrumentation.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. cmake_instrumentation
  2. ---------------------
  3. .. versionadded:: 4.0
  4. .. note::
  5. This command is only available when experimental support for instrumentation
  6. has been enabled by the ``CMAKE_EXPERIMENTAL_INSTRUMENTATION`` gate.
  7. Enables interacting with the
  8. :manual:`CMake Instrumentation API <cmake-instrumentation(7)>`.
  9. This allows for configuring instrumentation at the project-level.
  10. .. code-block:: cmake
  11. cmake_instrumentation(
  12. API_VERSION <version>
  13. DATA_VERSION <version>
  14. [HOOKS <hooks>...]
  15. [OPTIONS <options>...]
  16. [CALLBACK <callback>]
  17. [CUSTOM_CONTENT <name> <type> <content>]
  18. )
  19. The ``API_VERSION`` and ``DATA_VERSION`` must always be given. Currently, the
  20. only supported value for both fields is 1. See :ref:`cmake-instrumentation API v1`
  21. for details of the ``API_VERSION`` and :ref:`cmake-instrumentation Data v1` for details
  22. of the ``DATA_VERSION``.
  23. Each of the optional keywords ``HOOKS``, ``OPTIONS``, and ``CALLBACK``
  24. correspond to one of the parameters to the :ref:`cmake-instrumentation v1 Query Files`.
  25. The ``CALLBACK`` keyword can be provided multiple times to create multiple callbacks.
  26. Whenever ``cmake_instrumentation`` is invoked, a query file is generated in
  27. ``<build>/.cmake/instrumentation/v1/query/generated`` to enable instrumentation
  28. with the provided arguments.
  29. .. _`cmake_instrumentation Configure Content`:
  30. Custom Configure Content
  31. ^^^^^^^^^^^^^^^^^^^^^^^^
  32. The ``CUSTOM_CONTENT`` argument specifies certain data from configure time to
  33. include in each :ref:`cmake-instrumentation v1 Snippet File` that
  34. corresponds to the configure step associated with the command. This may be used
  35. to associate instrumentation data with certain information about its
  36. configuration, such as the optimization level or whether it is part of a
  37. coverage build.
  38. ``CUSTOM_CONTENT`` expects ``name``, ``type`` and ``content`` arguments.
  39. ``name`` is a specifier to identify the content being reported.
  40. ``type`` specifies how the content should be interpreted. Supported values are:
  41. * ``STRING`` the content is a string.
  42. * ``BOOL`` the content should be interpreted as a boolean. It will be ``true``
  43. under the same conditions that ``if()`` would be true for the given value.
  44. * ``LIST`` the content is a CMake ``;`` separated list that should be parsed.
  45. * ``JSON`` the content should be parsed as a JSON string. This can be a
  46. number such as ``1`` or ``5.0``, a quoted string such as ``\"string\"``,
  47. a boolean value ``true``/``false``, or a JSON object such as
  48. ``{ \"key\" : \"value\" }`` that may be constructed using
  49. ``string(JSON ...)`` commands.
  50. ``content`` is the actual content to report.
  51. Example
  52. ^^^^^^^
  53. The following example shows an invocation of the command and its
  54. equivalent JSON query file.
  55. .. code-block:: cmake
  56. cmake_instrumentation(
  57. API_VERSION 1
  58. DATA_VERSION 1
  59. HOOKS postGenerate preCMakeBuild postCMakeBuild
  60. OPTIONS staticSystemInformation dynamicSystemInformation trace
  61. CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data.cmake
  62. CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data_2.cmake
  63. CUSTOM_CONTENT myString STRING string
  64. CUSTOM_CONTENT myList LIST "item1;item2"
  65. CUSTOM_CONTENT myObject JSON "{ \"key\" : \"value\" }"
  66. )
  67. .. code-block:: json
  68. {
  69. "version": 1,
  70. "hooks": [
  71. "postGenerate", "preCMakeBuild", "postCMakeBuild"
  72. ],
  73. "options": [
  74. "staticSystemInformation", "dynamicSystemInformation", "trace"
  75. ],
  76. "callbacks": [
  77. "/path/to/cmake -P /path/to/handle_data.cmake"
  78. "/path/to/cmake -P /path/to/handle_data_2.cmake"
  79. ]
  80. }
  81. This will also result in a configure content JSON being reported in each
  82. :ref:`cmake-instrumentation v1 Snippet File` with the following contents:
  83. .. code-block:: json
  84. {
  85. "myString": "string",
  86. "myList": [
  87. "item1", "item2"
  88. ],
  89. "myObject": {
  90. "key": "value"
  91. }
  92. }