cmake_file_api.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_file_api
  2. --------------
  3. .. versionadded:: 3.27
  4. Enables interacting with the :manual:`CMake file API <cmake-file-api(7)>`.
  5. .. signature::
  6. cmake_file_api(QUERY ...)
  7. The ``QUERY`` subcommand adds a file API query for the current CMake
  8. invocation.
  9. .. code-block:: cmake
  10. cmake_file_api(
  11. QUERY
  12. API_VERSION <version>
  13. [CODEMODEL <versions>...]
  14. [CACHE <versions>...]
  15. [CMAKEFILES <versions>...]
  16. [TOOLCHAINS <versions>...]
  17. )
  18. The ``API_VERSION`` must always be given. Currently, the only supported
  19. value for ``<version>`` is 1. See :ref:`file-api v1` for details of the
  20. reply content and location.
  21. Each of the optional keywords ``CODEMODEL``, ``CACHE``, ``CMAKEFILES`` and
  22. ``TOOLCHAINS`` correspond to one of the object kinds that can be requested
  23. by the project. The ``configureLog`` object kind cannot be set with this
  24. command, since it must be set before CMake starts reading the top level
  25. ``CMakeLists.txt`` file.
  26. For each of the optional keywords, the ``<versions>`` list must contain one
  27. or more version values of the form ``major`` or ``major.minor``, where
  28. ``major`` and ``minor`` are integers. Projects should list the versions they
  29. accept in their preferred order, as only the first supported value from the
  30. list will be selected. The command will ignore versions with a ``major``
  31. version higher than any major version it supports for that object kind.
  32. It will raise an error if it encounters an invalid version number, or if none
  33. of the requested versions is supported.
  34. For each type of object kind requested, a query equivalent to a shared,
  35. stateless query will be added internally. No query file will be created in
  36. the file system. The reply *will* be written to the file system at
  37. generation time.
  38. It is not an error to add a query for the same thing more than once, whether
  39. from query files or from multiple calls to ``cmake_file_api(QUERY)``.
  40. The final set of queries will be a merged combination of all queries
  41. specified on disk and queries submitted by the project.
  42. Example
  43. ^^^^^^^
  44. A project may want to use replies from the file API at build time to implement
  45. some form of verification task. Instead of relying on something outside of
  46. CMake to create a query file, the project can use ``cmake_file_api(QUERY)``
  47. to request the required information for the current run. It can then create
  48. a custom command to run at build time, knowing that the requested information
  49. should always be available.
  50. .. code-block:: cmake
  51. cmake_file_api(
  52. QUERY
  53. API_VERSION 1
  54. CODEMODEL 2.3
  55. TOOLCHAINS 1
  56. )
  57. add_custom_target(verify_project
  58. COMMAND ${CMAKE_COMMAND}
  59. -D BUILD_DIR=${CMAKE_BINARY_DIR}
  60. -D CONFIG=$<CONFIG>
  61. -P ${CMAKE_CURRENT_SOURCE_DIR}/verify_project.cmake
  62. )