1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \page qmake-manual.html
|
---|
44 | \title qmake Manual
|
---|
45 | \startpage {index.html}{Qt Reference Documentation}
|
---|
46 | \nextpage qmake Tutorial
|
---|
47 |
|
---|
48 | \ingroup buildsystem
|
---|
49 | \ingroup qttools
|
---|
50 | \keyword qmake
|
---|
51 |
|
---|
52 | \c qmake is a tool that helps simplify the build
|
---|
53 | process for development project across different platforms. \c qmake
|
---|
54 | automates the generation of Makefiles so that only a few lines of
|
---|
55 | information are needed to create each Makefile. \c qmake can be used for
|
---|
56 | any software project, whether it is written in Qt or not.
|
---|
57 |
|
---|
58 | \c qmake generates a Makefile based on the information in a project
|
---|
59 | file. Project files are created by the developer, and are usually
|
---|
60 | simple, but more sophisticated project files can be created for
|
---|
61 | complex projects.
|
---|
62 | \c qmake contains additional features to support development with Qt,
|
---|
63 | automatically including build rules for \l{moc.html}{moc}
|
---|
64 | and \l{uic.html}{uic}.
|
---|
65 | \c qmake can also generate projects for Microsoft Visual studio
|
---|
66 | without requiring the developer to change the project file.
|
---|
67 |
|
---|
68 | \section1 Getting Started
|
---|
69 |
|
---|
70 | The \l{qmake Tutorial} and guide to \l{qmake Common Projects} provide overviews
|
---|
71 | that aim to help new users get started with \c qmake.
|
---|
72 |
|
---|
73 | \list
|
---|
74 | \o \l{qmake Tutorial}
|
---|
75 | \tableofcontents{1 qmake Tutorial}
|
---|
76 | \endlist
|
---|
77 |
|
---|
78 | \list
|
---|
79 | \o \l{qmake Common Projects}
|
---|
80 | \tableofcontents{1 qmake Common Projects}
|
---|
81 | \endlist
|
---|
82 |
|
---|
83 | \section1 Table of Contents
|
---|
84 |
|
---|
85 | \list
|
---|
86 | \o \l{Using qmake}
|
---|
87 | \tableofcontents{1 Using qmake}
|
---|
88 | \o \l{qmake Project Files}
|
---|
89 | \tableofcontents{1 qmake Project Files}
|
---|
90 | \o \l{Running qmake}
|
---|
91 | \tableofcontents{1 Running qmake}
|
---|
92 | \o \l{qmake Platform Notes}
|
---|
93 | \tableofcontents{1 qmake Platform Notes}
|
---|
94 | \o \l{qmake Advanced Usage}
|
---|
95 | \tableofcontents{1 qmake Advanced Usage}
|
---|
96 | \o \l{Using Precompiled Headers}
|
---|
97 | \tableofcontents{1 Using Precompiled Headers}
|
---|
98 | \o \l{qmake Reference}
|
---|
99 | \tableofcontents{1 qmake Reference}
|
---|
100 | \o \l{qmake Variable Reference}
|
---|
101 | \tableofcontents{1 qmake Variable Reference}
|
---|
102 | \o \l{qmake Function Reference}
|
---|
103 | \tableofcontents{1 qmake Function Reference}
|
---|
104 | \o \l{Configuring qmake's Environment}
|
---|
105 | \tableofcontents{1 Configuring qmake's Environment}
|
---|
106 | \endlist
|
---|
107 | */
|
---|
108 |
|
---|
109 | /*!
|
---|
110 | \page qmake-using.html
|
---|
111 | \title Using qmake
|
---|
112 | \contentspage {qmake Manual}{Contents}
|
---|
113 | \previouspage qmake Manual
|
---|
114 | \nextpage qmake Project Files
|
---|
115 |
|
---|
116 | \c qmake provides a project-oriented system for managing the build
|
---|
117 | process for applications, libraries, and other components. This
|
---|
118 | approach gives developers control over the source files used, and
|
---|
119 | allows each of the steps in the process to be described concisely,
|
---|
120 | typically within a single file. \c qmake expands the information in
|
---|
121 | each project file to a Makefile that executes the necessary commands
|
---|
122 | for compiling and linking.
|
---|
123 |
|
---|
124 | In this document, we provide a basic introduction to project files,
|
---|
125 | describe some of the main features of \c qmake, and show how to use
|
---|
126 | \c qmake on the command line.
|
---|
127 |
|
---|
128 | \section1 Describing a Project
|
---|
129 |
|
---|
130 | Projects are described by the contents of project (\c .pro) files.
|
---|
131 | The information within these is used by \c qmake to generate a Makefile
|
---|
132 | containing all the commands that are needed to build each project.
|
---|
133 | Project files typically contain a list of source and header files,
|
---|
134 | general configuration information, and any application-specific details,
|
---|
135 | such as a list of extra libraries to link against, or a list of extra
|
---|
136 | include paths to use.
|
---|
137 |
|
---|
138 | Project files can contain a number of different elements, including
|
---|
139 | comments, variable declarations, built-in functions, and some simple
|
---|
140 | control structures. In most simple projects, it is only necessary
|
---|
141 | to declare the source and header files that are used to build the
|
---|
142 | project with some basic configuration options.
|
---|
143 |
|
---|
144 | Complete examples of project files can be found in the
|
---|
145 | \l{qmake Tutorial}.
|
---|
146 | An introduction to project files can be found in the
|
---|
147 | \l{qmake Project Files} chapter, and a more detailed description is
|
---|
148 | available in the \l{qmake Reference}.
|
---|
149 |
|
---|
150 | \section1 Building a Project
|
---|
151 |
|
---|
152 | For simple projects, you only need to run \c qmake in the top
|
---|
153 | level directory of your project. By default, \c qmake generates a
|
---|
154 | Makefile that you then use to build the project, and you can then
|
---|
155 | run your platform's \c make tool to build the project.
|
---|
156 |
|
---|
157 | \c qmake can also be used to generate project files. A full
|
---|
158 | description of \c{qmake}'s command line options can be found in the
|
---|
159 | \l{Running qmake} chapter of this manual.
|
---|
160 |
|
---|
161 | \section1 Using Precompiled Headers
|
---|
162 |
|
---|
163 | In large projects, it is possible to take advantage of precompiled
|
---|
164 | header files to speed up the build process. This feature is described
|
---|
165 | in detail in the \l{Using Precompiled Headers} chapter.
|
---|
166 | */
|
---|
167 |
|
---|
168 | /*!
|
---|
169 | \page qmake-project-files.html
|
---|
170 | \title qmake Project Files
|
---|
171 | \contentspage {qmake Manual}{Contents}
|
---|
172 | \previouspage Using qmake
|
---|
173 | \nextpage Running qmake
|
---|
174 |
|
---|
175 | Project files contain all the information required by \c qmake to build
|
---|
176 | your application, library, or plugin. The resources used by your project
|
---|
177 | are generally specified using a series of declarations, but support for
|
---|
178 | simple programming constructs allow you to describe different build
|
---|
179 | processes for different platforms and environments.
|
---|
180 |
|
---|
181 | \tableofcontents
|
---|
182 |
|
---|
183 | \section1 Project File Elements
|
---|
184 |
|
---|
185 | The project file format used by \c qmake can be used to support both
|
---|
186 | simple and fairly complex build systems. Simple project files will
|
---|
187 | use a straightforward declarative style, defining standard variables
|
---|
188 | to indicate the source and header files that are used in the project.
|
---|
189 | Complex projects may use the control flow structures to fine-tune the
|
---|
190 | build process.
|
---|
191 |
|
---|
192 | The following sections describe the different types of elements used
|
---|
193 | in project files.
|
---|
194 |
|
---|
195 | \section2 Variables
|
---|
196 |
|
---|
197 | In a project file, variables are used to hold lists of strings.
|
---|
198 | In the simplest projects, these variables inform \c qmake about the
|
---|
199 | configuration options to use, or supply filenames and paths to use
|
---|
200 | in the build process.
|
---|
201 |
|
---|
202 | \c qmake looks for certain variables in each project file, and it
|
---|
203 | uses the contents of these to determine what it should write to a
|
---|
204 | Makefile. For example, the list of values in the \c HEADERS and
|
---|
205 | \c SOURCES variables are used to tell \c qmake about header and
|
---|
206 | source files in the same directory as the project file.
|
---|
207 |
|
---|
208 | Variables can also be used internally to store temporary lists of values,
|
---|
209 | and existing lists of values can be overwritten or extended with new
|
---|
210 | values.
|
---|
211 |
|
---|
212 | The following lines show how lists of values are assigned to variables:
|
---|
213 |
|
---|
214 | \snippet doc/src/snippets/qmake/variables.pro 0
|
---|
215 |
|
---|
216 | Note that the first assignment only includes values that are specified on
|
---|
217 | the same line as the \c SOURCES variable. The second assignment splits
|
---|
218 | the items across lines by using the \c \\ character.
|
---|
219 |
|
---|
220 | The list of values in a variable is extended in the following way:
|
---|
221 |
|
---|
222 | \snippet doc/src/snippets/qmake/variables.pro 1
|
---|
223 |
|
---|
224 | The \c CONFIG variable is another special variable that \c qmake
|
---|
225 | uses when generating a Makefile. It is discussed in the section on
|
---|
226 | \l{#GeneralConfiguration}{general configuration} later in this chapter.
|
---|
227 | In the above line, \c qt is added to the list of existing values
|
---|
228 | contained in \c CONFIG.
|
---|
229 |
|
---|
230 | The following table lists the variables that \c qmake recognizes, and
|
---|
231 | describes what they should contain.
|
---|
232 |
|
---|
233 | \table
|
---|
234 | \header \o Variable \o Contents
|
---|
235 | \row \o CONFIG \o General project configuration options.
|
---|
236 | \row \o DESTDIR \o The directory in which the executable or binary file will
|
---|
237 | be placed.
|
---|
238 | \row \o FORMS \o A list of .ui files to be processed by \c uic.
|
---|
239 | \row \o HEADERS \o A list of filenames of header (.h) files used when
|
---|
240 | building the project.
|
---|
241 | \row \o QT \o Qt-specific configuration options.
|
---|
242 | \row \o RESOURCES \o A list of resource (.rc) files to be included in the
|
---|
243 | final project. See the \l{The Qt Resource System} for
|
---|
244 | more information about these files.
|
---|
245 | \row \o SOURCES \o A list of source code files to be used when building
|
---|
246 | the project.
|
---|
247 | \row \o TEMPLATE \o The template to use for the project. This determines
|
---|
248 | whether the output of the build process will be an
|
---|
249 | application, a library, or a plugin.
|
---|
250 | \endtable
|
---|
251 |
|
---|
252 | The contents of a variable can be read by prepending the variable name with
|
---|
253 | \c $$. This can be used to assign the contents of one variable to another:
|
---|
254 |
|
---|
255 | \snippet doc/src/snippets/qmake/dereferencing.pro 0
|
---|
256 |
|
---|
257 | The \c $$ operator is used extensively with built-in functions that operate
|
---|
258 | on strings and lists of values. These are described in the chapter on
|
---|
259 | \l{qmake Advanced Usage}.
|
---|
260 |
|
---|
261 | Normally, variables are used to contain whitespace-separated lists
|
---|
262 | of values. However, it is sometimes necessary to specify values containing
|
---|
263 | spaces. These must be quoted in the following way:
|
---|
264 |
|
---|
265 | \snippet doc/src/snippets/qmake/quoting.pro 0
|
---|
266 |
|
---|
267 | The quoted text is treated as a single item in the list of values held by
|
---|
268 | the variable.
|
---|
269 |
|
---|
270 | \section2 Comments
|
---|
271 |
|
---|
272 | You can add comments to project files. Comments begin with the \c
|
---|
273 | # character and continue to the end of the same line. For example:
|
---|
274 |
|
---|
275 | \snippet doc/src/snippets/qmake/comments.pro 0
|
---|
276 |
|
---|
277 | To include the \c # character in variable assignments, it is necessary
|
---|
278 | to use the contents of the built-in \c LITERAL_HASH variable. See the
|
---|
279 | \l{qmake Variable Reference#LITERAL_HASH}{variable reference} for more
|
---|
280 | information.
|
---|
281 |
|
---|
282 | \section2 Built-in Functions and Control Flow
|
---|
283 |
|
---|
284 | \c qmake provides a number of built-in functions to allow the contents
|
---|
285 | of variables to be processed. The most commonly used function in simple
|
---|
286 | project files is the \c include function which takes a filename as an
|
---|
287 | argument. The contents of the given file are included in the project
|
---|
288 | file at the place where the \c include function is used.
|
---|
289 | The \c include function is most commonly used to include other project
|
---|
290 | files:
|
---|
291 |
|
---|
292 | \snippet doc/src/snippets/qmake/include.pro 0
|
---|
293 |
|
---|
294 | Support for conditional structures is made available via
|
---|
295 | \l{qmake Advanced Usage#scopes}{scopes} that behave like \c if
|
---|
296 | statements in programming languages:
|
---|
297 |
|
---|
298 | \snippet doc/src/snippets/qmake/scopes.pro 0
|
---|
299 |
|
---|
300 | The assignments inside the braces are only made if the condition is
|
---|
301 | true. In this case, the special \c win32 variable must be set; this
|
---|
302 | happens automatically on Windows, but this can also be specified on
|
---|
303 | other platforms by running \c qmake with the \c{-win32} command line
|
---|
304 | option (see \l{Running qmake} for more information). The opening
|
---|
305 | brace must stand on the same line as the condition.
|
---|
306 |
|
---|
307 | Simple loops are constructed by iterating over lists of values using
|
---|
308 | the built-in \c for function. The following code adds directories
|
---|
309 | to the \l{qmake Variable Reference#SUBDIRS}{SUBDIRS} variable, but
|
---|
310 | only if they exist:
|
---|
311 |
|
---|
312 | \snippet doc/src/snippets/qmake/functions.pro 0
|
---|
313 |
|
---|
314 | More complex operations on variables that would usually require loops
|
---|
315 | are provided by built-in functions such as \c find, \c unique, and
|
---|
316 | \c count. These functions, and many others are provided to manipulate
|
---|
317 | strings and paths, support user input, and call external tools. A list
|
---|
318 | of the functions available can be found in the
|
---|
319 | \l{qmake Advanced Usage} chapter of this manual.
|
---|
320 |
|
---|
321 | \section1 Project Templates
|
---|
322 |
|
---|
323 | The \c TEMPLATE variable is used to define the type of project that will
|
---|
324 | be built. If this is not declared in the project file, \c qmake assumes
|
---|
325 | that an application should be built, and will generate an appropriate
|
---|
326 | Makefile (or equivalent file) for the purpose.
|
---|
327 |
|
---|
328 | The types of project available are listed in the following table with
|
---|
329 | information about the files that \c qmake will generate for each of them:
|
---|
330 |
|
---|
331 | \table
|
---|
332 | \header \o Template \o Description of \c qmake output
|
---|
333 | \row \o app (default) \o Creates a Makefile to build an application.
|
---|
334 | \row \o lib \o Creates a Makefile to build a library.
|
---|
335 | \row \o subdirs \o Creates a Makefile containing rules for the
|
---|
336 | subdirectories specified using the \l{qmake Variable Reference#SUBDIRS}{SUBDIRS}
|
---|
337 | variable. Each subdirectory must contain its own project file.
|
---|
338 | \row \o vcapp \o Creates a Visual Studio Project file to build
|
---|
339 | an application.
|
---|
340 | \row \o vclib \o Creates a Visual Studio Project file to build a library.
|
---|
341 | \endtable
|
---|
342 |
|
---|
343 | See the \l{qmake Tutorial} for advice on writing project files for
|
---|
344 | projects that use the \c app and \c lib templates.
|
---|
345 |
|
---|
346 | When the \c subdirs template is used, \c qmake generates a Makefile
|
---|
347 | to examine each specified subdirectory, process any project file it finds
|
---|
348 | there, and run the platform's \c make tool on the newly-created Makefile.
|
---|
349 | The \l{qmake Variable Reference#SUBDIRS}{SUBDIRS} variable is used to
|
---|
350 | contain a list of all the subdirectories to be processed.
|
---|
351 |
|
---|
352 | \target GeneralConfiguration
|
---|
353 | \section1 General Configuration
|
---|
354 |
|
---|
355 | The \l{qmake Variable Reference#CONFIG}{CONFIG variable} specifies the
|
---|
356 | options and features that the compiler should use and the libraries that
|
---|
357 | should be linked against. Anything can be added to the \c CONFIG variable,
|
---|
358 | but the options covered below are recognized by \c qmake internally.
|
---|
359 |
|
---|
360 | The following options control the compiler flags that are used to build the
|
---|
361 | project:
|
---|
362 |
|
---|
363 | \table
|
---|
364 | \header \o Option \o Description
|
---|
365 | \row \o release \o The project is to be built in release mode.
|
---|
366 | This is ignored if \c debug is also specified.
|
---|
367 | \row \o debug \o The project is to be built in debug mode.
|
---|
368 | \row \o debug_and_release \o The project is built in \e both debug and
|
---|
369 | release modes.
|
---|
370 | \row \o debug_and_release_target \o The project is built in \e both debug
|
---|
371 | and release modes. TARGET is built into \e both the debug and release directories.
|
---|
372 | \row \o build_all \o If \c debug_and_release is specified, the project is
|
---|
373 | built in both debug and release modes by default.
|
---|
374 | \row \o autogen_precompile_source \o Automatically generates a \c .cpp file that includes
|
---|
375 | the precompiled header file specified in the .pro file.
|
---|
|
---|