我需要 CMAKE 宏的语法,该宏从 lex/yacc 等工具生成 .cc 和 .h 文件。
有人可以告诉我以下人为示例的语法:
假设我有一个文件 y.cc 依赖于 x.cc 和 xh,提到的两个文件是由工具 z_tool 从文件 xz 生成的,其语法是什么?
对于这个例子,假设 y.cc 将变成一个静态库,并且由于我对 CMAKE 很陌生,这个人为示例的完整 CMakellist.txt 将非常有帮助。我正在寻找一个便携式解决方案,因为我的工具am using 可在 Windows 和 UNIX 变体上使用。
I require the syntax of a CMAKE macro that generates .cc and .h files from a tool like lex/yacc.
Could someone please show me the syntax for the following contrived example:
say I have a file y.cc that depends on x.cc and x.h, the two files mentioned are generated by tool z_tool from file x.z. What would the syntax for this be ?
For this example assume that y.cc will be turned into a static library, and as I am quite new to CMAKE the full CMakellist.txt for this contrived example would be very helpful.I'm looking for a portable solution as the tools I am using are available on windows as well as UNIX variants.
发布评论
评论(3)
这里不是给你一个人为示例的答案,而是使用 flex 生成可执行文件的方法和 bison
Bison/flex 的 CMake 查找包包含在默认安装中,因此这是跨平台的。
一般来说,要创建稍后用作输入的输出,您可以使用 add_custom_command 函数。如果您使用自定义命令的输出作为库或可执行文件的输入,则 CMake 知道在编译库/可执行目标的源之前运行您的自定义命令。
Rather than give you the answer to a contrived example, here is the way you would generate an executable using flex and bison
The CMake find packages for bison/flex are included in the default installation, so this is cross platform.
In general to create an output that will later be used as an input you can use the add_custom_command function. If you use an output from the custom command as an input to a library or executable, then CMake knows to run your custom command before compiling the sources for the library/executable target.
以下行有错字
BIANRY 应拼写为 BINARY。
注意:CMake 文档也有此拼写错误。 (在 2.8.0 中,此问题已在 2.8.10 文档中修复)..
The following line has Typo
BIANRY should be spelled as BINARY.
Note: CMake Documentation has this typo there as well. ( in 2.8.0, this is fixed in 2.8.10 documentation)..
/* 让它在我的 Mac 上运行 Lion。我将文件名更改为 y.tab.c 和 lex.yy.c,这是从命令行运行 lex lex.l 和 yacc -D yacc.y 时的输出文件。见下文。
*/
/* To make it work on my Mac with Lion. I changed the files names to y.tab.c and lex.yy.c, which are the output files if you run lex lex.l and yacc -D yacc.y from command line. See below.
*/