forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.pri
156 lines (142 loc) · 5.82 KB
/
configure.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
#Designed by Wang Bin(Lucas Wang). 2013 <[email protected]>
### ONLY FOR Qt4. common.pri must be included before it so that write_file() can be used#######
### .qmake.cache MUST be created before it!
####ASSUME compile tests and .qmake.cache is in project out root dir
# Ensure that a cache is present. If none was found on startup, this will create
# one in the build directory of the project which loads this feature.
#cache()
QMAKE_CONFIG_LOG = $$dirname(_QMAKE_CACHE_QT4_)/config.log
QMAKE_CONFIG_TESTS_DIR = $$_PRO_FILE_PWD_/config.tests
lessThan(QT_MAJOR_VERSION, 5) {
defineTest(cache) {
!isEmpty(4): error("cache(var, [set|add|sub] [transient] [super], [srcvar]) requires one to three arguments.")
!exists($$_QMAKE_CACHE_QT4_) {
log("Info: creating cache file $$_QMAKE_CACHE_QT4_")
write_file($$_QMAKE_CACHE_QT4_)|return(false)
}
isEmpty(1):return(true)
!isEmpty(2):isEqual(2, set):mode_set=1
isEmpty(3) {
isEmpty(mode_set):error("cache(): modes other than 'set' require a source variable.")
srcvar = $$1
srcval = $$join($$srcvar, $$escape_expand(\\t)) ##TODO: how to use white space?
} else {
srcvar = $$3
dstvar = $$1
#We need the ref value, so the function's parameter must be a var name. join() is!
srcval = $$join($$srcvar, $$escape_expand(\\t)) ##TODO: how to use white space?
isEqual(2, add) {
varstr = "$$1 = $$srcval" ##TODO: how to use white space?
} else:isEqual(2, sub) {
varstr = "$$1 -= $$srcval"
} else:isEqual(2, set) {
##TODO: erase existing VAR in cache
varstr = "$$1 = $$srcval"
} else {
error("cache(): invalid flag $$2.")
}
}
#log("varstr: $$varstr")
##TODO: remove existing lines contain $$srcvar
#because write_file() will write 1 line for each value(separated by space), so the value must be closed with "", then it's 1 value, not list
#erase the existing var and value pair
win32 {#:isEmpty(QMAKE_SH) { #windows sucks. can not access the cache
} else {
#use sed for unix or msys
#convert '/' to '\/' for sed
srcval ~= s,/,\\/,g
srcval ~= s,\\ ,\\\\ ,g #for sed regexp. ' ' in qmake is '\ ' ?
system("sed -i -r '/.*$${dstvar}.*$${srcval}.*/d' $$_QMAKE_CACHE_QT4_ >/dev/null")
}
write_file($$_QMAKE_CACHE_QT4_, varstr, append)
}
} #Qt4
QMAKE_MAKE = $$(MAKE)
!isEmpty(QMAKE_MAKE) {
# We were called recursively. Use the right make, as MAKEFLAGS may be set as well.
} equals(MAKEFILE_GENERATOR, UNIX) {
QMAKE_MAKE = make
} else:equals(MAKEFILE_GENERATOR, MINGW) {
!equals(QMAKE_HOST.os, Windows): \
QMAKE_MAKE = make
else: \
QMAKE_MAKE = mingw32-make
} else:if(equals(MAKEFILE_GENERATOR, MSVC.NET)|equals(MAKEFILE_GENERATOR, MSBUILD)) {
QMAKE_MAKE = nmake
} else {
# error: the reset qmake will not work and displays nothing in qtc
warning("Configure tests are not supported with the $$MAKEFILE_GENERATOR Makefile generator.")
}
defineTest(qtRunLoggedCommand) {
msg = " $$1"
write_file($$QMAKE_CONFIG_LOG, msg, append)#|error("write file failed") #for debug
system("$$1 >> \"$$QMAKE_CONFIG_LOG\" 2>&1")|return(false)
return(true)
}
# Try to build the test project in $$QMAKE_CONFIG_TESTS_DIR/$$1
# ($$_PRO_FILE_PWD_/config.tests/$$1 by default).
#
# If the test passes, config_$$1 will be added to CONFIG.
# The result is automatically cached. Use of cached results
# can be suppressed by passing CONFIG =recheck to qmake.
#
# Returns: true iff the test passes
defineTest(qtCompileTest) {
positive = config_$$1
done = done_config_$$1
$$done:!recheck {
$$positive:return(true)
return(false)
}
log("Checking for $${1}... ")
msg = "executing config test $$1"
write_file($$QMAKE_CONFIG_LOG, msg, append)
test_dir = $$QMAKE_CONFIG_TESTS_DIR/$$1
test_out_dir = $$shadowed($$test_dir)
#system always call win32 cmd in windows, so we need "cd /d" to ensure success cd to a different partition
contains(QMAKE_HOST.os,Windows):test_cmd_base = "cd /d $$system_quote($$system_path($$test_out_dir)) &&"
else: test_cmd_base = "cd $$system_quote($$system_path($$test_out_dir)) &&"
# On WinRT we need to change the entry point as we cannot create windows applications
winrt {
qmake_configs = " \"QMAKE_LFLAGS =/ENTRY:main\""
}
# Disable qmake features which are typically counterproductive for tests
qmake_configs = "\"CONFIG -= qt debug_and_release app_bundle lib_bundle\""
iphoneos: qmake_configs = "\"CONFIG =iphoneos\""
iphonesimulator: qmake_configs = "\"CONFIG =iphonesimulator\""
# Clean up after previous run
exists($$test_out_dir/Makefile):qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE distclean")
mkpath($$test_out_dir)#|error("Aborting.") #mkpath currently return false, do not know why
SPEC =
!isEmpty(QMAKESPEC): SPEC = "-spec $$QMAKESPEC"
qtRunLoggedCommand("$$test_cmd_base $$system_quote($$system_path($$QMAKE_QMAKE)) $$SPEC $$qmake_configs $$system_path($$test_dir)") {
qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE") {
log("yes$$escape_expand(\\n)")
msg = "test $$1 succeeded"
write_file($$QMAKE_CONFIG_LOG, msg, append)
!$$positive {
CONFIG = $$positive
cache(CONFIG, add, positive)
}
!$$done {
CONFIG = $$done
cache(CONFIG, add, done)
}
export(CONFIG)
return(true)
}
}
log("no$$escape_expand(\\n)")
msg = "test $$1 FAILED"
write_file($$QMAKE_CONFIG_LOG, msg, append)
$$positive {
CONFIG -= $$positive
cache(CONFIG, sub, positive)
}
!$$done {
CONFIG = $$done
cache(CONFIG, add, done)
}
export(CONFIG)
return(false)
}