View Full Version : QMake: using unix backquote commands

6th May 2011, 09:57
I' m tring to include an external library to a .pro file.

To include this library when I compile in manual mode, I use the command

c++ -o test test.cpp `/mydir/libmesh-config --cxxflags --include --ldflags`

I use backquotes to have libraries path and so on. for example if I write

/mydir/libmesh-config --include

I obtain the list of includes in the form

-I/mydir/libmesh/include/base -I/mydir/libmesh/include/enums -I/mydir/libmesh/include/error_estimation -I/mydir/libmesh/include/fe -I/mydir/libmesh/include/geom -I/mydir/libmesh/include/mesh -I/mydir/libmesh/include/numerics -I/mydir/libmesh/include/parallel (and so on)

So I'd like to use this command in the .pro file instead of declaring every include path. The same for the --ldflags flag option that gives to me paths to libraries.

I've tried to write in the .pro file the following line, for example:

unix {
INCLUDEPATH += `/mydir/libmesh-config --include`

but it does not work (I get a "argument:: No such file or directory" error in qtcreator).

I'd like to know if it's possible to use this command to include libraries, instead of doing it by hand.

Thanks in advance.

6th May 2011, 10:20
Perhaps http://doc.trolltech.com/4.7-snapshot/qmake-function-reference.html#system-command does work?

6th May 2011, 11:32
Thanks. I'm trying to set the INCLUDEPATH variable, using this code

unix {
TMPPATHS = $$system(/mydir/bin/libmesh-config --include)
message(Adding include path $${LIBMESHPATH})
At first, i set in TMPPATHS the list of directories: then, inn LIBMESHINCLUDEPATHS I erase the "-I" at the beginning of every path (and I print this variable to verify that's ok). Then, I use the for cycle to add every path to the INCLUDEPATH variable.

But I've a problem in the for cycle. Infact, the message inside the loop is printed only once, and with an empty string in place of LIBMESHPATH. It seems that the cycle fails to initialize this variable, and after the cycle INCLUDEPATH remains empty.

How can I add paths in the variable to the INCLUDEPATH variable?

Added after 30 minutes:

Ok I've solved. I used the following code:

## Adding include paths ##
unix {
TMPPATHS = $$system(/mydir/bin/libmesh-config --include)
INCLUDEPATH += $$replace(TMPPATHS, "-I", "")

Thanks to everyone