PDA

View Full Version : Creating lint build targets


Micawber
15th April 2008, 15:56
Hello,

I am trying to include in my project file for qmake, support for extra build targets that will run lint on my source and create lint output that is tied to the source file name.

Snippet from my project file...


SOURCES += fileone.cpp \
filetwo.cpp \
filethree.cpp

INCLUDEPATH += /usr/include/somepath \
/home/user/somepath

MYSOURCES = SOURCES
for( name, $$MYSOURCES ) {
exists( $$name ) {
tmp_source = name
name ~= s/\.cpp//
lint_targets += $${name}.lint
sub.target = $${name}.lint
sub.commands = flint -os $${name}.lint -i $$INCLUDEPATH $${tmp_source}
QMAKE_EXTRA_TARGETS += sub
unset( sub )
}
}

linttarget.target = lint
linttarget.depends = $$lint_targets

QMAKE_EXTRA_TARGETS += linttarget


When I run qmake on it, it generates the following Makefile snippet...

filethree.lint:
flint -os filethree.lint -i /usr/include/somepath /home/usr/somepath name

filethree.lint:
flint -os filethree.lint -i /usr/include/somepath /home/usr/somepath name

filethree.lint:
flint -os filethree.lint -i /usr/include/somepath /home/usr/somepath name

lint: fileone.lint filetwo.lint filethree.lint



I think I just figured out the reason "name" is on the end of each of the commands for the lint targets.

I can't figure out why the QMAKE_EXTRA_TARGETS doesn't generate the expected targets with the proper command line.

Any help would be appreciated.

Oh, BTW, I using Qt 4.3.1 on Linux

-Mic

Micawber
15th April 2008, 22:44
Reply to my own thread!

I solved my problem by using QMAKE_EXTRA_COMPILER instead and treating the lint program as a separate compiler

mylint.output = ${QMAKE_FILE_BASE}.lint
mylint.input = SOURCES
mylint.CONFIG = no_link
mylint.commands = llint -os ${QMAKE_FILE_OUT} $${mylint_include_path} ${QMAKE_FILE_NAME}
QMAKE_EXTRA_COMPILERS += mylint

linttarget.target = lint
linttarget.depends = $$lint_targets # computed above (see original post)
QMAKE_EXTRA_TARGETS += linttarget


It ain't pretty, but it works. I now have an extra make target called lint that depends on fileone.lint filetwo.lint filethree.lint

Those in turn are generated by the extra compiler that invokes lint on each source.

I still would like to have a finer control on things like the include paths but without 3 or 4 weeks to dive into the guts of qmake, this works for me. Hopefully it helps someone else. ;)

-Mic