QMAKE_EXTRA_COMPILERS - 处理头文件之间依赖关系的问题

3
我正在使用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>文件需要在其他文件使用之前创建?
谢谢。

你是否找到了在 chh.depends 结尾应该放什么的解决方案? - CodingFrog
1个回答

2
  1. 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:

    CONFIG += lex
    LEXSOURCES += src/cmpl/CMPL_Scanner.l
    
  2. 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:

    QMAKE_YACC=bison
    # maybe adjust some other QMAKE_YACC* variables
    CONFIG += yacc    
    YACCSOURCES += src/cmpl/CMPL_Parser.yy
    
  3. 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:

    lex.CONFIG += target_predeps
    yacc_impl.CONFIG += target_predeps
    yacc_decl.CONFIG += target_predeps
    

    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.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接