如何检查 CMake 目标是否是最新的而无需构建?

huangapple go评论102阅读模式
英文:

How to check if a CMake target is up-to-date without building it?

问题

你怎么检查CMake目标是否是最新的,从命令行而不实际构建它?目标是“最新的”如果cmake --build <BUILD_DIR> --target <TARGETNAME>不会执行任何构建步骤。在我这里,CMake使用的底层构建系统是make,虽然一个通用的解决方案会更好。

英文:

How can I check if a CMake target is up-to-date, from the command-line, without actually building it? A target is "up-to-date" if cmake --build &lt;BUILD_DIR&gt; --target &lt;TARGETNAME&gt; would not actually execute any build steps.

In my case, the underlying build system used by CMake is make, although a generic solution would be better.

答案1

得分: 1

无需翻译的部分:There does not appear to be an option to do this with "pure" or generic CMake.

翻译部分:
然而,当底层构建系统为make时,可以通过在cmake调用的--后传递选项来完成此操作(详细信息请参阅这里):

--

将剩余的选项传递给本地工具。

make的情况下,--question选项回答了这个问题:

“Question”。悄悄地检查目标是否是最新的,但不执行配方;退出代码显示是否需要进行任何更新。

因此,总体的CMake调用是:

cmake --build <BUILD_DIR> --target <TARGETNAME> -- --question
英文:

There does not appear to be an option to do this with "pure" or generic CMake.

However, when the underlying build system is make, this can be accomplished by passing an option to make after -- on the cmake invocation:
> --
>
> Pass remaining options to the native tool.

In this case of make, the --question option answers this question:

> “Question”. Silently check whether the targets are up to date, but do not execute recipes; the exit code shows whether any updates are needed.

So overall the CMake invocation is:

cmake --build &lt;BUILD_DIR&gt; --target &lt;TARGETNAME&gt; -- --question

答案2

得分: 1

在我的情况下,CMake 使用的底层构建系统是 make,尽管通用的解决方案会更好。

正如已经回答的,CMake 无法做到这一点。

许多 CMake 初学者不理解的一点是:CMake 不是构建系统,而是构建系统的生成器。它本身不构建任何东西。它将这个任务委托给底层(生成的)构建系统,并且无法“访问”它的状态。因此,它不“知道”哪个目标是最新的,哪个不是。

英文:

> In my case, the underlying build system used by CMake is make, although a generic solution would be better.

As it was answered, CMake can't do that.

One thing many CMake beginners do not understand: CMake is not a build system but a generator of build systems. It doesn't build anything by itself. It delegates this job to the underlaid (generated) build system and has no "access" to its state. Hence, does't "know" what target is up to date and what isn't.

huangapple
  • 本文由 发表于 2023年3月31日 03:51:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定