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

发布于 2024-10-08 19:05:43 字数 1635 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坚持沉默 2024-10-15 19:05:43
  1. 据我所知,QMake 已经附带了 lex/yacc 集成,它在所有平台上使用 flex。因此对于 Flex,只需说:

    <前><代码>CONFIG += lex
    LEXSOURCES += src/cmpl/CMPL_Scanner.l

  2. QMake确实不支持开箱即用的bison。但鉴于 yacc 和 bison 基本相同,我会尝试如下操作:

    QMAKE_YACC=野牛
    # 也许调整一些其他 QMAKE_YACC* 变量
    配置+=yacc    
    YACCSOURCES += src/cmpl/CMPL_Parser.yy
    
  3. 此外,如果您遇到编译作业在 bison 作业完成之前运行的问题(似乎是 qmake 错误) ),您应该使用此解决方法:

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

    这将强制每个 QMAKE_EXTRA_COMPILERS 的输出成为(主)目标的依赖项,从而有效地确保生成的文件在编译开始之前可用。

  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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文