CMake:如何先执行add_custom_command [英] CMake: How to run a add_custom_command before everything else
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文