英文:
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 <BUILD_DIR> --target <TARGETNAME>
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 <BUILD_DIR> --target <TARGETNAME> -- --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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论