Provides the add_module_library CMake function that is a wrapper around add_library with additional module-specific rules.
This module currently supports:
- Clang 15+
- GCC 11+
- MSVC 19.28+
This module can also fallback to a non-modular library for compatibility.
Projects using add_module_library:
- {fmt}: a modern formatting library
hello.cc:
module;
#include<cstdio>exportmodule hello;
exportvoidhello() { std::printf("Hello, modules!\n"); }main.cc:
import hello;
intmain() { hello(); }CMakeLists.txt:
cmake_minimum_required(VERSION3.11)
project(HELLO CXX)
include(modules.cmake)
add_module_library(hellohello.cc)
add_executable(mainmain.cc)
target_link_libraries(mainhello)Building with clang:
CXX=clang++ cmake .
make
Running:
$ ./main
Hello, modules!
The code is distributed under the permissive MIT license with an optional exception that allows distributing binary code without attribution.