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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qmake-manual.qdoc -->
<title>Qt 4.8: qmake Common Projects</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<div class="breadcrumb toolblock">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<!-- Breadcrumbs go here -->
<li>qmake Common Projects</li>
</ul>
</div>
</div>
<div class="content mainContent">
<link rel="prev" href="qmake-tutorial.html" />
<link rel="next" href="qmake-using.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qmake-tutorial.html">qmake Tutorial</a>
<a class="nextPage" href="qmake-using.html">Using qmake</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#building-an-application">Building an Application</a></li>
<li class="level2"><a href="#the-app-template">The app Template</a></li>
<li class="level1"><a href="#building-a-library">Building a Library</a></li>
<li class="level2"><a href="#the-lib-template">The lib Template</a></li>
<li class="level1"><a href="#building-a-plugin">Building a Plugin</a></li>
<li class="level2"><a href="#building-a-qt-designer-plugin">Building a Qt Designer Plugin</a></li>
<li class="level1"><a href="#building-and-installing-in-debug-and-release-modes">Building and Installing in Debug and Release Modes</a></li>
<li class="level2"><a href="#building-in-both-modes">Building in Both Modes</a></li>
<li class="level2"><a href="#installing-in-both-modes">Installing in Both Modes</a></li>
</ul>
</div>
<h1 class="title">qmake Common Projects</h1>
<span class="subtitle"></span>
<!-- $$$qmake-common-projects.html-description -->
<div class="descr"> <a name="details"></a>
<p>This chapter describes how to set up <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> project files for three common project types that are based on Qt. Although all kinds of projects use many of the same variables, each of them use project-specific variables to customize output files.</p>
<p>Platform-specific variables are not described here; we refer the reader to the <a href="deployment.html">Deploying Qt Applications</a> document for information on issues such as <a href="deployment-mac.html#architecture-dependencies">building universal binaries for Mac OS X</a> and <a href="deployment-windows.html#visual-studio-2005-onwards">handling Visual Studio manifest files</a>.</p>
<a name="application"></a><a name="building-an-application"></a>
<h2>Building an Application</h2>
<a name="the-app-template"></a>
<h3>The app Template</h3>
<p>The <tt>app</tt> template tells <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> to generate a Makefile that will build an application. With this template, the type of application can be specified by adding one of the following options to the <tt>CONFIG</tt> variable definition:</p>
<table class="generic">
<thead><tr class="qt-style"><th >Option</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >windows</td><td >The application is a Windows GUI application.</td></tr>
<tr valign="top" class="even"><td >console</td><td ><tt>app</tt> template only: the application is a Windows console application.</td></tr>
</table>
<p>When using this template the following <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> system variables are recognized. You should use these in your .pro file to specify information about your application.</p>
<ul>
<li>HEADERS - A list of all the header files for the application.</li>
<li>SOURCES - A list of all the source files for the application.</li>
<li>FORMS - A list of all the UI files (created using <tt>Qt Designer</tt>) for the application.</li>
<li>LEXSOURCES - A list of all the lex source files for the application.</li>
<li>YACCSOURCES - A list of all the yacc source files for the application.</li>
<li>TARGET - Name of the executable for the application. This defaults to the name of the project file. (The extension, if any, is added automatically).</li>
<li>DESTDIR - The directory in which the target executable is placed.</li>
<li>DEFINES - A list of any additional pre-processor defines needed for the application.</li>
<li>INCLUDEPATH - A list of any additional include paths needed for the application.</li>
<li>DEPENDPATH - The dependency search path for the application.</li>
<li>VPATH - The search path to find supplied files.</li>
<li><a href="qmake-variable-reference.html#def-file">DEF_FILE</a> - Windows only: A .def file to be linked against for the application.</li>
<li><a href="qmake-variable-reference.html#rc-file">RC_FILE</a> - Windows only: A resource file for the application.</li>
<li><a href="qmake-variable-reference.html#res-file">RES_FILE</a> - Windows only: A resource file to be linked against for the application.</li>
</ul>
<p>You only need to use the system variables that you have values for, for instance, if you do not have any extra INCLUDEPATHs then you do not need to specify any, <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> will add in the default ones needed. For instance, an example project file might look like this:</p>
<pre class="cpp"> 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 <i>add</i> 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>
<a name="library"></a><a name="building-a-library"></a>
<h2>Building a Library</h2>
<a name="the-lib-template"></a>
<h3>The lib Template</h3>
<p>The <tt>lib</tt> template tells <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> to generate a Makefile that will build a library. When using this template, in addition to the system variables mentioned above for the <tt>app</tt> template the <tt>VERSION</tt> variable is supported. You should use these in your .pro file to specify information about the library.</p>
<p>When using the <tt>lib</tt> template, the following options can be added to the <tt>CONFIG</tt> variable to determine the type of library that is built:</p>
<table class="generic">
<thead><tr class="qt-style"><th >Option</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >dll</td><td >The library is a shared library (dll).</td></tr>
<tr valign="top" class="even"><td >staticlib</td><td >The library is a static library.</td></tr>
<tr valign="top" class="odd"><td >plugin</td><td >The library is a plugin; this also enables the dll option.</td></tr>
</table>
<p>The following option can also be defined to provide additional information about the library.</p>
<ul>
<li>VERSION - The version number of the target library, for example, 2.3.1.</li>
</ul>
<p>The target file name for the library is platform-dependent. For example, on X11 and Mac OS X, the library name will be prefixed by <tt>lib</tt>; on Windows, no prefix is added to the file name.</p>
<a name="plugin"></a><a name="building-a-plugin"></a>
<h2>Building a Plugin</h2>
<p>Plugins are built using the <tt>lib</tt> template, as described in the previous section. This tells <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> to generate a Makefile for the project that will build a plugin in a suitable form for each platform, usually in the form of a library. As with ordinary libraries, the <tt>VERSION</tt> variable is used to specify information about the plugin.</p>
<ul>
<li>VERSION - The version number of the target library, for example, 2.3.1.</li>
</ul>
<a name="building-a-qt-designer-plugin"></a>
<h3>Building a Qt Designer Plugin</h3>
<p><i>Qt Designer</i> plugins are built using a specific set of configuration settings that depend on the way Qt was configured for your system. For convenience, these settings can be enabled by adding <tt>designer</tt> to the project's <tt>CONFIG</tt> variable. For example:</p>
<pre class="cpp"> CONFIG += designer plugin</pre>
<p>See the <a href="examples-designer.html">Qt Designer Examples</a> for more examples of plugin-based projects.</p>
<a name="building-and-installing-in-debug-and-release-modes"></a>
<h2>Building and Installing in Debug and Release Modes</h2>
<p>Sometimes, it is necessary to build a project in both debug and release modes. Although the <tt>CONFIG</tt> variable can hold both <tt>debug</tt> and <tt>release</tt> options, the <tt>debug</tt> option overrides the <tt>release</tt> option.</p>
<a name="building-in-both-modes"></a>
<h3>Building in Both Modes</h3>
<p>To enable a project to be built in both modes, you must add the <tt>debug_and_release</tt> option to your project's <tt>CONFIG</tt> definition:</p>
<pre class="cpp"> CONFIG += debug_and_release
CONFIG(debug, debug|release) {
TARGET = debug_binary
} else {
TARGET = release_binary
}</pre>
<p>The scope in the above snippet modifies the build target in each mode to ensure that the resulting targets have different names. Providing different names for targets ensures that one will not overwrite the other.</p>
<p>When <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> processes the project file, it will generate a Makefile rule to allow the project to be built in both modes. This can be invoked in the following way:</p>
<pre class="cpp"> make all</pre>
<p>The <tt>build_all</tt> option can be added to the <tt>CONFIG</tt> variable in the project file to ensure that the project is built in both modes by default:</p>
<pre class="cpp"> CONFIG += build_all</pre>
<p>This allows the Makefile to be processed using the default rule:</p>
<pre class="cpp"> make</pre>
<a name="installing-in-both-modes"></a>
<h3>Installing in Both Modes</h3>
<p>The <tt>build_all</tt> option also ensures that both versions of the target will be installed when the installation rule is invoked:</p>
<pre class="cpp"> make install</pre>
<p>It is possible to customize the names of the build targets depending on the target platform. For example, a library or plugin may be named using a different convention on Windows to the one used on Unix platforms:</p>
<pre class="cpp"> CONFIG(debug, debug|release) {
mac: TARGET = $$join(TARGET,,,_debug)
win32: TARGET = $$join(TARGET,,d)
}</pre>
<p>The default behavior in the above snippet is to modify the name used for the build target when building in debug mode. An <tt>else</tt> clause could be added to the scope to do the same for release mode; left as it is, the target name remains unmodified.</p>
</div>
<!-- @@@qmake-common-projects.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qmake-tutorial.html">qmake Tutorial</a>
<a class="nextPage" href="qmake-using.html">Using qmake</a>
</p>
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.</p>
<br />
<p>
The documentation provided herein is licensed under the terms of the
<a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
License version 1.3</a> as published by the Free Software Foundation.</p>
<p>
Documentation sources may be obtained from <a href="http://www.qt-project.org">
www.qt-project.org</a>.</p>
<br />
<p>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. <a title="Privacy Policy"
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>
|