Including .pro Files: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
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|Български]]<br />[[Category:Tools]]<br />[[Category:HowTo]]


=Including pro-files into pro-files=
= 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.
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.
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.
<br />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.
<br />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&amp;amp;#40;pwd&amp;amp;#41; command (on Unix/Linux only - sorry).
<br />Within the &quot;qmake variable reference&amp;quot;: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:<br />''' &quot;'''PWD'''&quot;:http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#pwd<br />'''''' This variable contains the full path leading to the directory where the qmake project file &amp;#40;project.pro&amp;amp;#41; is located.<br />* &quot;'''OUT_PWD'''&quot;:http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#out-pwd<br />'''''' This variable contains the full path leading to the directory where qmake places the generated Makefile.<br />* Usage of the $$ prefix is detailed &quot;here&amp;quot;:http://doc.qt.nokia.com/latest/qmake-advanced-usage.html#variables .


In a pro-file, you have two important variables: <span class="caps">INCLUDEPATH</span> and <span class="caps">DEPENDPATH</span>. 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.
When having setup the include and depend paths, it is just a matter of adding to the SOURCES, HEADERS, RESOURCES and FORMS sections.


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).
To summarize, here is a small example:
 
Within the [http://doc.qt.nokia.com/4.7/qmake-variable-reference.html qmake variable reference] ''[doc.qt.nokia.com]'' , there are variables that may help find the current working directory (Tested on Windows ). A couple of these are:
 
* [http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#pwd '''<span class="caps">PWD</span>'''] ''[doc.qt.nokia.com]''
** This variable contains the full path leading to the directory where the qmake project file (project.pro) is located.
* [http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#out-pwd '''<span class="caps">OUT</span>_PWD'''] ''[doc.qt.nokia.com]''
** This variable contains the full path leading to the directory where qmake places the generated Makefile.
* Usage of the $$ prefix is detailed [http://doc.qt.nokia.com/latest/qmake-advanced-usage.html#variables here] ''[doc.qt.nokia.com]'' .


When having setup the include and depend paths, it is just a matter of adding to the <span class="caps">SOURCES</span>, <span class="caps">HEADERS</span>, <span class="caps">RESOURCES</span> and <span class="caps">FORMS</span> sections.
<code>INCLUDEPATH ''= $$system&amp;amp;#40;pwd&amp;amp;#41;/include<br />DEPENDSPATH''= $$system&amp;amp;#40;pwd&amp;amp;#41;


To summarize, here is a small example:
SOURCES ''= src/foo.cpp<br />HEADERS''= include/foo.h<br />FORMS ''= forms/foo.ui<br />RESOURCES''= foo.qrc<br /></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:


==Caveats==
<code>…<br />include(support/foo/foo.pri)<br />…<br /></code>
 
This solution seems to be too clever to the translation tools. To be able to use lrelease and lupdate, you must rely on less dynamic pro/pri-files, or simply find a way to generate a custom pro-file that you just use for translations.
 
===Categories:===


* [[:Category:HowTo|HowTo]]
== Caveats ==
* [[:Category:Tools|Tools]]

Revision as of 14:32, 23 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&amp;#40;pwd&amp;#41; command (on Unix/Linux only - sorry).
Within the "qmake variable reference&quot;: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 &#40;project.pro&amp;#41; 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&quot;: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&amp;amp;#40;pwd&amp;amp;#41;/include<br />DEPENDSPATH''= $$system&amp;amp;#40;pwd&amp;amp;#41;

SOURCES ''= src/foo.cpp<br />HEADERS''= include/foo.h<br />FORMS ''= forms/foo.ui<br />RESOURCES''= foo.qrc<br />

Finally, in the pro-file, simply add the pri-file by calling include:

<br />include(support/foo/foo.pri)<br /><br />

Caveats