直接使用CMAKE中对象库的输出

发布于 2025-02-13 14:32:29 字数 686 浏览 1 评论 0原文

我正在尝试使用CMAKE与Clang一起使用C ++ 20模块。我需要执行以下操作:

  • 首先,编译模块接口

  • 然后编译所有实现文件 - 将模块接口提供标志

  • 使用用于使用模块的标志

    ,再次将模块接口和生成的库提供。

问题发生在第一步。模块接口需要在其他所有内容之前进行编译,因此我的想法是创建一个对象库(因为否则CMake将“链接”它,这会破坏模块接口)。

然后,我需要对象文件列表(当然,这只是一个),但是这似乎只能使用发电机表达式,并且在为第2步添加编译器标志时,我无法使用发电机表达式

。是使用add_custom_commandadd_custom_target进行编译,但是您运行的风险不正确使用相同的编译标志(似乎似乎存在没有正确的方法来获取所有目标的编译标志)。

因此,总而言之,结构可能是这样的:

module -def.cpp(模块定义文件) - >模块 - def.pcm 模块-impl.cpp(实现文件) - > 我需要使用-fmodule-file =< dir>/module-def.pcm来编译模块 - impl.cpp

,但我找不到一个好方法由于我找不到可靠的方法来获得通往生成的PCM文件的路径。

I'm trying to work with c++20 modules with clang using CMake. I need to do the following:

  • first, compile the module interface

  • then compile all the implementation files - giving the module interface with a flag

  • for using the module, again give the module interface with a flag as well as the generated library.

The problem occurs during the first step. The module interface needs to be compiled before everything else, so my idea was to create an OBJECT library (because otherwise CMake will "link" it, which breaks the module interface).

I then need the list of object files (which will be only one, of course), but that seems to be only doable with a generator expression, and I cannot use generator expressions when adding the compiler flags for step 2.

Another idea I had was to compile using add_custom_command and add_custom_target, but then you run the risk of not properly using the same compile flags (there seems to be no proper way to get all the compile flags from a target).

So, to summarize, the structure might be like this:

module-def.cpp (module definition file) -> module-def.pcm
module-impl.cpp (implementation file) -> module-impl.o

I need to compile module-impl.cpp with a -fmodule-file=<dir>/module-def.pcm, but I cannot find a good way to do this, since I cannot find a reliable way to get the path to the generated pcm-file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文