-
Notifications
You must be signed in to change notification settings - Fork 55
/
global.pri
431 lines (343 loc) · 12.4 KB
/
global.pri
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
# Copyright 2014 - 2018 CyberTech Co. Ltd., Yurii Litvinov, Iakov Kirilenko
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Build settings common to all projects in TrikRuntime.
# Provides:
# CONFIGURATION_SUFFIX variable that shall be consistently used in TARGET and LIBS variables in all projects.
# copyToDestdir function to copy arbitrary files and directories to DESTDIR
# uses function to automatically add a library to INCLUDEPATH and LIBS.
#
# Uses environment variable INSTALL_ROOT as a root of a file structure for install rules.
#
# Uses CONFIG variable to control support for Google Sanitizers:
# - CONFIG+=sanitize-address will enable address sanitizer
# - CONFIG+=sanitize-undefined will enable undefined behavior sanitizer
# - CONFIG+=sanitize-thread will enable thread sanitizer
!isEmpty(_PRO_FILE_):!isEmpty(CONFIG):isEmpty(RUNTIME_GLOBAL_PRI_INCLUDED){
# commented out, seems like there is no need for this var, but let's wait
RUNTIME_GLOBAL_PRI_INCLUDED=1
COMPILER = $$(CXX)
!isEmpty(QMAKE_GCC_MAJOR_VERSION) {
COMPILER_VERSION=$${QMAKE_GCC_MAJOR_VERSION}.$${QMAKE_GCC_MINOR_VERSION}
}
COMPILER_IS_ARM = $$find(COMPILER, arm-.*)
PYTHONQTALL_CONFIG=PythonQtCore
CONFIG *= qt
CONFIG -= app_bundle
!win32:CONFIG *= use_gold_linker
#CONFIG *= fat-lto
#deal with mixed configurations
CONFIG -= debug_and_release debug_and_release_target
CONFIG(debug, debug | release): CONFIG -= release
else:!debug:CONFIG *= release
release:CONFIG -= debug
no-sanitizers: CONFIG *= nosanitizers
CONFIG = $$unique(CONFIG)
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO *= -Og
QMAKE_CXXFLAGS_DEBUG *= -Og
unix:debug {
QMAKE_CXXFLAGS += -coverage
QMAKE_LFLAGS += -coverage
}
!gcc4:!gcc5:!clang:!win32:gcc:*-g++*:system($$QMAKE_CXX --version | grep -qEe '"\\<5\\.[0-9]+\\."' ){ CONFIG += gcc5 }
!gcc4:!gcc5:!clang:!win32:gcc:*-g++*:system($$QMAKE_CXX --version | grep -qEe '"\\<4\\.[0-9]+\\."' ){ CONFIG += gcc4 }
GLOBAL_PWD = $$absolute_path($$PWD)
GLOBAL_OUTPWD = $$absolute_path($$OUT_PWD)
isEmpty(GLOBAL_DESTDIR) {
GLOBAL_DESTDIR = $$GLOBAL_OUTPWD/bin
}
isEmpty(DESTDIR) {
DESTDIR = $$GLOBAL_DESTDIR
}
PROJECT_BASENAME = $$basename(_PRO_FILE_)
PROJECT_NAME = $$section(PROJECT_BASENAME, ".", 0, 0)
isEmpty(TARGET) {
TARGET = $$PROJECT_NAME$$CONFIGURATION_SUFFIX
} else {
R=$$find( TARGET, "$$CONFIGURATION_SUFFIX$" )
isEmpty(R):TARGET = $$TARGET$$CONFIGURATION_SUFFIX
}
!no_rpath {
unix:!macx {
QMAKE_LFLAGS += -Wl,-rpath-link,$$GLOBAL_DESTDIR
QMAKE_LFLAGS += -Wl,-O1,-rpath,\'\$$ORIGIN\'
} macx {
QMAKE_LFLAGS += -rpath @executable_path
QMAKE_LFLAGS += -rpath @executable_path/../Lib
QMAKE_LFLAGS += -rpath @executable_path/../Frameworks
QMAKE_LFLAGS += -rpath @executable_path/../../../
}
}
equals(TEMPLATE, lib){
CONFIG += create_pc create_libtool
QMAKE_PKGCONFIG_NAME=$$TARGET
QMAKE_PKGCONFIG_PREFIX = $$INSTALLBASE
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$headers.path
QMAKE_PKGCONFIG_VERSION = $$VERSION
# QMAKE_PKGCONFIG_DESCRIPTION =
}
#Workaround for a known gcc/ld (before 7.3/bionic) issue
#use_gold_linker:!clang: QMAKE_LFLAGS += -Wl,--disable-new-dtags
macx-clang {
# QMAKE_MACOSX_DEPLOYMENT_TARGET=10.12
QMAKE_LFLAGS_SONAME = -Wl,-install_name,@rpath/
}
!nosanitizers:!clang:gcc:*-g++*:gcc4{
warning("Disabled sanitizers, failed to detect compiler version or too old compiler: $$QMAKE_CXX")
CONFIG += nosanitizers
}
!nosanitizers {
CONFIG += sanitizer
}
!nosanitizers {
# seems like we want USan always, but are afraid of ....
!CONFIG(sanitize_address):!CONFIG(sanitize_thread):!CONFIG(sanitize_memory):!CONFIG(sanitize_kernel_address) {
# Ubsan is turned on by default
#CONFIG += sanitizer sanitize_undefined
#QMAKE_SANITIZE_UNDEFINED_CXXFLAGS += -fsanitize-trap=undefined -fsanitize-undefined-trap-on-error
}
CONFIG(sanitize_address) {
# GCC 5.5 does not know this
# QMAKE_SANITIZE_ADDRESS_CXXFLAGS += -fsanitize-address-use-after-scope
#!clang:QMAKE_LFLAGS_RELEASE *= -static-libasan
}
#LSan can be used without performance degrade even in release build
#But at the moment we can not, because of Qt problems
CONFIG(debug):!CONFIG(sanitize_address):!CONFIG(sanitize_memory):!CONFIG(sanitize_thread):!macx-clang {
CONFIG += sanitize_leak
}
sanitize_leak {
QMAKE_CFLAGS *= -fsanitize=leak
QMAKE_CXXFLAGS *= -fsanitize=leak
QMAKE_LFLAGS *= -fsanitize=leak
#!clang:QMAKE_LFLAGS_RELEASE *= -static-liblsan
}
sanitize_memory {
QMAKE_CFLAGS *= -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins
QMAKE_CXXFLAGS *= -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins
}
sanitize_undefined {
# This hack allows to avoid runtime dependency.
win32:isEmpty(TRIK_SANITIZE_UNDEFINED_FLAGS):TRIK_SANITIZE_UNDEFINED_FLAGS = -fsanitize-undefined-trap-on-error
QMAKE_SANITIZE_UNDEFINED_CFLAGS *= $$TRIK_SANITIZE_UNDEFINED_FLAGS
QMAKE_SANITIZE_UNDEFINED_CXXFLAGS *= $$TRIK_SANITIZE_UNDEFINED_FLAGS
QMAKE_SANITIZE_UNDEFINED_LFLAGS *= $$TRIK_SANITIZE_UNDEFINED_FLAGS
#!clang:QMAKE_LFLAGS_RELEASE *= -static-libubsan
}
sanitize_thread {
#!clang:QMAKE_LFLAGS_RELEASE *= -static-libtsan
}
gcc5 {
CONFIG(sanitize_undefined){
# Ubsan has (had at least) known issues with false errors about calls of methods of the base class.
# That must be disabled. Variables for confguring ubsan are taken from here:
# https://codereview.qt-project.org/#/c/43420/17/mkspecs/common/sanitize.conf
# They can change in some version of Qt, keep track of it.
# By the way, simply setting QMAKE_CFLAGS, QMAKE_CXXFLAGS and QMAKE_LFLAGS instead of those used below
# will not work due to arguments order ("-fsanitize=undefined" must be declared before "-fno-sanitize=vptr").
# Useless since 2019? Commented out.
# QMAKE_SANITIZE_UNDEFINED_CFLAGS += -fno-sanitize=vptr
# QMAKE_SANITIZE_UNDEFINED_CXXFLAGS += -fno-sanitize=vptr
# QMAKE_SANITIZE_UNDEFINED_LFLAGS += -fno-sanitize=vptr
}
}
unix {
QMAKE_CFLAGS_RELEASE += -fsanitize-recover=all
QMAKE_CXXFLAGS_RELEASE += -fsanitize-recover=all
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -fno-sanitize-recover=all
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -fno-sanitize-recover=all
QMAKE_CFLAGS_DEBUG += -fno-sanitize-recover=all
QMAKE_CXXFLAGS_DEBUG += -fno-sanitize-recover=all
}
}
precompile_header {
PRECOMPILED_HEADER = $$PWD/pch.h
QMAKE_CXXFLAGS *= -Wno-error=invalid-pch
}
INCLUDEPATH += $$_PRO_FILE_PWD_ \
$$_PRO_FILE_PWD_/include \
$$_PRO_FILE_PWD_/include/$$PROJECT_NAME \
THIS_IS_QS_LOG=$$find(PROJECT_NAME, [qQ]s[lL]og)
isEmpty(THIS_IS_QS_LOG) {
INCLUDEPATH += $$GLOBAL_PWD/qslog/qslog
}
CONFIG += c++14
DEFINES += QT_FORCE_ASSERTS
QMAKE_CXXFLAGS += -pedantic-errors -Wextra -Werror
!clang: QMAKE_CXXFLAGS += -ansi
gcc5 | clang {
QMAKE_CXXFLAGS +=-Werror=pedantic -Werror=delete-incomplete
}
clang {
#treat git submodules as system path
SYSTEM_INCLUDE_PREFIX_OPTION += $$system(git submodule status 2>/dev/null | sed $$shell_quote('s/^.[0-9a-fA-F]* \\([^ ]*\\).*$/-isystem=\\1/g'))
#treat Qt includes as system headers
SYSTEM_INCLUDE_PREFIX_OPTION +=\
-cxx-isystem$$shell_quote($$[QT_INSTALL_HEADERS]) \
--system-header-prefix=$$shell_quote($$[QT_INSTALL_LIBS]) \
for(module, QT) {
equals(module, "testlib"): module = test
moduleList = $$split(module, )
SYSTEM_INCLUDE_PREFIX_OPTION += \
--system-header-prefix=Qt$$upper($$take_first(moduleList))$$join(moduleList, )
}
unset(moduleList)
}
gcc {
#treat Qt includes as system headers
#but -isystem causes problems in OE thud
!count(COMPILER_IS_ARM, 1):SYSTEM_INCLUDE_PREFIX_OPTION *= -isystem $$[QT_INSTALL_HEADERS]
}
QMAKE_CXXFLAGS += $$SYSTEM_INCLUDE_PREFIX_OPTION
gcc:versionAtLeast(QT_VERSION, 5.14.2):QMAKE_CXXFLAGS *= -Wno-error=deprecated-declarations
false:clang {
# Problem from Qt system headers
QMAKE_CXXFLAGS += -Wno-error=expansion-to-defined -Wno-error=c++98-compat -Wno-error=sign-conversion \
-Wno-error=covered-switch-default -Wno-error=c++98-compat-pedantic \
-Wno-error=documentation-unknown-command -Wno-error=inconsistent-missing-destructor-override \
-Wno-error=used-but-marked-unused -Wno-error=extra-semi-stmt -Wno-error=padded \
-Wno-error=float-equal -Wno-error=float-conversion -Wno-error=implicit-float-conversion \
-Wno-error=redundant-parens -Wno-error=deprecated -Wno-error=shift-sign-overflow \
-Wno-error=zero-as-null-pointer-constant -Wno-error=exit-time-destructors \
-Wno-error=double-promotion -Wno-error=shadow-field -Wno-error=documentation \
-Wno-error=reserved-id-macro -Wno-error=extra-semi -Wno-error=comma
}
QMAKE_CXXFLAGS += -Werror=cast-qual -Werror=write-strings -Werror=redundant-decls -Werror=unreachable-code \
-Werror=non-virtual-dtor -Wno-error=overloaded-virtual \
-Werror=uninitialized -Werror=init-self
gcc4:QMAKE_CXXFLAGS += -Wno-error=missing-field-initializers
# Simple function that checks if given argument is a file or directory.
# Returns false if argument 1 is a file or does not exist.
defineTest(isDir) {
exists($$system_path($$1/*)):return(true)
return(false)
}
# Useful function to copy additional files to destination,
# from http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output
defineTest(copyToDestdir) {
FILES = $$1
NOW = $$2
for(FILE, FILES) {
DESTDIR_SUFFIX =
AFTER_SLASH = $$section(FILE, "/", -1, -1)
isDir($$FILE) {
ABSOLUTE_PATH = $$absolute_path($$FILE, $$GLOBAL_PWD)
BASE_NAME = $$section(ABSOLUTE_PATH, "/", -1, -1)
DESTDIR_SUFFIX = $$BASE_NAME/
FILE = $$FILE/*
}
DDIR = $$quote($$system_path($$DESTDIR/$$3$$DESTDIR_SUFFIX))
FILE = $$quote($$system_path($$FILE))
mkpath($$DDIR)
win32 {
# probably, xcopy needs /s and /e for directories
COPY_DIR = "cmd.exe /C xcopy /y /i /s /e "
!silent: COPY_DIR += /f
} else {
COPY_DIR = rsync -a
!silent: COPY_DIR += -v
}
COPY_COMMAND = $$COPY_DIR $$FILE $$DDIR
isEmpty(NOW) {
QMAKE_POST_LINK += $$COPY_COMMAND $$escape_expand(\\n\\t)
} else {
system($$COPY_COMMAND)
}
}
export(QMAKE_POST_LINK)
}
defineTest(interfaceIncludes) {
PROJECTS = $$1
for(PROJECT, PROJECTS) {
INCLUDEPATH *= $$GLOBAL_PWD/$$PROJECT/include
}
export(INCLUDEPATH)
}
defineTest(implementationIncludes) {
interfaceIncludes($$1)
}
defineTest(transitiveIncludes) {
interfaceIncludes($$1)
}
defineTest(PythonQtIncludes) {
INCLUDEPATH += $$GLOBAL_PWD/PythonQt/PythonQt/src
export(INCLUDEPATH)
}
defineTest(links) {
LIBS *= -L$$GLOBAL_DESTDIR
LIBS *= -L$$DESTDIR
PROJECTS = $$1
for(PROJECT, PROJECTS) {
LIBS += -l$$PROJECT$$CONFIGURATION_SUFFIX
}
export(LIBS)
}
defineTest(installs) {
unix {
equals(TEMPLATE, lib) {
target.path = $$INSTALL_ROOT/usr/lib/
isEmpty(PUBLIC_HEADERS) {
headers.files = $$HEADERS
headers.path = $$INSTALL_ROOT/usr/include/$$PROJECT_NAME/
} else {
headers.files = $$PUBLIC_HEADERS
headers.path = $$INSTALL_ROOT/usr/include/$$PROJECT_NAME/
}
}
equals(TEMPLATE, app) {
target.path = $$INSTALL_ROOT/usr/bin/
}
INSTALLS += target
export(target.path)
equals(TEMPLATE, lib) {
INSTALLS += headers
export(headers.files)
export(headers.path)
}
export(INSTALLS)
}
HEADERS += $$PUBLIC_HEADERS
export(HEADERS)
}
defineTest(installAdditionalConfigs) {
FILES = $$1
unix {
additionalConfigs.files += $$FILES
additionalConfigs.path = $$INSTALL_ROOT/etc/trik/trikRuntime/
INSTALLS += additionalConfigs
export(additionalConfigs.path)
export(additionalConfigs.files)
export(INSTALLS)
}
}
defineTest(installAdditionalSharedFiles) {
FILES = $$1
unix {
additionalSharedFiles.files += $$FILES
additionalSharedFiles.path = $$INSTALL_ROOT/usr/share/trikRuntime/
INSTALLS *= additionalSharedFiles
export(additionalSharedFiles.path)
export(additionalSharedFiles.files)
export(INSTALLS)
}
}
defineTest(enableFlagIfCan) {
system(bash -c $$system_quote(echo $$shell_quote(int main(){return 0;}) | $$QMAKE_CXX $$QMAKE_CXXFLAGS $$1 -x c++ -c - -o $$system(bash -c mktemp) 2>/dev/null) ) {
QMAKE_CXXFLAGS += $$1
export(QMAKE_CXXFLAGS)
} else {
message(Cannot enable $$1)
}
}
} # GLOBAL_PRI_INCLUDED