cmake_instrumentation.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 CUSTOM_CONTENT`:
  30. Custom CMake Content
  31. ^^^^^^^^^^^^^^^^^^^^
  32. The ``CUSTOM_CONTENT`` argument specifies certain data from configure time to
  33. include in each :ref:`cmake-instrumentation v1 CMake Content File`. This
  34. may be used to associate instrumentation data with certain information about its
  35. configuration, such as the optimization level or whether it is part of a
  36. coverage build.
  37. ``CUSTOM_CONTENT`` expects ``name``, ``type`` and ``content`` arguments.
  38. ``name`` is a specifier to identify the content being reported.
  39. ``type`` specifies how the content should be interpreted. Supported values are:
  40. * ``STRING`` the content is a string.
  41. * ``BOOL`` the content should be interpreted as a boolean. It will be ``true``
  42. under the same conditions that ``if()`` would be true for the given value.
  43. * ``LIST`` the content is a CMake ``;`` separated list that should be parsed.
  44. * ``JSON`` the content should be parsed as a JSON string. This can be a
  45. number such as ``1`` or ``5.0``, a quoted string such as ``\"string\"``,
  46. a boolean value ``true``/``false``, or a JSON object such as
  47. ``{ \"key\" : \"value\" }`` that may be constructed using
  48. ``string(JSON ...)`` commands.
  49. ``content`` is the actual content to report.
  50. Example
  51. ^^^^^^^
  52. The following example shows an invocation of the command and its
  53. equivalent JSON query file.
  54. .. code-block:: cmake
  55. cmake_instrumentation(
  56. API_VERSION 1
  57. DATA_VERSION 1
  58. HOOKS postGenerate preCMakeBuild postCMakeBuild
  59. OPTIONS staticSystemInformation dynamicSystemInformation trace
  60. CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data.cmake
  61. CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data_2.cmake
  62. CUSTOM_CONTENT myString STRING string
  63. CUSTOM_CONTENT myList LIST "item1;item2"
  64. CUSTOM_CONTENT myObject JSON "{ \"key\" : \"value\" }"
  65. )
  66. .. code-block:: json
  67. {
  68. "version": 1,
  69. "hooks": [
  70. "postGenerate", "preCMakeBuild", "postCMakeBuild"
  71. ],
  72. "options": [
  73. "staticSystemInformation", "dynamicSystemInformation", "trace"
  74. ],
  75. "callbacks": [
  76. "/path/to/cmake -P /path/to/handle_data.cmake"
  77. "/path/to/cmake -P /path/to/handle_data_2.cmake"
  78. ]
  79. }
  80. This will also result in the following content included in each
  81. :ref:`cmake-instrumentation v1 CMake Content File`:
  82. .. code-block:: json
  83. "custom": {
  84. "myString": "string",
  85. "myList": [
  86. "item1", "item2"
  87. ],
  88. "myObject": {
  89. "key": "value"
  90. }
  91. }