如何在 CMake 中使用 c++20 模块?
Clang 和 MSVC 已经支持 Modules TS 来自未完成的 C++20 标准.我可以使用 CMake 或其他构建系统构建基于模块的项目吗?
Clang and MSVC already supports Modules TS from unfinished C++20 standard. Can I build my modules based project with CMake or other build system and how?
我尝试了 build2,它支持模块并且运行良好,但我有一个 问题 关于它的依赖管理(UPD:问题已关闭).
I tried build2, it supports modules and it works very well, but i have a question about it's dependency management (UPD: question is closed).
推荐答案
CMake 目前不支持 C++20 模块.
CMake currently does not support C++20 modules.
另请参阅CMake 问题跟踪器中的相关问题.请注意,与插入新的编译器选项相比,支持模块需要来自构建系统的更多支持.它从根本上改变了在构建过程中必须如何处理源文件之间的依赖关系:在预模块世界中,所有 cpp 源文件都可以按任何顺序独立构建.使用不再正确的模块,这不仅对 CMake 本身有影响,而且对下游构建系统也有影响.
See also the relevant issue in the CMake issue tracker. Note that supporting modules requires far more support from the build system than inserting a new compiler option. It fundamentally changes how dependencies between source files have to be handled during the build: In a pre-modules world all cpp source files can be built independently in any order. With modules that is no longer true, which has implications not only for CMake itself, but also for the downstream build system.
查看 CMake Fortran 模块论文细节.从构建系统的角度来看,Fortran 模块的行为与 C++20 模块非常相似.
Take a look at the CMake Fortran modules paper for the gory details. From a build system's point of view, Fortran's modules behave very similar to the C++20 modules.
更新:CMake 3.20 引入了对带有 Ninja Generator 的模块的实验性支持(并且仅用于 Ninja).详细信息可以在相应的拉取请求中找到.在此阶段,此功能仍处于高度实验阶段,不 用于生产用途.如果你打算玩这个,你真的应该阅读 Fortran 模块论文和依赖格式论文 以了解您正在了解的内容.
Update: CMake 3.20 introduces experimental support for Modules with the Ninja Generator (and only for Ninja). Details can be found in the respective pull request. At this stage, this feature is still highly experimental and not intended for production use. If you intend to play around with this anyway, you really should be reading both the Fortran modules paper and the dependency format paper to understand what you're getting into.
相关文章