aboutsummaryrefslogtreecommitdiffstats
path: root/doc/appendix/qbs-porting.qdoc
blob: ee6159606dcd8c3637184c74a25ce5d64ca26933 (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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qbs.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \contentspage index.html
    \previouspage building-qbs.html
    \page porting-to-qbs.html
    \nextpage attributions.html

    \title Appendix B: Migrating from Other Build Systems

    You can use the \c {qbs create-project} command to automatically generate
    \QBS project files from an arbitrary directory structure. This is a useful
    starting point when migrating from other build tools, such as qmake or
    CMake.

    To use the tool, switch to the project directory and run the
    \c {qbs create-project} command, which is located in the \c bin directory of
    the \QBS installation directory (or the Qt Creator installation directory).

    After generating the initial .qbs file, add the missing configuration
    variables and functions to it, as described in the following sections.

    \section1 Migrating from qmake

    The following sections describe the \QBS equivalents of qmake variable
    values.

    \section2 CONFIG

    Specify project configuration and compiler options.

    \section3 console

    Set the \l{Product::consoleApplication}{product.consoleApplication} property
    to \c true for the \l{Application}, \l{CppApplication},or \l{QtApplication}
    item. For example:

    \code
    Application {
        name: "helloworld"
        files: "main.cpp"
        Depends { name: "cpp" }
        consoleApplication: true
    }
    \endcode

    \section3 ordered

    This qmake variable has no direct equivalent in \QBS. Instead, the build
    order is determined by implicit and explicit dependencies between products.
    To add an explicit dependency, add a \l{Depends} item to a
    \l{Product}{product}:

    \code
    CppApplication {
        name: "myapp"
        Depends { name: "mylib" }
    }
    \endcode

    The \c myapp product depends on and links to the \c mylib product, and is
    therefore built after it.

    \section3 qt

    In qmake, the Qt dependency is implicit, whereas in \QBS it is not.
    If \c {CONFIG -= qt}, add a \l{Depends} item to specify that
    the \l{Product}{product} depends on the \l{Module cpp}{cpp module}:

    \code
    Product {
        Depends { name: "cpp" }
    }
    \endcode

    \section2 DEFINES

    Set the \l{Module cpp}{cpp.defines} property for the \l{Product}{product}.

    \note To reference \c cpp.defines, you must specify a dependency on the
    \l{Module cpp}{cpp} module.

    \code
    Product {
        Depends { name: "cpp" }
        cpp.defines: ["SUPPORT_MY_FEATURES"]
    }
    \endcode

    \section2 DESTDIR

    We recommend that you use the \l{Installing Files}{installation mechanism}
    to specify the location of the target file:

    \code
    Application {
        Group {
            name: "Runtime resources"
            files: "*.qml"
            qbs.install: true
            qbs.installDir: "share/myproject"
        }
        Group {
            name: "The App itself"
            fileTagsFilter: "application"
            qbs.install: true
            qbs.installDir: "bin"
        }
    }
    \endcode

    If that is not possible, you can use the \c destinationDirectory property:

    \code
    DynamicLibrary {
        name: "mydll"
        destinationDirectory: "libDir"
    }
    \endcode

    \section2 HEADERS, SOURCES, FORMS, RESOURCES

    Include header, source, form, and resource files as values of
    \l{Product::files}{product.files} property:

    \code
    QtApplication {
        name: "myapp"
        files: ["myapp.h", "myapp.cpp", "myapp.ui", "myapp.qrc"]
    }
    \endcode

    \QBS uses \l{FileTagger}{file taggers} to figure out what kind of file
    it is dealing with.

    \section2 ICON

    There is no direct equivalent in \QBS. If you add a \l{Depends}
    {dependency} to the \l{Module ib}{ib module} and add the \c .xcassets
    directory as a value of the \c files property of the \l{Product}
    {product}, \QBS takes care of setting the application icon automatically
    when building for Apple platforms:

    \code
    Application {
        name: "myapp"
        files [".xcassets"]
        Depends { name: "ib" }
    }
    \endcode

    Alternatively, you can set the icon name as the value of the
    \l{Module bundle}{bundle.infoPlist} parameter, specify a dependency to the
    \c ib module, and add the application \c .icns file as a value of the
    \c files property:

    \code
    Application {
        name: "myapp"
        files ["myapp.icns"]
        Depends { name: "ib" }
        bundle.infoPlist: ({"CFBundleIconFile": "myapp"})
    \endcode

    \section2 INCLUDEPATH

    Add the paths to the include files as values of the \l{Module cpp}
    {cpp.includePaths} property:

    \code
    CppApplication {
        cpp.includePaths: ["..", "some/other/dir"]
    }
    \endcode

    \section2 LIBS

    For libraries that are part of the project, use \l{Depends} items.

    To pull in external libraries, use the \l{Module cpp}{cpp.libraryPaths}
    property for the Unix \c -L (library path) flags and the
    \c cpp.dynamicLibraries and \c cpp.staticLibraries properties for the
    \c -l (library) flags.

    For example, \c {LIBS += -L/usr/local/lib -lm} would become:

    \code
    CppApplication {
        cpp.libraryPaths: ["/usr/local/lib"]
        cpp.dynamicLibraries: ["m"]
    }
    \endcode

    \section2 OUT_PWD

    Use the \c product.buildDirectory property of the \l{Product}{product}
    to refer to the base output directory of the generated artifacts.

    \section2 PWD

    Corresponds to the the file-scope variable \c path.

    \section2 _PRO_FILE_

    Corresponds to the file-scope variable \c filePath when used in a
    \l{Project}{project} or \l{Product}{product}.

    \section2 _PRO_FILE_PWD_

    Corresponds to the \c sourceDirectory property of a
    \l{Project}{project} or \l{Product}{product}.

    \section2 QMAKE_ASSET_CATALOGS

    Add a \l{Depends}{dependency} to the \l{Module ib}{ib module} and add
    the \c .xcassets directory as a value of the \c files property of the
    \l{Product}{product}:

    \code
    Application {
        name: "myapp"
        files [".xcassets"]
        Depends { name: "ib" }
    }
    \endcode

    \section2 QMAKE_BUNDLE_DATA

    For the time being, you can manually place files in the appropriate location
    using the \l{Installing Files}{installation mechanism}. Better solutions are
    under development.

    \section2 QMAKE_BUNDLE_EXTENSION

    Set the \c bundle.extension property for the \l{Module bundle}{bundle}.

    \note Unlike qmake, \QBS automatically prepends a period (.) to the property
    value.

    \section2 QMAKE_{C,CXX,OBJECTIVE}_CFLAGS{_DEBUG,_RELEASE}

    Use the \c cpp.commonCompilerFlags property of the the \l{Module cpp}{cpp}
    module or the properties corresponding to each compiler flags variable:

    \table
        \header
            \li qmake Variable
            \li cpp Module Property
        \row
            \li \c QMAKE_CFLAGS_DEBUG

                \c QMAKE_CFLAGS_RELEASE
            \li \c cpp.cCompilerFlags
        \row
            \li \c QMAKE_CXXFLAGS_DEBUG

                \c QMAKE_CXXFLAGS_RELEASE
            \li \c cpp.cxxCompilerFlags
        \row
            \li \c QMAKE_OBJECTIVE_CFLAGS
            \li \c cpp.objcCompilerFlags

                \c cpp.objcxxCompilerFlags
    \endtable

    Use \l{Properties} items or simple conditionals as values
    of the \l{Module qbs}{qbs.buildVariant} property to simulate the \c _DEBUG
     and\c _RELEASE variants of the qmake variables.

    \section2 QMAKE_FRAMEWORK_BUNDLE_NAME

    Set the \c bundle.bundleName property (which is derived from
    \c product.target) combined with \c bundle.extension for the
    \l{Module bundle}{bundle}.

    \section2 QMAKE_FRAMEWORK_VERSION

    Set the \c bundle.frameworkVersion property for the \l{Module bundle}
    {bundle}.

    \section2 QMAKE_INFO_PLIST

    Include the \c info.plist file as a value of the \c files property of the
    \l{Product}{product} and specify a dependency to the \l{Module bundle}
    {bundle} module:

    \code
    Application {
        name: "myapp"
        files ["info.plist"]
        Depends { name: "bundle" }
    }
    \endcode

    \QBS will automatically add any necessary properties to your \c Info.plist
    file. Typically, it determines the appropriate values from the other
    properties in the project, and therefore you do not need to use the
    \c {Info.plist.in > Info.plist} configuration mechanism. Further, you almost
    never need to embed placeholders into the source \c Info.plist file. Set the
    \c bundle.processInfoPlist property to \c false to disable this behavior:

    \code
    \\ ...
        bundle.processInfoPlist: false
    \endcode

    In addition to, or instead of, using an actual \c Info.plist file, you can
    add \c Info.plist properties using the \c bundle.infoPlist property. For
    example:

    \code
    \\ ...
        bundle.infoPlist: ({
            "NSHumanReadableCopyright": "Copyright (c) 2017 Bob Inc",
            "Some other key", "Some other value, & XML special characters are no problem! >;) 非凡!"
        })
    \endcode

    \section2 QMAKE_LFLAGS

    Set the \l{Module cpp}{cpp.linkerFlags} property for the \l{Product}
    {product}.

    \section2 QMAKE_{MACOSX,IOS,TVOS,WATCHOS}_DEPLOYMENT_TARGET

    For each qmake deployment target variable, use the corresponding property of
    the \l{Module cpp}{cpp} module:

    \table
        \header
            \li qmake Variable
            \li cpp Module Property
        \row
            \li \c QMAKE_MACOSX_DEPLOYMENT_TARGET
            \li \c cpp.minimumMacosVersion
        \row
            \li \c QMAKE_IOS_DEPLOYMENT_TARGET
            \li \c cpp.minimumIosVersion
        \row
            \li \c QMAKE_TVOS_DEPLOYMENT_TARGET
            \li \c cpp.minimumTvosVersion
        \row
            \li \c QMAKE_WATCHOS_DEPLOYMENT_TARGET
            \li \c cpp.minimumWatchosVersion
    \endtable

    \section2 QMAKE_RPATHDIR

    Set the \l{Module cpp}{cpp.rpaths} property for the \l{Product}{product}.

    \section2 QMAKE_SONAME_PREFIX

    Use the \l{Module cpp}{cpp.sonamePrefix} property for the \l{Product}
    {product}.

    \section2 QML_IMPORT_PATH

    Used only for Qt Creator QML syntax highlighting. Inside a \l{Product},
    \l{Application}, \l{CppApplication}, or \l{QtApplication}, create a
    \c qmlImportPaths property:

    \code
    Product {
        name: "myProduct"
        property stringList qmlImportPaths: [sourceDirectory + "/path/to/qml/"]
    }
    \endcode

    \section2 QT

    Add a \l{Depends} item to the \l{Product}{product} that
    specifies the dependencies to \l{Qt Modules}{Qt modules}. For example:

    \code
    QtApplication {
        Depends { name: "Qt.widgets" }
    }
    \endcode

    You could also use the following form that is equivalent to the previous
    one:

    \code
    QtApplication {
        Depends { name: "Qt"; submodules: "widgets" }
    }
    \endcode

    \section2 QTPLUGIN

    Building static applications often requires linking to static QPA plugins,
    such as \c qminimal. You can use the following syntax to enable \QBS to
    link to the required plugins:

    \code
    QtApplication {
        name: "myapp"
        Depends { name: "Qt"; submodules: ["core", "gui", "widgets"] }
        Depends { name: "Qt.qminimal"; condition: Qt.core.staticBuild }
    }
    \endcode

    \section2 RC_FILE

    Add Windows resource files to the value of the \c files property for the
    \l{Product}{product}.

    \section2 TARGET

    Use the \c targetName property to specify the base file name of target
    artifacts of the \l{Product}{product}.

    \section2 TEMPLATE

    \section3 app

    Use \l{Application} or \l{CppApplication} as the \l{Product}{product}:

    \code
    CppApplication {
        name: "helloworld"
        files: "main.cpp"
    }
    \endcode

    This is roughly equivalent to:

    \code
    Product {
        name: "helloworld"
        type: "application"
        files: "main.cpp"
        Depends { name: "cpp" }
    }
    \endcode

    \section3 lib

    Use either \l{DynamicLibrary} or \l{StaticLibrary} as the \l{Product}
    {product}, depending on whether the value of \c CONFIG in the .pro file is
    \c shared or \c static. For example, if the value is \c shared:

    \code
    DynamicLibrary {
        name: "mydll"
        files: ["mySourceFile.cpp"]
        Depends { name: "cpp" }
    }
    \endcode

    \section3 subdirs

    In a \l{Project} item, specify subdirectories as values of the
    \c references property:

    \code
    Project {
        references: [
            "app/app.qbs",
            "lib/lib.qbs"
        ]
    }
    \endcode

    \section2 message(), warning(), error(), log()

    You can use the JavaScript console printing functions (\c console.info,
    \c console.warn, \c console.error, and \c console.log) to print info,
    warning, error, and log messages to the console.

    \code
    Product {
        name: {
            console.info("--> now evaluating the product name");
            return "theName";
        }
        Depends { name: "cpp" }
        cpp.includePath: { throw "An error occurred." }
    }
    \endcode
*/