[Qt-interest] How to add support for re2c in qmake project file

Rui Maciel rui.maciel at gmail.com
Tue Sep 6 22:06:39 CEST 2011


A while ago I felt the felt the need to incorporate lexers generated by 
re2c[1] in a qmake project.  To help those who may be in a similar situation 
in the future, or at least to save them bit of time digging through the 
manual, here is what I came up:


Let's consider that the parser is located in ./parsers/, and is composed of 
the following files:
MyParser.h++
MyParser.c++.re2c

The re2c routine works in a similar way than Flex[2], which means that it 
generates a lexer from instructions specified in a source file.  In this 
case, the lexer is entirely defined in MyParser.c++.re2c, which is used to 
generate a source file, named MyParser.c++, with the class implementation.  
Through the command line, this is achieved through the following command:

$ re2c -o parsers/MyParser.c++ parsers/MyParser.c++.re2c


To be able to set a Makefile that handles this, we need to perform the 
following tasks:

1) add MyParser{h,c}++ to the HEADER and SOURCES list.
2) define a new Makefile target in the qmake project file
3) add the newly created target to the QMAKE_EXTRA_TARGETS list


Step 1) should be obvious to anyone who maintains a qmake project file.  
Step 2) is achieved by defining a new object which must have the following 
members: target, commands, depends and output.  As an example, here is a 
definition of a new object called MyParserRe2c:

MyParserRe2c.target = parsers/MyParser.c++
MyParserRe2c.commands = re2c -o parsers/MyParser.c++ 
parsers/MyParser.c++.re2c
MyParserRe2c.depends = parsers/MyParser.c++.re2c
MyParserRe2c.output = parsers/MyParser.c++

Step 3) Just add the newly created object to QMAKE_EXTRA_TARGETS.  For 
example:

QMAKE_EXTRA_TARGETS += MyParserRe2c

Now, whenever parsers/MyParser.c++.re2c is changed, Makefile takes care of 
rebuilding MyParser.c++ and the subsequent dependencies.


Hope this helps,
Rui Maciel


[1] http://re2c.org/
[2] http://flex.sourceforge.net/
[3] http://doc.qt.nokia.com/latest/qmake-environment-
reference.html#customizing



More information about the Qt-interest-old mailing list