如何在 CMake 中使用 c++20 模块? [英] How to use c++20 modules with CMake?

查看:48
本文介绍了如何在 CMake 中使用 c++20 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ClangMSVC 已经支持 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.

这篇关于如何在 CMake 中使用 c++20 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆