Writing projects with C++20 Module support
This book mainly discusses CMake 3.26, but it's worth noting that CMake frequently updates, and version 3.28 was released just before this chapter went to press. If you're using this version or newer, you can access the latest features by setting the cmake_minimum_required()
command to VERSION 3.28.0
.
On the other hand, if you need to stick with an older version or want to cater to a broader audience who might not have upgraded, you'll need to enable experimental support to use C++20 modules in CMake.
Let's explore how to do that.
Enabling the experimental support in CMake 3.26 and up
Experimental support represents a form of agreement: you, as the developer, acknowledge that this feature is not yet production-ready and should be used solely for testing purposes. To "sign" such an agreement, you'll need to set the CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API
variable in the project’s listfile to a specific...