A package's library can consist of, or include, C++20 module interface units:
src/geom.cppm export module geom;
src/detail/shapes.ixx also .mpp, .cxxm and .c++m
import geom;
int main() { return geom::area(6, 7); }
- Module units in src/ (any depth) belong to the package's library. cx publishes them through the library's CXX_MODULES file set, so dependents import them without any configuration.
- Mixing: headers, sources and modules can be mixed in one package.
- Requirements:
- package.standard = 20 or newer
- CMake 3.28 or newer
- a compiler with module support: Clang 17+, GCC 14+ or MSVC 17.4+. AppleClang can't build them. Clang also needs clang-scan-deps (on Debian and Ubuntu, the clang-tools-<version> package). Without these, the configure step fails with a message that says so.
- the Ninja generator (or Visual Studio). cx uses Ninja when it's in PATH at the first configure. A module package in a build directory that uses Make fails with a message saying to install Ninja and run cx clean.
- Projects without modules are unaffected: the generated CMake only requires CMake 3.28 when a package has module units.
- The artifact cache never stores packages with modules, because module interfaces are compiled by each consumer.
- cx install --lib installs the module units with the library.
import std
[package]
standard = 23
import-std = true
import std; needs CMake 3.30 or newer and a compiler and standard library that provide the std module. cx sets CMAKE_CXX_MODULE_STD and checks that the toolchain supports it, with a clear error if not.
As of CMake 4.2, import std is still experimental in CMake: it only works when CMake's CMAKE_EXPERIMENTAL_CXX_IMPORT_STD gate is set to a UUID that changes with every CMake release. cx doesn't guess it. If you want to use the experimental support, set CX_CMAKE_IMPORT_STD_GATE to the value for your CMake version (from CMake's Help/dev/experimental.rst), and cx passes it on.
Header units (import <vector>;) aren't supported.