gpt4 book ai didi

cmake - CMake 中生成的依赖文件

转载 作者:行者123 更新时间:2023-12-05 07:41:47 30 4
gpt4 key购买 nike

我们有一些源代码处理工具,可以从多个“片段”生成原始汇编文件等内容。

当使用 make 中的这些工具时,我们可以通过让源处理工具发出“依赖文件”来确保最新的构建,就像 gcc 一样-MD 标志。

例如,假设我有一个汇编模板文件 Frob.asmtmpl,以及一个名为 asm_templater 的模板引擎,它的作用类似于增强的 C 预处理器。

我们运行 asm_templater -d Frob.asmtmpl 生成 Frob.sFrob.d。后者是一个 makefile 依赖片段,如下所示:

Frob.s: Frob.asmtmpl ThingIncludedByFrob.asmincl OtherThingIncluded.asmincl

在基于 makefile 的构建系统中,如果它存在,我们将 include(Frob.d) 告诉 make Frob.asmtmpl 的实际 deps 是。

我们如何为 CMake 做类似的事情?似乎 CMake 的两次通过性质(生成然后构建),以及需要支持多生成引擎导致的结论是必须有某种我还没有弄清楚的 native CMake 方法来做到这一点。

我需要以某种方式向 CMake 表明 Frob.s 之间存在依赖关系。和ThingIncludedByFrob.asmincl,但这都是由Frob.asmtmpl的内容决定的,所以需要通过工具来提取。

最佳答案

您可能对 CMake 的 add_custom_command 感兴趣/正在寻找命令。它有两个签名:

The first signature is for adding a custom command to produce an output. A target created in the same directory (CMakeLists.txt file) that specifies any output of the custom command as a source file is given a rule to generate the file using the command at build time.

The second signature adds a custom command to a target such as a library or executable. This is useful for performing an operation before or after building the target. The command becomes part of the target and will only execute when the target itself is built. If the target is already built, the command will not execute.

因此,您可以创建一个自定义命令,将 COMMAND asm_templater -d Frob.asmtmplOUTPUTSBYPRODUCTS 设置为 Frob .s取决于 ThingIncludedByFrob.asmincl OtherThingIncluded.asmincl

我知道这种简单的方法可能仍然涉及在 CMakeLists.txt 文件中维护依赖项。我只是觉得提这个比不提要好。我不知道 CMake 级别的 depfile 处理。 add_custom_command 的使用可以构成更复杂设置的基础,通过解析 dep 文件生成自定义命令。

关于cmake - CMake 中生成的依赖文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45169207/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com