PDA

View Full Version : Qt project management - bigger project



Peppy
20th December 2010, 21:24
I am very confused how to manage bigger project in Qt with .pro files. I have got this directory tree:


/
/bin - all binary files (.EXE/.DLL)
/lib - all linking libraries (.a/ .lib)
/tmp - temporary
/src - sources
Projects:
/src/Executable/Executable.pro
/src/Library.GUI/Library.GUI.pro
/src/Library.Services/Library.Services.pro
/src/...

How to link this projects together with Qt .pro/.pri (projects files) ? Is there some tutorial for it? :confused:

ChrisW67
20th December 2010, 23:00
It is all in the QMake manual. Look at "TEMPLATE = subdirs" for your PRO files to traverse a tree. Use a single, central PRI file that determines the full path to the bin and lib directories and defines QMAKE variable containing the results, and use those in the LIBS and DESTDIR variables of the component PRO files.

Peppy
21st December 2010, 19:49
Yes, of course, but I am very confused by using this project-type files (better solution is something like Visual Studio Solution and adding project via dialogues, and not via manually typing project ... it's not so practical)

tbscope
21st December 2010, 21:18
Before trying to run, you should at least be able to crawl.
This means that before you use tools like Visual Studio, you should already have basic knowledge of the toolchain and how to build programs with certain toolkits.

The subdirs template is extremely easy to use.
But, if you want shiny dialogs and buttons, go for Qt Creator.

Peppy
21st December 2010, 21:41
I don't want shiny dialogs, but Visual Studio has more better project management than Qt Creator, here I must manually set up directories and configuration, but it wasn't my question. But:

1. If I define something in Project.pro (it is main project file - works as entry for other subprojects) and use this variable in SubProject.pro (not included together, linked via SUBDIRS), it will works?

I have got 2 projects: Main - just for environment setup and working like entry point, Subproject - some subproject...


# Main.pro

DESTDIR = bin
DLLDESTDIR = bin
# and so on...

TEMPLATE = subdirs
SUBDIR = subproject



#subproject.pro
DESTDIR = ../$${DESTDIR}


2. Will this "project" work ?
3. Can I put makefile files into other directory ?

SixDegrees
21st December 2010, 22:10
If you need setting shared across a project, the easiest approach is to put them all into a project include file (*.pri) and include that file in the project files that need it. What you define in a *.pri file is arbitrary; any legal project file construct is acceptable. This is how shared settings are handled in any make-based environment.

You can, of course, also use environment variables for similar purposes. If these variables are unset or set incorrectly, however, builds can fail in unpleasant ways.

ChrisW67
21st December 2010, 23:15
More like this:


# top.pro
include(common.pri)
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = sub1



# common.pri
# You can use another method to locate the directories, e.g. full paths
MYBINDESTDIR = $$PWD/bin
MYDLLDESTDIR = $$PWD/bin
MYLIBDESTDIR = $$PWD/lib



# sub1/sub1.pro
include(../common.pri)
message( Sub1 MYBINDESTDIR is $$MYBINDESTDIR )
message( Sub1 MYDLLDESTDIR is $$MYDLLDESTDIR )
message( Sub1 MYLIBDESTDIR is $$MYLIBDESTDIR )

TEMPLATE = app
DESTDIR = $$MYBINDESTDIR

# Input
SOURCES += main.cpp

Peppy
22nd December 2010, 15:42
I am not sure, in your second code block: Yes, Okay, I have $$PWD/Bin (in main project - it is okay), but what if it will be subproject? It will not changes it automatically (this PATH) or it will make files into a current subproject directory? For example:


#in main project:
PWD = c:/test/project
BINDIR = $${PWD}/bin # also: c:/test/project/bin - that's good

#in subproject, it will change or not? (If not, it will be okay, if yes, I can't use them)
PWD = c:/test/project/subproject
BINDIR = c:/test/project/subproject/bin ??

I think I need use full direct paths (I don't want to play with these commands)....

Okay previous question was unanswered: How can I change a Makefiles files directory (I don't want have Makefiles at sources)

ChrisW67
23rd December 2010, 02:10
I am not sure, in your second code block: Yes, Okay, I have $$PWD/Bin (in main project - it is okay), but what if it will be subproject? It will not changes it automatically (this PATH) or it will make files into a current subproject directory?

Take 30 seconds and try it for yourself. $$PWD will be the directory containing common.pri, which is the top level directory in my example.


How can I change a Makefiles files directory (I don't want have Makefiles at sources)

You want to do a shadow build if you wish to keep the sources and the derived files (Makefiles, *.o, *.a, executables etc.) separate. If you are using Qt Creator there's a simple option to do this for you. Otherwise, create a build directory in parallel with your top level project directory and run the qmake there:


$ ls -d
myproject
$ mkdir build
$ cd build
$ qmake ../myproject/myproject.pro
$ make

This will affect the $$PWD expansion so you may wish to hard code the paths in common.pri.

If someone else has an elegant solution to identify the top of the shadow build location so that outputs can be placed there then I'm all ears.

Peppy
23rd December 2010, 21:39
Yes, I think a shadow build will be the best sollution, but if I have more subprojects, which has shadow builds too, it won't be much chaotic? Should I forbid a shadow builds in subprojects? How to organize it (to decrease a mess of directories, and count of directories [make shared binary, temporary, library, makefile and source directories and forbid for everyone subproject new shadow builds directories]) ?

ChrisW67
24th December 2010, 00:38
If you have a structure:


myproject/
myproject.pro # includes the sub projects using subdirs template
...
subproj1/
subproj1.pro # maybe a library template
... # source files
subproj2/
subproj2.pro # maybe another lib
...
subproj3/
subproj3.pro # this one is an app template
...
subproj4/
subproj4.pro # this one is another set of sub-projects
...
subproj4a/
subproj4a.pro # another lib
...
subpro4b/
subproj4b.pro # another app
...

and so on then when you shadow build you get:


myproject_shadow_build_dir/
Makefile
... # output files
subproj1/
Makefile
... # output files
subproj2/
Makefile
... # output files
subproj3/
Makefile
... # output files
subproj4/
Makefile
... # output files
subproj4a/
Makefile
... # output files
subproj4b/
Makefile
... # output files

in your build directory (If you don't fiddle with DESTDIR etc). One project structure, one shadow build structure.

Peppy
24th December 2010, 14:50
Okay, I'll try something