experimental.rst 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 `P1689r4`_ paper.
  33. Compiler writers may try out their scanning functionality using
  34. the `cxx-modules-sandbox`_ test project, modified to set variables
  35. as above for their compiler.
  36. For compilers that generate module maps, tell CMake as follows:
  37. .. code-block:: cmake
  38. set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
  39. set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
  40. "${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
  41. Currently, the only supported format is ``gcc``. The format is described in
  42. the GCC documentation, but the relevant section for the purposes of CMake is:
  43. A mapping file consisting of space-separated module-name, filename
  44. pairs, one per line. Only the mappings for the direct imports and any
  45. module export name need be provided. If other mappings are provided,
  46. they override those stored in any imported CMI files. A repository
  47. root may be specified in the mapping file by using ``$root`` as the
  48. module name in the first active line.
  49. -- GCC module mapper documentation
  50. .. _`D1483r1`: https://mathstuf.fedorapeople.org/fortran-modules/fortran-modules.html
  51. .. _`P1689r4`: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1689r4.html
  52. .. _`cxx-modules-sandbox`: https://github.com/mathstuf/cxx-modules-sandbox