Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Including .pro Files: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
'''English''' [[IncludingProFiles Malay|Malay]] [[IncludingProFiles Spanish|Spanish]] [[IncludingProFiles_German|German]] [[IncludingProFiles_French|French]] [[IncludingProFiles_Bulgarian|Български]] | '''English''' [[IncludingProFiles Malay|Malay]] [[IncludingProFiles Spanish|Spanish]] [[IncludingProFiles_German|German]] [[IncludingProFiles_French|French]] [[IncludingProFiles_Bulgarian|Български]] | ||
[[Category:Tools]] | |||
[[Category:HowTo]] | |||
= Including pro-files into pro-files = | = Including pro-files into pro-files = | ||
Line 6: | Line 8: | ||
First up, a convention, pro-files meant for inclusion in other pro-files are commonly named '''.pri, just to indicate that they are for inclusion. This also means that qmake does not find them, but uses the appropriate pro-file instead. | First up, a convention, pro-files meant for inclusion in other pro-files are commonly named '''.pri, just to indicate that they are for inclusion. This also means that qmake does not find them, but uses the appropriate pro-file instead. | ||
In a pro-file, you have two important variables: INCLUDEPATH and DEPENDPATH. The first is used by the C++ compiler when resolving #include statements, while the latter is used by qmake when trying to determine what to build in which order. | |||
To create a truly movable source tree, the pri-files update these variables appropriately. My trick to do that is to rely on the current working directory. You find that by running the $$system(pwd) command (on Unix/Linux only - sorry). | |||
Within the "qmake variable reference":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html , there are variables that may help find the current working directory (Tested on Windows ). A couple of these are: | |||
''' "'''PWD'''":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#pwd | |||
'''''' This variable contains the full path leading to the directory where the qmake project file (project.pro) is located. | |||
* "'''OUT_PWD'''":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#out-pwd | |||
'''''' This variable contains the full path leading to the directory where qmake places the generated Makefile. | |||
* Usage of the $$ prefix is detailed "here":http://doc.qt.nokia.com/latest/qmake-advanced-usage.html#variables . | |||
When having setup the include and depend paths, it is just a matter of adding to the SOURCES, HEADERS, RESOURCES and FORMS sections. | When having setup the include and depend paths, it is just a matter of adding to the SOURCES, HEADERS, RESOURCES and FORMS sections. | ||
Line 14: | Line 24: | ||
To summarize, here is a small example: | To summarize, here is a small example: | ||
<code>INCLUDEPATH ''= $$system | <code>INCLUDEPATH ''= $$system(pwd)/include | ||
DEPENDSPATH''= $$system(pwd) | |||
SOURCES ''= src/foo.cpp | SOURCES ''= src/foo.cpp | ||
HEADERS''= include/foo.h | |||
FORMS ''= forms/foo.ui | |||
RESOURCES''= foo.qrc | |||
</code> | |||
Finally, in the pro-file, simply add the pri-file by calling include: | Finally, in the pro-file, simply add the pri-file by calling include: | ||
<code>… | <code>… | ||
include(support/foo/foo.pri) | |||
… | |||
</code> | |||
== Caveats == | == Caveats == |
Revision as of 08:56, 25 February 2015
English Malay Spanish German French Български
Including pro-files into pro-files
QMake's project files sometimes need to rely on the include feature. This is a great tool, but there are some tricks of the trade to be aware of.
First up, a convention, pro-files meant for inclusion in other pro-files are commonly named .pri, just to indicate that they are for inclusion. This also means that qmake does not find them, but uses the appropriate pro-file instead.
In a pro-file, you have two important variables: INCLUDEPATH and DEPENDPATH. The first is used by the C++ compiler when resolving #include statements, while the latter is used by qmake when trying to determine what to build in which order.
To create a truly movable source tree, the pri-files update these variables appropriately. My trick to do that is to rely on the current working directory. You find that by running the $$system(pwd) command (on Unix/Linux only - sorry).
Within the "qmake variable reference":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html , there are variables that may help find the current working directory (Tested on Windows ). A couple of these are: "PWD":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#pwd ' This variable contains the full path leading to the directory where the qmake project file (project.pro) is located.
' This variable contains the full path leading to the directory where qmake places the generated Makefile.
- Usage of the $$ prefix is detailed "here":http://doc.qt.nokia.com/latest/qmake-advanced-usage.html#variables .
When having setup the include and depend paths, it is just a matter of adding to the SOURCES, HEADERS, RESOURCES and FORMS sections.
To summarize, here is a small example:
INCLUDEPATH ''= $$system(pwd)/include
DEPENDSPATH''= $$system(pwd)
SOURCES ''= src/foo.cpp
HEADERS''= include/foo.h
FORMS ''= forms/foo.ui
RESOURCES''= foo.qrc
Finally, in the pro-file, simply add the pri-file by calling include:
…
include(support/foo/foo.pri)
…