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

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

问题描述

C语

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 ,它支持模块并且效果很好,但是我有一个

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天全站免登陆