获取CMake的在项目执行的目标建立一个库之前 [英] Get CMake to execute a target in project before building a library
问题描述
我使用的CMake来构建我的C ++项目,它有多个可执行文件和库(同一项目的一部分)。所有工作正常,但我的可执行文件之一是code发生器,产生一些库类的。我已经得到了所有的代工作,但无法弄清楚如何调用该可执行文件(codeGEN)库建成之前。我在Linux环境。希望有人能回答这个问题。
I am using CMake to build my C++ project and it has multiple executables and a library (all part of same project). All is working fine, however one of my executables is a code generator that creates some of the library classes. I have got all the generation working but can't figure out how to call this executable (codegen) just before the library is built. I am on Linux environment. Hope someone can answer this.
推荐答案
在的CMakeLists.txt
:
首先,定义你的可执行文件:
First, define your executable:
add_executable(marks-code-generator gen.cpp)
然后,定义自定义命令生成源:
Then, define a custom command to generate the source:
add_custom_command(OUTPUT generated.cpp generated.hpp
COMMAND marks-code-generator ARGS args here maybe
MAIN_DEPENDENCY input-file.in
DEPENDS marks-code-generator
COMMENT here we go!
VERBATIM)
选项逐字
确保特定平台的转义正确。在注释
将被打印出来让执行时,给像 [66%]在这里,我们走!
。
The option VERBATIM
makes sure platform-specific escaping is done correctly. The COMMENT
will be printed out as make executes, giving something like [ 66%] here we go!
.
最后,命名源列表中生成的源代码为您实际的程序:
Finally, name your generated source in the source list for your real program:
add_executable(some-program generated.cpp generated.hpp non-generated.cpp foo.cpp)
这篇关于获取CMake的在项目执行的目标建立一个库之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!