summaryrefslogtreecommitdiffstats
path: root/doc/html/qmake-manual-5.html
blob: d8ae485be6a6acbd2b648f862a29324e4917d9dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>qmake Concepts</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><p align="right">[<a href="qmake-manual-4.html">Prev: qmake Tutorial</a>] [<a href="qmake-manual.html">Home</a>] [<a href="qmake-manual-6.html">Next: qmake's Advanced Concepts</a>]</p>
<h2 align="center">qmake Concepts</h2>
<h3><a name="1"></a>Introducing qmake</h3>
<p><em>qmake</em> is an easy-to-use tool from Trolltech that creates makefiles for development projects across different platforms. <em>qmake</em> simplifies the generation of makefiles so that only a few lines of information are needed to create a makefile. <em>qmake</em> can be used for any software project whether it is written in TQt or not, although it also contains additional features to support TQt development.</p>
<p><em>qmake</em> generates a makefile based on the information in a project file. Project files are created by the developer. Project files are usually simple, but can be quite sophisticated if required. <em>qmake</em> can also generate projects for Microsoft Visual studio without having to change the project file.</p>
<h3><a name="2"></a>qmake's Concepts</h3>
<h4><a name="2-1"></a>The QMAKESPEC environment variable</h4>
<p>Before <em>qmake</em> can be used to build makefiles, the QMAKESPEC environment variable must be set to the platform-compiler combination that is being used on the system. The QMAKESPEC environment variable tells qmake where to look to find platform and compiler specific information. This ensures that the right libraries are used, and that the generated makefile uses the correct syntax. A list of the currently supported platform-compiler combinations can be found in qt/mkspecs. Just set your environment variable to one of the directories listed.</p>
<p>For example, if you are using Microsoft Visual Studio on Windows, then you would set the QMAKESPEC environment variable to <em>win32-msvc</em>. If you are using gcc on Solaris then you would set your QMAKESPEC environment variable to <em>solaris-g++</em>.</p>
<p>Inside each of the directories in qt/mkspecs, there is a <em>qmake.conf</em> file which contains the platform and compiler specific information. These settings are applied to any project that is built using <em>qmake</em> and should not be modified unless you're an expert. For example, if all your applications had to link against a particular library, you might add this information to the relevant <em>qmake.conf</em> file.</p>
<h4><a name="2-2"></a>Project (.pro) files</h4>
<p>A project file is used to tell <em>qmake</em> the details it needs to know about creating a makefile for the application. For instance, a list of source files and header files that should be put into the project file; any application specific configuration, such as an extra library that should be linked against, or an extra include path.</p>
<h5><a name="2-2-1"></a>'#' comments</h5>
<p>You can add comments to project files. Comments begin with the '#' symbol and run to the end of the line.</p>
<h4><a name="2-3"></a>Templates</h4>
<p>The template variable tells <em>qmake</em> what sort of makefile should be generated for the application. The following choices are available:</p>
<ul><li><p>app - Creates a makefile that builds an application. This is the default, so if a template is not specified, this is used.</p>
<li><p>lib - Creates a makefile that builds a library.</p>
<li><p>vcapp - Creates a Visual Studio Project file which builds an application.</p>
<li><p>vclib - Creates a Visual Studio Project file which builds a library.</p>
<li><p>subdirs - This is a special template which creates a makefile which will go into the specified directories and create a makefile for the project file and call make on it.</p>
</ul><h5><a name="2-3-1"></a>The 'app' template</h5>
<p>The 'app' template tells <em>qmake</em> to generate a makefile that will build an application. When using this template the following <em>qmake</em> system variables are recognized. You should use these in your .pro file to specify information about your application.</p>
<ul><li><p>HEADERS - A list of all the header files for the application.</p>
<li><p>SOURCES - A list of all the source files for the application.</p>
<li><p>FORMS - A list of all the .ui files (created using <em>TQt Designer</em>) for the application.</p>
<li><p>LEXSOURCES - A list of all the lex source files for the application.</p>
<li><p>YACCSOURCES - A list of all the yacc source files for the application.</p>
<li><p>TARGET - Name of the executable for the application. This defaults to the name of the project file. (The extension, if any, is added automatically).</p>
<li><p>DESTDIR - The directory in which the target executable is placed.</p>
<li><p>DEFINES - A list of any additional pre-processor defines needed for the application.</p>
<li><p>INCLUDEPATH - A list of any additional include paths needed for the application.</p>
<li><p>DEPENDPATH - The dependency search path for the application.</p>
<li><p>VPATH - The search path to find supplied files.</p>
<li><p>DEF_FILE - Windows only: A .def file to be linked against for the application.</p>
<li><p>RC_FILE - Windows only: A resource file for the application.</p>
<li><p>RES_FILE - Windows only: A resource file to be linked against for the application.</p>
</ul><p>You only need to use the system variables that you have values for, for instance, if you don't have any extra INCLUDEPATHs then you don't need to specify any, <em>qmake</em> will add in the default ones needed. For instance, an example project file might look like this:</p>
<pre>
TEMPLATE = app
DESTDIR  = c:\helloapp
HEADERS += hello.h
SOURCES += hello.cpp 
SOURCES += main.cpp
DEFINES += QT_DLL
CONFIG  += qt warn_on release
</pre>
<p>For items that are single valued, e.g. the template or the destination directory, we use "="; but for multi-valued items we use "+=" to <em>add</em> to the existing items of that type. Using "=" replaces the item's value with the new value, for example if we wrote <tt>DEFINES=QT_DLL</tt>, all other definitions would be deleted.</p>
<h5><a name="2-3-2"></a>The 'lib' template</h5>
<p>The 'lib' template tells <em>qmake</em> to generate a makefile that will build a library. When using this template, in addition to the system variables mentioned above for the 'app' template the <em>VERSION</em> variable is supported. You should use these in your .pro file to specify information about the library.</p>
<ul><li><p>VERSION - The version number of the target library, for example, 2.3.1.</p>
</ul><h5><a name="2-3-3"></a>The 'subdirs' template</h5>
<p>The 'subdirs' template tells qmake to generate a makefile that will go into the specified subdirectories and generate a makefile for the project file in the directory and call make on it.</p>
<p>The only system variable that is recognised for this template is the <em>SUBDIRS</em> variable. This variable contains a list of all the subdirectories that contain project files to be processed. It is essential that the project file in the sub directory has the same name as the subdirectory, so that <em>qmake</em> can find it. For example, if the subdirectory is called 'myapp' then the project file in that directory should be called <em>myapp.pro</em> in that directory.</p>
<h4><a name="2-4"></a>The CONFIG variable</h4>
<p>The config variable specifies the options that the compiler should use and the libraries that should be linked against. Anything can be added to the config variable, but the options covered below are recognised by qmake internally.</p>
<p>The following options control what compiler flags are used:</p>
<ul><li><p>release - The application is to be built in release mode. This is ignored if 'debug' is specified.</p>
<li><p>debug - The application is to be built in debug mode.</p>
<li><p>warn_on - The compiler should output as many warnings as possible. This is ignored if 'warn_off' is specified.</p>
<li><p>warn_off - The compiler should output as few warnings as possible.</p>
</ul><p>The following options define the type of library/application to be built:</p>
<ul><li><p>qt - The application is a TQt application and should link against the TQt library.</p>
<li><p>thread - The application is a multi-threaded application.</p>
<li><p>x11 - The application is an X11 application or library.</p>
<li><p>windows - 'app' template only: the application is a Windows window application.</p>
<li><p>console - 'app' template only: the application is a Windows console application.</p>
<li><p>dll - 'lib' template only: The library is a shared library (dll).</p>
<li><p>staticlib - 'lib' template only: The library is a static library.</p>
<li><p>plugin - 'lib' template only: The library is a plugin; this enables the dll option.</p>
</ul><p>For example, if your application uses the TQt library and you want to build it as a debuggable multi-threaded application, your project file will have the following line:</p>
<pre>
    CONFIG += qt thread debug
</pre>
<p>Note, that you must use "+=", not "=", or <em>qmake</em> will not be able to use the settings used to build TQt as a guide as what type of TQt library was built.</p>
<!-- eof -->
<p align="right">[<a href="qmake-manual-4.html">Prev: qmake Tutorial</a>] [<a href="qmake-manual.html">Home</a>] [<a href="qmake-manual-6.html">Next: qmake's Advanced Concepts</a>]</p>
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>