How to use c++20 modules with CMake?(如何在 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.
这篇关于如何在 CMake 中使用 c++20 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 CMake 中使用 c++20 模块?
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01