本文介绍了CMake:如何在其他一切之前运行 add_custom_command的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义命令
add_custom_command(
OUTPUT config.h
PRE_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_config_h.py ${CMAKE_CURRENT_BINARY_DIR}/config.h
)
我正在尝试先运行它,然后生成 unix Makefile.
I'm trying to run it before everything else and I generate unix Makefiles.
然而 PRE_BUILD 仅支持 VS2010,这意味着 config.h
在链接之前构建.
However PRE_BUILD is only supported for VS2010 which means that config.h
is build before linking.
如何在 cmake 开始编译源代码之前创建自定义命令.
how do I make a custom command before cmake starts compiling sources.
推荐答案
你应该使用 add_custom_target
而不是 add_dependencies
让你的普通目标依赖它:
You should use add_custom_target
instead and add_dependencies
to make your normal target depend on it:
add_custom_target(
myCustomTarget
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_config_h.py ${CMAKE_CURRENT_BINARY_DIR}/config.h
)
add_dependencies(myTarget myCustomTarget)
这应该确保在编译 myTarget
的源代码之前运行该命令.
This should ensure that the command is run before compiling the sources of myTarget
.
这篇关于CMake:如何在其他一切之前运行 add_custom_command的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!