cmake add_custom_command 已经过时了
我遇到的问题是 add_custom_command 总是过时,因此在每个构建上运行。自定义命令运行作为同一项目目标的工具来生成由另一个目标使用的文件:
add_executable(GeneratorTool main.cpp)
add_custom_command(
OUTPUT generated.h
COMMAND GeneratorTool
DEPENDS main.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "** GeneratorTool **"
)
add_library(MyLib STATIC generated.h ...)
在构建输出(Visual Studio 2010)中,我总是看到 ** GeneratorTool **。我希望一旦 generated.h 存在并且比 main.cpp 新,它就不会再次构建。 有什么想法吗?
谢谢, 约亨
I have the problem that add_custom_command is always out of date and therefore runs on every build. the custom command runs a tool that is a target of the same project to generate a file that is used by another target:
add_executable(GeneratorTool main.cpp)
add_custom_command(
OUTPUT generated.h
COMMAND GeneratorTool
DEPENDS main.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "** GeneratorTool **"
)
add_library(MyLib STATIC generated.h ...)
In the build output (visual studio 2010) I always see ** GeneratorTool **. I would expect that it does not build again once generated.h exists and is newer than main.cpp.
Any ideas?
Thanks,
Jochen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您可以将
DEPENDS
放在add_custom_command
中的 GeneratorTool 上,而不是main.cpp
。GeneratorTool
已经依赖于main.cpp
。那么很可能是
generate.h
的位置不明确,从而强制重建 generated.h。确保 MyLib 在正确的位置查找
generate.h
。我的盲目猜测是尝试:
First of all, you can put
DEPENDS
on GeneratorTool in youradd_custom_command
instead ofmain.cpp
.GeneratorTool
already dependsmain.cpp
.Then most likely it is the location of
generated.h
which is ambiguous which forces the rebuilt of generated.h.Make sure that MyLib looks for the
generated.h
in the right place.My blind guess is to try:
另一件事可能是 - 确保命令正在生成所有
OUTPUT
文件。如果您的生成器无法生成其中之一,它每次都会运行(这是我的问题)。Another thing it could be - make sure the command is generating all
OUTPUT
files. If you generator is failing to generate even one of them, it will run every time (this was my problem).