experimental.rst 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. CMake Experimental Features Guide
  2. *********************************
  3. The following is a guide to CMake experimental features that are
  4. under development and not yet included in official documentation.
  5. See documentation on `CMake Development`_ for more information.
  6. .. _`CMake Development`: README.rst
  7. C++20 Module Dependencies
  8. =========================
  9. The Ninja generator has experimental infrastructure supporting C++20 module
  10. dependency scanning. This is similar to the Fortran modules support, but
  11. relies on external tools to scan C++20 translation units for module
  12. dependencies. The approach is described by Kitware's `D1483r1`_ paper.
  13. The ``CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP`` variable can be set to ``1``
  14. in order to activate this undocumented experimental infrastructure. This
  15. is **intended to make the functionality available to compiler writers** so
  16. they can use it to develop and test their dependency scanning tool.
  17. The ``CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE`` variable must also be set
  18. to tell CMake how to invoke the C++20 module dependency scanning tool.
  19. For example, add code like the following to a test project:
  20. .. code-block:: cmake
  21. set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
  22. string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
  23. "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE>"
  24. " -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
  25. " ${flags_to_scan_deps} -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT>"
  26. )
  27. The tool specified by ``CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE`` is
  28. expected to process the translation unit, write preprocessor dependencies
  29. to the file specified by the ``<DEP_FILE>`` placeholder, and write module
  30. dependencies to the file specified by the ``<DYNDEP_FILE>`` placeholder.
  31. The module dependencies should be written in the format described
  32. by the `P1689r3`_ paper, with the following updates:
  33. * Omit the ``outputs``, ``inputs``, and ``depends`` fields from
  34. each entry in the ``rules`` array. They are unused.
  35. * Flatten ``future-compile`` members directly into each rule.
  36. * Factor a ``primary-output`` field out of the now-flattened ``outputs``.
  37. * The ``work-directory`` field is optional.
  38. Compiler writers may try out their scanning functionality using
  39. the `cxx-modules-sandbox`_ test project, modified to set variables
  40. as above for their compiler.
  41. For compilers that generate module maps, tell CMake as follows:
  42. .. code-block:: cmake
  43. set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
  44. set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
  45. "${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
  46. Currently, the only supported format is ``gcc``. The format is described in
  47. the GCC documentation, but the relevant section for the purposes of CMake is:
  48. A mapping file consisting of space-separated module-name, filename
  49. pairs, one per line. Only the mappings for the direct imports and any
  50. module export name need be provided. If other mappings are provided,
  51. they override those stored in any imported CMI files. A repository
  52. root may be specified in the mapping file by using ``$root`` as the
  53. module name in the first active line.
  54. -- GCC module mapper documentation
  55. .. _`D1483r1`: https://mathstuf.fedorapeople.org/fortran-modules/fortran-modules.html
  56. .. _`P1689r3`: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1689r3.html
  57. .. _`cxx-modules-sandbox`: https://github.com/mathstuf/cxx-modules-sandbox