cmake-cxxmodules.7.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 if the compiler and generator
  25. support scanning. See policy :policy:`CMP0155`.
  26. Compiler Support
  27. ================
  28. Compilers which CMake natively supports module dependency scanning include:
  29. * MSVC toolset 14.34 and newer (provided with Visual Studio 17.4 and newer)
  30. * LLVM/Clang 16.0 and newer
  31. * GCC 14 (for the in-development branch, after 2023-09-20) and newer
  32. Generator Support
  33. =================
  34. The list of generators which support scanning sources for C++ modules include:
  35. - :generator:`Ninja`
  36. - :generator:`Ninja Multi-Config`
  37. - :generator:`Visual Studio 17 2022`
  38. Limitations
  39. -----------
  40. There are a number of known limitations of the current C++ module support in
  41. CMake. This does not document known limitations or bugs in compilers as these
  42. can change over time.
  43. For all generators:
  44. - Header units are not supported.
  45. - No builtin support for ``import std;`` or other compiler-provided modules.
  46. For the Ninja Generators:
  47. - ``ninja`` 1.11 or newer is required.
  48. For the :ref:`Visual Studio Generators`:
  49. - Only Visual Studio 2022 and MSVC toolsets 14.34 (Visual Studio
  50. 17.4) and newer.
  51. - No support for exporting or installing BMI or module information.
  52. - No support for compiling BMIs from ``IMPORTED`` targets with C++ modules.
  53. - No diagnosis of using modules provided by ``PRIVATE`` sources from
  54. ``PUBLIC`` module sources.