QMAKE_EXTRA_COMPILERS - 头文件之间的依赖关系问题
我正在使用 flex 和 bison 创建一个 Qt 项目。头文件_CMPL_Parser.hh
(由bison生成)和头文件compile.hh
(#include _CMPL_Parser.hh)。
我使用 QMAKE_EXTRA_COMPILERS 来将 flex 和 bison 包含在我的项目中(请参阅下面的项目文件部分)。不幸的是,_CMPL_Parser.hh
是在编译器需要此文件将其包含在 compiler.hh -> compiler.cc
中之后创建的。
...
FLEX_SOURCES = src/cmpl/CMPL_Scanner.l
BISON_SOURCES = src/cmpl/CMPL_Parser.yy
flex.commands=flex -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
flex.output= $$OUT_PWD/_CMPL_Scanner.cc
flex.input=FLEX_SOURCES
flex.variable_out=SOURCES
flex.name=flex ${QMAKE_FILE_IN}
QMAKE_EXTRA_COMPILERS+=flex
bisonsource.commands=bison -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
bisonsource.output= $$OUT_PWD/_CMPL_Parser.cc
bisonsource.input=BISON_SOURCES
bisonsource.variable_out=SOURCES
bisonsource.name=bisonsource ${QMAKE_FILE_IN}
QMAKE_EXTRA_COMPILERS+=bisonsource
bisonheader.commands=@true
bisonheader.output= $$OUT_PWD/_CMPL_Parser.hh
bisonheader.input=BISON_SOURCES
bisonheader.variable_out=HEADERS
bisonheader.name=bisonheader ${QMAKE_FILE_IN}
#bisonheader.depends= bin/_CMPL_Parser.cc
QMAKE_EXTRA_COMPILERS+=bisonheader
...
HEADERS += src/cmpl/Compiler.hh \
src/cmpl/FileIO.hh \
...
SOURCES += src/cmpl/Compiler.cc \
src/cmpl/FileIO.cc \
...
我还尝试在我的项目文件中定义以下依赖项。但它也失败了。
chh.input = src/cmpl/Compiler.hh
chh.depends = $$OUT_PWD/_CMPL_Parser.hh
chh.name = chh
chh.dependency_type = TYPE_C
chh.variable_out = HEADERS
QMAKE_EXTRA_COMPILERS += chh
如何表达 _CMPL_Parser.hh
在被其他文件使用之前被创建?
谢谢。
I am creating a Qt project using flex and bison. There is a dependency between the header file _CMPL_Parser.hh
(generated by bison) and the header file compile.hh
(#include _CMPL_Parser.hh
).
I use QMAKE_EXTRA_COMPILERS
to include flex and bison in my project (see the part of my project file below). Unfortunately, _CMPL_Parser.hh
is created after the compiler needs this file to include it in compiler.hh -> compiler.cc
.
...
FLEX_SOURCES = src/cmpl/CMPL_Scanner.l
BISON_SOURCES = src/cmpl/CMPL_Parser.yy
flex.commands=flex -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
flex.output= $OUT_PWD/_CMPL_Scanner.cc
flex.input=FLEX_SOURCES
flex.variable_out=SOURCES
flex.name=flex ${QMAKE_FILE_IN}
QMAKE_EXTRA_COMPILERS+=flex
bisonsource.commands=bison -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
bisonsource.output= $OUT_PWD/_CMPL_Parser.cc
bisonsource.input=BISON_SOURCES
bisonsource.variable_out=SOURCES
bisonsource.name=bisonsource ${QMAKE_FILE_IN}
QMAKE_EXTRA_COMPILERS+=bisonsource
bisonheader.commands=@true
bisonheader.output= $OUT_PWD/_CMPL_Parser.hh
bisonheader.input=BISON_SOURCES
bisonheader.variable_out=HEADERS
bisonheader.name=bisonheader ${QMAKE_FILE_IN}
#bisonheader.depends= bin/_CMPL_Parser.cc
QMAKE_EXTRA_COMPILERS+=bisonheader
...
HEADERS += src/cmpl/Compiler.hh \
src/cmpl/FileIO.hh \
...
SOURCES += src/cmpl/Compiler.cc \
src/cmpl/FileIO.cc \
...
I also tried to define the following dependencies in my project file. But it failed, too.
chh.input = src/cmpl/Compiler.hh
chh.depends = $OUT_PWD/_CMPL_Parser.hh
chh.name = chh
chh.dependency_type = TYPE_C
chh.variable_out = HEADERS
QMAKE_EXTRA_COMPILERS += chh
How is it possible to express that _CMPL_Parser.hh
is to be created before it is be used by other files?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,QMake 已经附带了 lex/yacc 集成,它在所有平台上使用 flex。因此对于 Flex,只需说:
<前><代码>CONFIG += lex
LEXSOURCES += src/cmpl/CMPL_Scanner.l
QMake确实不支持开箱即用的bison。但鉴于 yacc 和 bison 基本相同,我会尝试如下操作:
此外,如果您遇到编译作业在 bison 作业完成之前运行的问题(似乎是 qmake 错误) ),您应该使用此解决方法:
这将强制每个 QMAKE_EXTRA_COMPILERS 的输出成为(主)目标的依赖项,从而有效地确保生成的文件在编译开始之前可用。
QMake already comes with a lex/yacc integration that uses flex on all platforms, as far as I can see. So for flex, just say:
QMake indeed doesn't support bison out of the box. But seeing as yacc and bison are basically the same, I'd try something like the following:
In addition, if you run into problems where the compile job is running before the bison job has finished (a qmake bug, it seems), you should use this workaround:
This will force the outputs of each of these QMAKE_EXTRA_COMPILERS to be a dependency of the (main) target, effectively ensuring that the generated files are available before compilation starts.