PDA

View Full Version : qmake + subdirectories



niko
14th April 2007, 08:10
Hello,

I would like to get some structure in my project:
/ <- main-sourcecode
/reader <- import filters
/writer <- export filters

I don't need libraries - all should be linked together in one executable.

I could do this with one big .pro in / which includes reader/... files.
But normaly this is done with a .pro file in every folder.

Is there anywhere an example for this?
Or should I organize my files different?

thanks,
niko

marcel
14th April 2007, 08:17
Check the examples directory in your qt installation. There are some examples there.

Regards

wysota
14th April 2007, 08:18
If you use more than one .pro file, it is assumed that you want to build more than one separate "thing" (subproject). In your case it is of course possible to build the subdirectiories as static libraries which would then be linked with the main application, but if you don't need that functionality, you'll get exactly the same code with a single project file.

niko
14th April 2007, 09:50
Check the examples directory in your qt installation. There are some examples there.

I did that - but they all are independent applications. And I want only one executable out of it.




If you use more than one .pro file, it is assumed that you want to build more than one separate "thing" (subproject). In your case it is of course possible to build the subdirectiories as static libraries which would then be linked with the main application, but if you don't need that functionality, you'll get exactly the same code with a single project file.
Ok - i will like to try it with static libraries.

my subdir-pro:

CONFIG += staticlib
TEMPLATE = lib
TARGET = ../reader
If I build the subdir it creates a libreader.a in the root-directory.

my root-pro:

TEMPLATE=app
LIBS += -L. -lreader
SUBDIRS += reader
If I build the project if finds and uses the libreader.a file.


But "SUBDIRS += reader" in the root-pro is ignored. so i have to go manually in alls subdirs and build them. How can I tell the root-pro it should behave like app *and* subdirs (or any other solution?)

thanks,
niko

elcuco
14th April 2007, 10:45
TEMPLATE=app
LIBS += -L. -lreader
SUBDIRS += reader


is this portable to non gcc compilers?

niko
14th April 2007, 11:23
from the qmake-manual:


unix:LIBS += -L. -lreader
win32:LIBS += reader.lib

i guess this way it is portable

(i currently don't have a mac or windows here to test this)

wysota
14th April 2007, 13:39
But "SUBDIRS += reader" in the root-pro is ignored.
Because it only makes sense for "subdirs" template.


so i have to go manually in alls subdirs and build them. How can I tell the root-pro it should behave like app *and* subdirs (or any other solution?)
make two subdirectories and use one to build the library and the other to build the main app. Alternatively you might try this:

TEMPLATE = subdirs
SUBDIRS = mainapp.pro reader/reader.pro



is this portable to non gcc compilers?
Partially. The "-L" and "-l" switches are portable but the library name might not be.

jpn
14th April 2007, 14:18
How about simple .pri files for reader and writer? ;)

wysota
14th April 2007, 14:26
The simplest way is to just put files into two directories and provide relative paths in the .pro file. No additional .pro or .pri files needed :)

niko
14th April 2007, 18:50
The simplest way is to just put files into two directories and provide relative paths in the .pro file. No additional .pro or .pri files needed :)
ok, thanks

i will do it that way....

niko