cmake-cxxmodules.7.rst 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .. cmake-manual-description: CMake C++ Modules Support Reference
  2. cmake-cxxmodules(7)
  3. *******************
  4. .. versionadded:: 3.28
  5. C++ 20 introduced the concept of "modules" to the language. The design
  6. requires build systems to order compilations among each other to satisfy
  7. ``import`` statements reliably. CMake's implementation asks the compiler
  8. to scan source files for module dependencies during the build, collates
  9. scanning results to infer ordering constraints, and tells the build tool
  10. how to dynamically update the build graph.
  11. Scanning Control
  12. ================
  13. Whether or not sources get scanned for C++ module usage is dependent on the
  14. following queries. The first query that provides a yes/no answer is used.
  15. - If the source file belongs to a file set of type ``CXX_MODULES``, it will
  16. be scanned.
  17. - If the target does not use at least C++ 20, it will not be scanned.
  18. - If the source file is not the language ``CXX``, it will not be scanned.
  19. - If the :prop_sf:`CXX_SCAN_FOR_MODULES` source file property is set, its
  20. value will be used.
  21. - If the :prop_tgt:`CXX_SCAN_FOR_MODULES` target property is set, its value
  22. will be used. Set the :variable:`CMAKE_CXX_SCAN_FOR_MODULES` variable
  23. to initialize this property on all targets as they are created.
  24. - Otherwise, the source file will be scanned. See policy :policy:`CMP0155`.
  25. Compiler Support
  26. ================
  27. Compilers which CMake natively supports module dependency scanning include:
  28. * MSVC toolset 14.34 and newer (provided with Visual Studio 17.4 and newer)
  29. * LLVM/Clang 16.0 and newer
  30. * GCC 14 (for the in-development branch, after 2023-09-20) and newer
  31. Generator Support
  32. =================
  33. The list of generators which support scanning sources for C++ modules include:
  34. - :generator:`Ninja`
  35. - :generator:`Ninja Multi-Config`
  36. - :generator:`Visual Studio 17 2022`
  37. Limitations
  38. -----------
  39. There are a number of known limitations of the current C++ module support in
  40. CMake. This does not document known limitations or bugs in compilers as these
  41. can change over time.
  42. For all generators:
  43. - Header units are not supported.
  44. - No builtin support for ``import std;`` or other compiler-provided modules.
  45. For the Ninja Generators:
  46. - ``ninja`` 1.11 or newer is required.
  47. For the :ref:`Visual Studio Generators`:
  48. - Only Visual Studio 2022 and MSVC toolsets 14.34 (Visual Studio
  49. 17.4) and newer.
  50. - No support for exporting or installing BMI or module information.
  51. - No support for compiling BMIs from ``IMPORTED`` targets with C++ modules.
  52. - No diagnosis of using modules provided by ``PRIVATE`` sources from
  53. ``PUBLIC`` module sources.