1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \page developing-on-mac.html
|
---|
30 | \title Developing Qt Applications for Mac OS X
|
---|
31 | \brief Information for developing Qt applications for Mac OS X
|
---|
32 | \ingroup platform-specific
|
---|
33 |
|
---|
34 | \tableofcontents
|
---|
35 |
|
---|
36 | Mac OS X is a UNIX platform and behaves similar to other Unix-like
|
---|
37 | platforms. The main difference is X11 is not used as the primary windowing
|
---|
38 | system. Instead, Mac OS X uses its own native windowing system that is
|
---|
39 | accessible through the Carbon and Cocoa APIs. Application development on
|
---|
40 | Mac OS X is done using Xcode Tools, an optional install included on every
|
---|
41 | Mac with updates available from \l {http://developer.apple.com}{Apple's
|
---|
42 | developer website}. Xcode Tools includes Apple-modified versions of the GCC
|
---|
43 | compiler.
|
---|
44 |
|
---|
45 |
|
---|
46 | \section1 What Versions of Mac OS X are Supported?
|
---|
47 |
|
---|
48 | As of Qt 4.7, Qt supports Mac OS X versions 10.4 and up. It is usually in
|
---|
49 | the best interest of the developer and user to be running the latest
|
---|
50 | updates to any version. We test internally against Mac OS X 10.4.11 as well
|
---|
51 | as the updated release of Mac OS X 10.5 and Mac OS X 10.6.
|
---|
52 |
|
---|
53 | \section2 Carbon or Cocoa?
|
---|
54 |
|
---|
55 | Qt supports building in two flavors, using either the Carbon or Cocoa API.
|
---|
56 | Using the Cocoa API, Qt requires 10.5 and provides both 32-bit and 64-bit support. With
|
---|
57 | Carbon, Qt can be developed on and deployed to 10.4, but there is no 64-bit
|
---|
58 | support.
|
---|
59 |
|
---|
60 | Note: There is no accessibility support in the Cocoa version. This is planned
|
---|
61 | for Qt 4.8.
|
---|
62 |
|
---|
63 | With Qt 4.7 we recommend using the Cocoa version of Qt for development,
|
---|
64 | unless you want to target the 10.4 platform. Qt uses Cocoa by default,
|
---|
65 | both for the binary package and when configuring Qt from source (using the \c{configure}
|
---|
66 | script). To build Qt for Carbon, specify the \c{-carbon} flag to configure.
|
---|
67 |
|
---|
68 | There are two versions of the Qt binary, one with x86 and x86_64
|
---|
69 | Cocoa and another with x86 and ppc Carbon. If you want a different setup
|
---|
70 | you must build Qt yourself using the source package. To explicitly configure
|
---|
71 | Qt to build for 34-bit or 64-bit architectures (or both), use
|
---|
72 | the \c{-arch} flags (see \l{universal binaries}{Universal Binaries}).
|
---|
73 | For the Cocoa version, 64 bit is chosen by default.
|
---|
74 |
|
---|
75 | Currently, Apple's default GCC compiler is used by default (GCC 4.0.1 on
|
---|
76 | 10.4 and 10.5, GCC 4.2 on 10.6). You can specify alternate compilers
|
---|
77 | though. For example, on Mac OS X 10.5, Apple's GCC 4.2 is also available
|
---|
78 | and selectable with the configure flag: \c{-platform macx-g++42}. LLVM-GCC
|
---|
79 | support is available by passing in the \c{-platform macx-llvm} flag. GCC
|
---|
80 | 3.x will \e not work. Though they may work, We do not support custom-built
|
---|
81 | GCC's.
|
---|
82 |
|
---|
83 | The following table summarizes the different versions of Mac OS X and what
|
---|
84 | capabilities are used by Qt.
|
---|
85 |
|
---|
86 | \table
|
---|
87 | \header
|
---|
88 | \o Mac OS X Version
|
---|
89 | \o Cat Name
|
---|
90 | \o Native API Used by Qt
|
---|
91 | \o Bits available to address memory
|
---|
92 | \o CPU Architecture Supported
|
---|
93 | \o Development Platform
|
---|
94 | \row
|
---|
95 | \o 10.4
|
---|
96 | \o Tiger
|
---|
97 | \o Carbon
|
---|
98 | \o 32
|
---|
99 | \o PPC/Intel
|
---|
100 | \o Yes
|
---|
101 | \row
|
---|
102 | \o 10.5
|
---|
103 | \o Leopard
|
---|
104 | \o Carbon
|
---|
105 | \o 32
|
---|
106 | \o PPC/Intel
|
---|
107 | \o Yes
|
---|
108 | \row
|
---|
109 | \o 10.5
|
---|
110 | \o Leopard
|
---|
111 | \o Cocoa
|
---|
112 | \o 32/64
|
---|
113 | \o PPC/Intel
|
---|
114 | \o Yes
|
---|
115 | \row
|
---|
116 | \o 10.6
|
---|
117 | \o Snow Leopard
|
---|
118 | \o Cocoa/Carbon
|
---|
119 | \o 32
|
---|
120 | \o PPC/Intel
|
---|
121 | \o Yes
|
---|
122 | \row
|
---|
123 | \o 10.6
|
---|
124 | \o Snow Leopard
|
---|
125 | \o Cocoa
|
---|
126 | \o 64
|
---|
127 | \o Intel
|
---|
128 | \o Yes
|
---|
129 | \endtable
|
---|
130 |
|
---|
131 | Note that building for ppc-64 is not supported on 10.6.
|
---|
132 |
|
---|
133 | \section2 Which One Should I Use?
|
---|
134 |
|
---|
135 | Carbon and Cocoa both have their advantages and disadvantages. Probably the
|
---|
136 | easiest way to determine is to look at the version of Mac OS X you are
|
---|
137 | targetting. If your application can target 10.5 and up, then we recommend
|
---|
138 | using Cocoa. If you need to target earlier versions of the operating system
|
---|
139 | and do not need access to 64-bit or newer Apple technologies, then Carbon
|
---|
140 | is a good fit. If your needs fall in between, you can go with a 64-bit Cocoa and 32-bit
|
---|
141 | Carbon universal application.
|
---|
142 |
|
---|
143 | For Mac OS X 10.6, Apple has started recommending developers to build their
|
---|
144 | applications 64-bit. The main reason is that there is a small speed
|
---|
145 | increase due to the extra registers on Intel CPU's, all their machine
|
---|
146 | offerings have been 64-bit since 2007, and there is a cost for reading all
|
---|
147 | the 32-bit libraries into memory if everything else is 64-bit. If you want
|
---|
148 | to follow this advice, there is only one choice, 64-bit Cocoa.
|
---|
149 |
|
---|
150 |
|
---|
151 | \section2 Building Qt statically
|
---|
152 |
|
---|
153 | We recommend building Qt as shared frameworks. Static builds are only partially
|
---|
154 | supported, meaning that you can build most of Qt statically, but some modules,
|
---|
155 | like web-kit and Designer, will fail. You can specify which modules to build
|
---|
156 | from configure (e.g. -no-webkit -nomake tools). For Cocoa configurations, both
|
---|
157 | static and no-framework builds requires manually copying the
|
---|
158 | 'src/gui/mac/qt_menu.nib/ directory into the " Resources" directory in
|
---|
159 | the application bundle.
|
---|
160 |
|
---|
161 | \target universal binaries
|
---|
162 | \section1 Universal Binaries
|
---|
163 |
|
---|
164 | In 2006, Apple begin transitioning from PowerPC (PPC) to Intel (x86)
|
---|
165 | systems. Both architectures are supported by Qt. The release of Mac OS X
|
---|
166 | 10.5 in October 2007 added the possibility of writing and deploying 64-bit
|
---|
167 | GUI applications. Qt 4.5 and up supports both the 32-bit (PPC and x86) and
|
---|
168 | 64-bit (PPC64 and x86-64) versions of PowerPC and Intel-based systems.
|
---|
169 |
|
---|
170 | Universal binaries are used to bundle binaries for more than one
|
---|
171 | architecture into a single package, simplifying deployment and
|
---|
172 | distribution. When running an application the operating system will select
|
---|
173 | the most appropriate architecture. Universal binaries support the following
|
---|
174 | architectures; they can be added to the build at configure time using the
|
---|
175 | \c{-arch} arguments:
|
---|
176 |
|
---|
177 | \table
|
---|
178 | \header
|
---|
179 | \o Architecture
|
---|
180 | \o Flag
|
---|
181 | \row
|
---|
182 | \o Intel, 32-bit
|
---|
183 | \o \c{-arch x86}
|
---|
184 | \row
|
---|
185 | \o Intel, 64-bit
|
---|
186 | \o \c{-arch x86_64}
|
---|
187 | \row
|
---|
188 | \o PPC, 32-bit
|
---|
189 | \o \c{-arch ppc}
|
---|
190 | \row
|
---|
191 | \o PPC, 64-bit
|
---|
192 | \o \c{-arch ppc64}
|
---|
193 | \endtable
|
---|
194 |
|
---|
195 | If there are no \c{-arch} flags specified, configure builds Qt for a 32-bit
|
---|
196 | architecture when using Carbon, and a 64-bit architecture when using Cocoa. Universal
|
---|
197 | binaries were initially
|
---|
198 | used to simplify the PPC to Intel migration. You can use \c{-universal} to
|
---|
199 | build for both the 32-bit Intel and PPC architectures.
|
---|
200 |
|
---|
201 | \note The \c{-arch} flags at configure time only affect how Qt is built.
|
---|
202 | Applications are by default built for the 32-bit architecture you are
|
---|
203 | currently on. To build a universal binary, add the architectures to the
|
---|
204 | CONFIG variable in the .pro file:
|
---|
205 |
|
---|
206 | \code
|
---|
207 | CONFIG += x86 ppc x86_64 ppc64
|
---|
208 | \endcode
|
---|
209 |
|
---|
210 | \section2 Working with several versions of Qt
|
---|
211 | You can only install one version of Qt at a time when using the binary
|
---|
212 | package. The reason for this is that a binary installation will install different parts of Qt
|
---|
213 | (frameworks, documentation, examples, tools, etc) to different
|
---|
214 | predefined locations on the OS, as described by Apple. If you want
|
---|
215 | to work against other versions at the same time, you need
|
---|
216 | to build the other versions explicitly from source. When doing so, you can
|
---|
217 | provide \c{-prefix} to configure to set install location.
|
---|
218 | The binary package will install Qt to the following locations:
|
---|
219 |
|
---|
220 | \table
|
---|
221 | \header
|
---|
222 | \o Qt
|
---|
223 | \o Location
|
---|
224 | \row
|
---|
225 | \o Designer, Linguist ...
|
---|
226 | \o /Developer/Applications/Qt
|
---|
227 | \row
|
---|
228 | \o Documentation
|
---|
229 | \o /Developer/Documentation/Qt
|
---|
230 | \row
|
---|
231 | \o Examples
|
---|
232 | \o /Developer/Examples/Qt
|
---|
233 | \row
|
---|
234 | \o Plugins
|
---|
235 | \o /Developer/Applications/Qt/Plugins
|
---|
236 | \row
|
---|
237 | \o Frameworks
|
---|
238 | \o /Library/Frameworks
|
---|
239 | \row
|
---|
240 | \o Libraries
|
---|
241 | \o /usr/lib
|
---|
242 | \row
|
---|
243 | \o qmake, moc, uic ...
|
---|
244 | \o /Developer/Tools/Qt (symlink to /usr/bin)
|
---|
245 | \row
|
---|
246 | \o uninstall-qt.py, uninstall-qtsdk.py
|
---|
247 | \o /Developer/Tools
|
---|
248 | \endtable
|
---|
249 |
|
---|
250 | \section1 Day-to-Day Application Development on OS X
|
---|
251 |
|
---|
252 | On the command-line, applications can be built using \c qmake and \c make.
|
---|
253 | Optionally, \c qmake can generate project files for Xcode with
|
---|
254 | \c{-spec macx-xcode}. If you are using the binary package, \c qmake
|
---|
255 | generates Xcode projects by default; use \c{-spec macx-gcc} to generate
|
---|
256 | makefiles.
|
---|
257 |
|
---|
258 | The result of the build process is an application bundle, which is a
|
---|
259 | directory structure that contains the actual application executable. The
|
---|
260 | application can be launched by double-clicking it in Finder, or by
|
---|
261 | referring directly to its executable from the command line, i. e.
|
---|
262 | \c{myApp.app/Contents/MacOS/myApp}.
|
---|
263 |
|
---|
264 | If you wish to have a command-line tool that does not use the GUI (e.g.,
|
---|
265 | \c moc, \c uic or \c ls), you can tell \c qmake not to execute the bundle
|
---|
266 | creating steps by removing it from the \c{CONFIG} in your \c{.pro} file:
|
---|
267 |
|
---|
268 | \code
|
---|
269 | CONFIG -= app_bundle
|
---|
270 | \endcode
|
---|
271 |
|
---|
272 |
|
---|
273 | \section1 Deployment - "Compile once, deploy everywhere"
|
---|
274 |
|
---|
275 | In general, Qt supports building on one Mac OS X version and deploying on
|
---|
276 | all others, both forward and backwards. You can build on 10.4 Tiger and run
|
---|
277 | the same binary on 10.5 and up.
|
---|
278 |
|
---|
279 | Some restrictions apply:
|
---|
280 |
|
---|
281 | \list
|
---|
282 | \o Some functions and optimization paths that exist in later versions
|
---|
283 | of Mac OS X will not be available if you build on an earlier
|
---|
284 | version of Mac OS X.
|
---|
285 | \o The CPU architecture should match.
|
---|
286 | \o Cocoa support is only available for Mac OS X 10.5 and up.
|
---|
287 | \endlist
|
---|
288 |
|
---|
289 | Universal binaries can be used to provide a smorgasbord of configurations
|
---|
290 | catering to all possible architectures.
|
---|
291 |
|
---|
292 | Mac applications are typically deployed as self-contained application
|
---|
293 | bundles. The application bundle contains the application executable as well
|
---|
294 | as dependencies such as the Qt libraries, plugins, translations and other
|
---|
295 | resources you may need. Third party libraries like Qt are normally not
|
---|
296 | installed system-wide; each application provides its own copy.
|
---|
297 |
|
---|
298 | The most common way to distribute applications is to provide a compressed
|
---|
299 | disk image (.dmg file) that the user can mount in Finder. The Mac
|
---|
300 | deployment tool (macdeployqt) can be used to create the self-contained bundles, and
|
---|
301 | optionally also create a .dmg archive. See the
|
---|
302 | \l{Deploying an Application on Mac OS X}{Mac deployment guide} for more
|
---|
303 | information about deployment. It is also possible to use an installer
|
---|
304 | wizard. More information on this option can be found in
|
---|
305 | \l{http://developer.apple.com/mac/}{Apple's documentation}.
|
---|
306 | */
|
---|
307 |
|
---|