PDA

View Full Version : qmake+flex dependency problem



nurtsi
19th February 2008, 15:35
Hi,

I'm trying to use flex with qmake but I can't get the dependencies right. I want to keep the generated code in separate files. Here's a simple test to illustrate the problem:

main.cpp:


#include "parser.h"

int main(int argc, char ** argv)
{
argv++; argc--;

if(--argc > 0)
parserin = fopen(++argv[0], "r");
else parserin = stdin;

parserlex();

return 0;
}


parser.l:


%option noyywrap

%%

%%


And finally the makefile:


TEMPLATE = app

SOURCES += main.cpp

LEXSOURCES += parser.l

QMAKE_LEX = flex
QMAKE_LEXFLAGS = --header-file=parser.h

TARGET = ParserTest

LIBS += -lfl

CONFIG -= qt


The problem is that qmake tries to compile main.cpp first that depends on the generated parser.h (which doesn't exist). How can I tell qmake about this dependency? I tried defining custom compilers for flex, but the dependency problem is still there.

nurtsi
20th February 2008, 08:11
A simple solution seems to be building the flex stuff into a library and then linking that against a separate application so the order of compilation doesn't matter.

Though I'm still curious how to define the dependencies so that the application in the first post is built correctly.