-
Notifications
You must be signed in to change notification settings - Fork 239
/
NifSkope_functions.pri
272 lines (219 loc) · 5.63 KB
/
NifSkope_functions.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
###############################
## Functions
###############################
# Shortcut for ends of commands
nt = $$escape_expand(\\n\\t)
# Sanitize filepath for OS
defineReplace(syspath) {
path = $$1
path ~= s,/,$${QMAKE_DIR_SEP},g
return($$path)
}
# Get command for sed
defineReplace(getSed) {
sedbin = ""
win32 {
PROG = C:/Program Files (x86)
!exists($$PROG) {
PROG = C:/Program Files
}
GNUWIN32 = $${PROG}/GnuWin32/bin
CYGWIN = C:/cygwin/bin
CYGWIN64 = C:/cygwin64/bin
SEDPATH = /sed.exe
exists($${GNUWIN32}$${SEDPATH}) {
sedbin = $${GNUWIN32}$${SEDPATH}
} else:exists($${CYGWIN}$${SEDPATH}) {
sedbin = $${CYGWIN}$${SEDPATH}
} else:exists($${CYGWIN64}$${SEDPATH}) {
sedbin = $${CYGWIN64}$${SEDPATH}
} else {
#message(Neither GnuWin32 or Cygwin were found)
sedbin = $$system(where sed 2> NUL)
}
!isEmpty(sedbin) {
sedbin = \"$${sedbin}\"
}
}
unix {
sedbin = sed
}
return($$sedbin)
}
# Get command for 7z
defineReplace(get7z) {
_7zbin = ""
win32 {
_7zbin = C:/Program Files/7-Zip/7z.exe
!exists($$_7zbin) {
_7zbin = C:/Program Files (x86)/7-Zip/7z.exe
}
!exists($$_7zbin) {
return()
}
}
unix {
# TODO: Untested
_7zbin = $$system(which unzip 2>/dev/null)
}
return(\"$$_7zbin\")
}
_VERSION =
_REVISION =
# Retrieve NifSkope version
defineReplace(getVersion) {
# I turned this into a function because I didn't want
# the Version/Revision macros to have to straddle the
# includes. (VERSION needed to come before, REVISION after)
!isEmpty(_VERSION):return($$_VERSION)
_VERSION = $$cat(build/VERSION)
export(_VERSION)
return($$_VERSION)
}
# Retrieve NifSkope revision
defineReplace(getRevision) {
!isEmpty(_REVISION):return($$_REVISION)
GIT_HEAD = $$cat(.git/HEAD)
# At this point GIT_HEAD either contains commit hash, or symbolic ref:
# GIT_HEAD = 303c05416ecceb3368997c86676a6e63e968bc9b
# GIT_HEAD = ref: refs/head/feature/blabla
contains(GIT_HEAD, "ref:") {
# Resolve symbolic ref
GIT_HEAD = .git/$$member(GIT_HEAD, 1)
# GIT_HEAD now points to the file containing hash,
# e.g. .git/refs/head/feature/blabla
exists($$GIT_HEAD) {
GIT_HEAD = $$cat($$GIT_HEAD)
} else {
clear(GIT_HEAD)
}
}
count(GIT_HEAD, 1) {
# Single component, hopefully the commit hash
# Fetch first seven characters (abbreviated hash)
GIT_HEAD ~= s/^(.......).*/\\1/
_REVISION = $$GIT_HEAD
export(_REVISION)
return($$_REVISION)
}
return()
}
# Format Qt Version
defineReplace(QtHex) {
maj = $$QT_MAJOR_VERSION
min = $$QT_MINOR_VERSION
pat = $$QT_PATCH_VERSION
greaterThan(min, 9) {
equals(min, 10):min=a
equals(min, 11):min=b
equals(min, 12):min=c
equals(min, 13):min=d
equals(min, 14):min=e
equals(min, 15):min=f
greaterThan(min, 15):min=f
# Stop. They won't go this high.
}
greaterThan(pat, 9) {
equals(pat, 10):pat=a
equals(pat, 11):pat=b
equals(pat, 12):pat=c
equals(pat, 13):pat=d
equals(pat, 14):pat=e
equals(pat, 15):pat=f
greaterThan(pat, 15):pat=f
# Stop. They won't go this high.
}
return(0x0$${maj}0$${min}0$${pat})
}
# Format string for Qt DLL
DLLSTRING = $$quote(Qt5%1)
CONFIG(debug, debug|release) {
DLLEXT = $$quote(d.dll)
} else {
DLLEXT = $$quote(.dll)
}
# Returns list of absolute paths to Qt DLLs required by project
defineReplace(QtBins) {
modules = $$eval(QT)
list =
for(m, modules) {
list += $$sprintf($$[QT_INSTALL_BINS]/$${DLLSTRING}, $$m)$${DLLEXT}
}
*-g++ {
# Copies libgcc*-*, libstdc++-*, libwinpthread-*
# Note: As of Qt 5.5, changed `lib*` to `lib*-*` in order to avoid unneeded libs.
list += \
$$[QT_INSTALL_BINS]/lib*-*.dll
}
return($$list)
}
# Copies the given files to the destination directory
defineTest(copyFiles) {
files = $$1
subdir = $$2
abs = $$3
rename = $$4 # for renaming ONE file, no wildcards
regexp = $$5 # for file extension renaming, no wildcards
!isEmpty(rename):!isEmpty(regexp):message(WARNING: Cannot use both 4th and 5th param of copyFiles)
unset(oldext)
unset(newext)
unset(newfile)
# If `abs` wasn't passed in, make it false
# (For whatever reason true/false don't pass in as true/false
# even after using $$eval())
isEmpty(abs) {
abs = false
} else {
abs = true
}
ddir = $$syspath($${DESTDIR}$${QMAKE_DIR_SEP}$${subdir})
QMAKE_POST_LINK += $$sprintf($$QMAKE_MKDIR_CMD, $${ddir}) $$nt
for(FILE, files) {
fileabs = $${PWD}$${QMAKE_DIR_SEP}$${FILE}
$$abs {
fileabs = $${FILE}
}
!isEmpty(regexp) {
oldext = $$section(regexp, :, 0, 0)
newext = $$section(regexp, :, 1, 1)
newfile = $$section(FILE, /, -1)
newfile ~= s,.$${oldext},.$${newext},g
}
fileabs = $$syspath($${fileabs})
QMAKE_POST_LINK += $$QMAKE_COPY $${fileabs} $${ddir}$${rename}$${newfile} $$nt
}
export(QMAKE_POST_LINK)
unset(ddir)
}
# Copies the given dirs to the destination directory
defineTest(copyDirs) {
dirs = $$1
subdir = $$2
abs = $$3
# If `abs` wasn't passed in, make it false
# (For whatever reason true/false don't pass in as true/false
# even after using $$eval())
isEmpty(abs) {
abs = false
} else {
abs = true
}
ddir = $$syspath($${DESTDIR}$${QMAKE_DIR_SEP}$${subdir})
QMAKE_POST_LINK += $$sprintf($$QMAKE_MKDIR_CMD, $${ddir}) $$nt
for(DIR, dirs) {
dirabs = $${PWD}$${QMAKE_DIR_SEP}$${DIR}
$$abs {
dirabs = $${FILE}
}
dirabs = $$syspath($${dirabs})
# Fix copy for subdir on unix, also assure clean subdirs (no extra files)
!isEmpty(subdir) {
win32:*msvc*:QMAKE_POST_LINK += rd /s /q $${ddir} $$nt
else:!unix:QMAKE_POST_LINK += rm -rf $${ddir} $$nt
unix:QMAKE_POST_LINK += rm -rf $${ddir} $$nt
}
QMAKE_POST_LINK += $$QMAKE_COPY_DIR $${dirabs} $${ddir} $$nt
}
export(QMAKE_POST_LINK)
unset(ddir)
}