blob: f848c2c22e494245cb2347fc529fe2da8f490974 (
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
\chapter Using Precompiled Headers
\target About
\section1 About Precompiled Headers
\index About Precompiled Headers
\index Using Precompiled Headers
\index Precompiled Headers
\index PCH
Precompiled headers are a performance feature supported by some
compilers to compile a stable body of code, and store the compiled
state of the code in a binary file. During subsequent compilations,
the compiler will load the stored state, and continue compiling the
specified file. Each subsequent compilation is faster because the
stable code does not need to be recompiled.
\e qmake supports the use of precompiled headers (PCH) on some
platforms and build environments, including:
\list
\i Windows
\list
\i nmake
\i Dsp projects (VC 6.0)
\i Vcproj projects (VC 7.0 \& 7.1)
\endlist
\i Mac OS X
\list
\i Makefile
\i Xcode
\i GCC 3.3 and up
\endlist
\i Unix
\list
\i GCC 3.4 and up
\endlist
\endlist
\target ADD_PCH
\section1 Adding PCH to your project
\target PCH_CONTENTS
\section2 Contents of the precompiled header file
The precompiled header must contain code which is \e stable
and \e static throughout your project. A typical PCH might look
like this:
\section3 stable.h
\code
/* Add C includes here */
#if defined __cplusplus
/* Add C++ includes here */
#include <stdlib>
#include <iostream>
#include <vector>
#include <ntqapplication.h> // TQt includes
#include <tqpushbutton.h>
#include <tqlabel.h>
#include "thirdparty/include/libmain.h"
#include "my_stable_class.h"
...
#endif
\endcode
Note that a precompiled header file needs to separate C includes from
CPP includes, since the precompiled header file for C files may not
contain C++ code.
\target PROJECT_OPTIONS
\section2 Project options
To make your project use PCH, the only thing you need to change in
your project settings (.pro), is to include the PRECOMPILED_HEADER option:
\code
PRECOMPILED_HEADER = stable.h
\endcode
\e qmake will handle the rest, to ensure the creation and use of the
precompiled header file. You do not need to include the precompiled
header file in HEADERS, as qmake will do this if the configuration
supports PCH.
All platforms that support precompiled headers have the configuration
option \Bold precompile_header set. Using this option, you may trigger
conditional blocks in your .pro file, to add settings when using PCH.
For example:
\code
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
DEFINES += USING_PCH
}
\endcode
\target EXAMPLE_PROJECT
\section1 Example project
You can find the following source code in the
\e{qt/qmake/examples/precompile} directory:
\Bold mydialog.ui
\quotefile precompile/mydialog.ui
\skipto <!
\printuntil </UI>
\Bold stable.h
\quotefile precompile/stable.h
\skipto /*
\printuntil #endif
\Bold myobject.h
\quotefile precompile/myobject.h
\skipto #include
\printuntil }
\Bold myobject.cpp
\quotefile precompile/myobject.cpp
\skipto #include
\printuntil }
\Bold util.cpp
\quotefile precompile/util.cpp
\skipto void
\printuntil }
\Bold main.cpp
\quotefile precompile/main.cpp
\skipto #include
\printuntil }
\Bold precompile.pro
\quotefile precompile/precompile.pro
\skipto #
\printuntil .ui
|