Skip to content

mohitmishra786/low-level-dev-skills / skills/compilers/cpp-modules

cpp-modules

Verified

C++20 modules skill for modern C++ projects. Use when working with named modules, module partitions, header units, CMake MODULE_SOURCES, Clang -fmodules-ts, BMI caching issues, or migrating from headers to modules. Activates on queries about C++20 modules, import statements, module interface units, header units, or BMI files.

FileKindSize
SKILL.mdskill md6.2 KB
references/modules-cmake-support.mdmarkdown2.4 KB

references/modules-cmake-support.md

View on GitHub
# C++20 Modules CMake Support Reference

Source: https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html

## Table of Contents

1. [Version Requirements](#version-requirements)
2. [FILE_SET CXX_MODULES](#file_set-cxx_modules)
3. [Generator Support](#generator-support)
4. [Compiler Support Matrix](#compiler-support-matrix)

## Version Requirements

| Feature | Minimum CMake |
|---------|---------------|
| Stable `CXX_MODULES` FILE_SET | 3.28 |
| Experimental modules (Ninja) | 3.25 |
| `import std;` support | 3.30 (with MSVC STL) |

## FILE_SET CXX_MODULES

```cmake
add_library(mylib)
target_sources(mylib
    PUBLIC
        FILE_SET CXX_MODULES FILES
            include/mylib.cppm        # module interface
            include/mylib-utils.cppm  # partition
    PRIVATE
        src/mylib-impl.cpp            # implementation unit (module; not export module)
)

# Install module interface units alongside the library
install(TARGETS mylib
    ARCHIVE DESTINATION lib
    FILE_SET CXX_MODULES DESTINATION include/mylib
)
```

## Generator Support

| Generator | Module Support | Notes |
|-----------|---------------|-------|
| Ninja ≥1.11 | Full | Best support; use for development |
| Ninja Multi-Config | Full | CMake ≥3.28 |
| MSBuild (VS 2022) | Full | MSVC modules work well |
| Make | None | Does not support dynamic deps |
| Xcode | Partial | Experimental |

Always use Ninja for module builds during development:

```bash
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20
```

## Compiler Support Matrix

| Compiler | Status | Notes |
|----------|--------|-------|
| MSVC 19.34+ (VS 2022 17.4+) | Best | `import std;` supported |
| Clang ≥16 | Good | Use `--precompile` pipeline |
| Clang ≥18 | Better | stdlib module support |
| GCC ≥14 | Improving | `-fmodules-ts` more stable |
| GCC 11–13 | Experimental | Many edge cases |

### MSVC-specific

```cmake
# Enable standard library modules with MSVC
target_compile_features(mylib PUBLIC cxx_std_23)
# In C++23: import std; // works with MSVC and CMake 3.30+
```

### Clang-specific flags

```cmake
# Force Clang to use module compilation mode
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    target_compile_options(mylib PRIVATE -fmodules)
endif()
```

### GCC-specific

```cmake
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    target_compile_options(mylib PRIVATE -fmodules-ts)
    # GCC stores BMI in gcm.cache/ relative to build dir
endif()
```
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 468kUpdated Claude CodeCodexUnverifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 319kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 319kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 319kUpdated Claude CodeCodexVerifiedInstall