| .\ |
| . |
| . |
| .nr rst2man-indent-level 0 |
| . |
| .de1 rstReportMargin |
| \\$1 \\n[an-margin] |
| level \\n[rst2man-indent-level] |
| level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] |
| - |
| \\n[rst2man-indent0] |
| \\n[rst2man-indent1] |
| \\n[rst2man-indent2] |
| .. |
| .de1 INDENT |
| .\ |
| . RS \\$1 |
| . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] |
| . nr rst2man-indent-level +1 |
| .\ |
| .. |
| .de UNINDENT |
| . RE |
| .\ |
| .\ |
| .nr rst2man-indent-level -1 |
| .\ |
| .in \\n[rst2man-indent\\n[rst2man-indent-level]]u |
| .. |
| .TH "CMAKE-CXXMODULES" "7" "Jan 23, 2025" "3.31.5" "CMake" |
| .SH NAME |
| cmake-cxxmodules \- CMake C++ Modules Support Reference |
| .sp |
| Added in version 3.28. |
|
|
| .sp |
| C++ 20 introduced the concept of \(dqmodules\(dq to the language. The design |
| requires build systems to order compilations among each other to satisfy |
| \fBimport\fP statements reliably. CMake\(aqs implementation asks the compiler |
| to scan source files for module dependencies during the build, collates |
| scanning results to infer ordering constraints, and tells the build tool |
| how to dynamically update the build graph. |
| .SH COMPILATION STRATEGY |
| .sp |
| With C++ modules, compiling a set of C++ sources is no longer embarrassingly |
| parallel. That is, any given source may first require the compilation of |
| another source file first in order to provide a \(dqCMI\(dq (compiled module |
| interface) or \(dqBMI\(dq (binary module interface) that C++ compilers use to |
| satisfy \fBimport\fP statements in other sources. With headers, sources could |
| share their declarations so that any consumers could compile independently. |
| With modules, declarations are now generated into these BMI files by the |
| compiler during compilation based on the contents of the source file and its |
| \fBexport\fP statements. |
| .sp |
| The order necessary for compilation requires build\-time resolution of the |
| ordering because the order is controlled by the contents of the sources. This |
| means that the ordering needs extracted from the source during the build to |
| avoid regenerating the build graph via a configure and generate phase for |
| every source change to get a correct build. |
| .sp |
| The general strategy is to use a \(dqscanner\(dq to extract the ordering dependency |
| information and update the build graph with new edges between existing edges |
| by taking the per\-source scan results (represented by \X'tty: link https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1689r5.html'\fI\%P1689R5\fP\X'tty: link' files) and |
| \(dqcollating\(dq the dependencies within a target and to modules produced by |
| targets visible to the target. The primary task is to generate \(dqmodule map\(dq |
| files to pass to each compile rule with the paths to the BMIs needed to |
| satisfy \fBimport\fP statements. The collator also has tasks to use the |
| build\-time information to fill out information including \fBinstall\fP rules for |
| the module interface units, their BMIs, and properties for any exported |
| targets with C++ modules. |
| .sp |
| \fBNOTE:\fP |
| .INDENT 0.0 |
| .INDENT 3.5 |
| CMake is focusing on correct builds before looking at performance |
| improvements. There are known tactics within the chosen strategy which may |
| offer build performance improvements. However, they are being deferred |
| until we have a working model against which to compare them. It is also |
| important to note that a tactic useful in one situation (e.g., clean |
| builds) may not be performant in a different situation (e.g., incremental |
| builds). Finding a balance and offering controls to select the tactics is |
| future work. |
| .UNINDENT |
| .UNINDENT |
| .SH SCANNING CONTROL |
| .sp |
| Whether or not sources get scanned for C++ module usage is dependent on the |
| following queries. The first query that provides a yes/no answer is used. |
| .INDENT 0.0 |
| .IP \(bu 2 |
| If the source file belongs to a file set of type \fBCXX_MODULES\fP, it will |
| be scanned. |
| .IP \(bu 2 |
| If the target does not use at least C++ 20, it will not be scanned. |
| .IP \(bu 2 |
| If the source file is not the language \fBCXX\fP, it will not be scanned. |
| .IP \(bu 2 |
| If the \X'tty: link #prop_sf:CXX_SCAN_FOR_MODULES'\fI\%CXX_SCAN_FOR_MODULES\fP\X'tty: link' source file property is set, its |
| value will be used. |
| .IP \(bu 2 |
| If the \X'tty: link #prop_tgt:CXX_SCAN_FOR_MODULES'\fI\%CXX_SCAN_FOR_MODULES\fP\X'tty: link' target property is set, its value |
| will be used. Set the \X'tty: link #variable:CMAKE_CXX_SCAN_FOR_MODULES'\fI\%CMAKE_CXX_SCAN_FOR_MODULES\fP\X'tty: link' variable |
| to initialize this property on all targets as they are created. |
| .IP \(bu 2 |
| Otherwise, the source file will be scanned if the compiler and generator |
| support scanning. See policy \X'tty: link #policy:CMP0155'\fI\%CMP0155\fP\X'tty: link'\&. |
| .UNINDENT |
| .sp |
| Note that any scanned source will be excluded from any unity build (see |
| \X'tty: link #prop_tgt:UNITY_BUILD'\fI\%UNITY_BUILD\fP\X'tty: link') because module\-related statements can only happen at |
| one place within a C++ translation unit. |
| .SH COMPILER SUPPORT |
| .sp |
| Compilers which CMake natively supports module dependency scanning include: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| MSVC toolset 14.34 and newer (provided with Visual Studio 17.4 and newer) |
| .IP \(bu 2 |
| LLVM/Clang 16.0 and newer |
| .IP \(bu 2 |
| GCC 14 (for the in\-development branch, after 2023\-09\-20) and newer |
| .UNINDENT |
| .SH IMPORT STD SUPPORT |
| .sp |
| Support for \fBimport std\fP is limited to the following toolchain and standard |
| library combinations: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| Clang 18.1.2 and newer with \fB\-stdlib=libc++\fP |
| .IP \(bu 2 |
| MSVC toolset 14.36 and newer (provided with Visual Studio 17.6 Preview 2 and |
| newer) |
| .UNINDENT |
| .sp |
| The \X'tty: link #variable:CMAKE_CXX_COMPILER_IMPORT_STD'\fI\%CMAKE_CXX_COMPILER_IMPORT_STD\fP\X'tty: link' variable may be used to detect |
| support for a standard level with the active C++ toolchain. |
| .sp |
| \fBNOTE:\fP |
| .INDENT 0.0 |
| .INDENT 3.5 |
| This support is provided only when experimental support for |
| \fBimport std;\fP has been enabled by the |
| \fBCMAKE_EXPERIMENTAL_CXX_IMPORT_STD\fP gate. |
| .UNINDENT |
| .UNINDENT |
| .SH GENERATOR SUPPORT |
| .sp |
| The list of generators which support scanning sources for C++ modules include: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| \X'tty: link #generator:Ninja'\fI\%Ninja\fP\X'tty: link' |
| .IP \(bu 2 |
| \X'tty: link #generator:Ninja Multi-Config'\fI\%Ninja Multi\-Config\fP\X'tty: link' |
| .IP \(bu 2 |
| \X'tty: link #generator:Visual Studio 17 2022'\fI\%Visual Studio 17 2022\fP\X'tty: link' |
| .UNINDENT |
| .SS Limitations |
| .sp |
| There are a number of known limitations of the current C++ module support in |
| CMake. This does not document known limitations or bugs in compilers as these |
| can change over time. |
| .sp |
| For all generators: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| Header units are not supported. |
| .IP \(bu 2 |
| No builtin support for \fBimport std;\fP or other compiler\-provided modules. |
| .UNINDENT |
| .sp |
| For the Ninja Generators: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| \fBninja\fP 1.11 or newer is required. |
| .UNINDENT |
| .sp |
| For the \X'tty: link #visual-studio-generators'\fI\%Visual Studio Generators\fP\X'tty: link': |
| .INDENT 0.0 |
| .IP \(bu 2 |
| Only Visual Studio 2022 and MSVC toolsets 14.34 (Visual Studio |
| 17.4) and newer. |
| .IP \(bu 2 |
| No support for exporting or installing BMI or module information. |
| .IP \(bu 2 |
| No support for compiling BMIs from \fBIMPORTED\fP targets with C++ modules |
| (including \fBimport std\fP). |
| .IP \(bu 2 |
| No diagnosis of using modules provided by \fBPRIVATE\fP sources from |
| \fBPUBLIC\fP module sources. |
| .UNINDENT |
| .SH COPYRIGHT |
| 2000-2024 Kitware, Inc. and Contributors |
| .\ |
| . |
|
|