forked from pasnox/qodeedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.pri
220 lines (183 loc) · 8.08 KB
/
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
###########################################################################################
## Created using Monkey Studio IDE v1.9.0.1 (1.9.0.1)
##
## Author : Filipe Azevedo aka Nox P@sNox <[email protected]>
## Project : functions.pri
## FileName : functions.pri
## Date : 2012-07-28T13:13:40
## License : LGPL3
## Comment : Creating using Monkey Studio RAD
## Home Page : https://github.com/pasnox/qmake-extensions
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
###########################################################################################
# Return a list of folders being absolute or relative depending of $$1
# $$1: The path where to list folders ($$1 is included)
# $$2: Optional parameter to forbid some filters
defineReplace( getFolders ) {
q_paths = $$1
q_filters = $$2 .svn
q_folders =
for( q_path, q_paths ) {
command = "ls -RQ1 \"$$q_path\" | grep \":\" | sed \"s/://g\" | sed \"s/'/\\\\\\'/g\""
macx|win32:command = ls -R1 \"$$q_path\" | grep \":\" | sed \"s/://g\" | sed \"s/\'/\\\\\\\'/g\" | sed \"s/\\(.*\\)/\\\"\\1\\\"/g\"
win32:!cb_win32:command = "for /D /R \"$$q_path\" %i in (*) do @echo \"%i\""
_q_folders = $$system( $$command )
_q_folders *= $$1
_q_folders = $$replace( _q_folders, $$Q_BACK_SLASH, $$Q_SLASH )
# loop paths
for( q_folder, _q_folders ) {
# check filters
filtered = false
for( q_filter, q_filters ) {
result = $$find( q_folder, $$q_filter )
!isEmpty( result ):filtered = true
}
isEqual( filtered, false ):exists( $$q_folder ) {
q_folders *= $$q_folder
}
}
}
#message( Getting folders for $$q_paths: $$q_folders )
return( $$q_folders )
}
# Identical to getFolders except that folders are returned relative to $$3
# $$1: The path where to list folders ($$1 is included)
# $$2: Make relative to $$2
# $$3: Replace $$2 by $$3 in final list
# $$4: Optional parameter to forbid some filters
defineReplace( getRelativeFolders ) {
q_folders = $$getFolders( $$1, $$4 )
q_folders = $$replace( q_folders, $$2, $$3 )
#message( Getting relative folders for $$q_paths: $$q_folders )
return( $$q_folders )
}
# Return the project build mode
defineReplace( buildMode ) {
CONFIG( debug, debug|release ) {
return( debug )
} else {
return( release )
}
}
# Return a generated target name according to build mode
# $$1: Base target name
# $$2: Optional build mode, if empty get using buildMode()
defineReplace( targetForMode ) {
q_target = $$1
q_mode = $$2
isEmpty( q_mode ):q_mode = $$buildMode()
isEqual( q_mode, release ) {
q_target = $$quote( $$q_target )
} else {
unix:q_target = $$quote( $$join( q_target, , , _debug ) )
else:q_target = $$quote( $$join( q_target, , , d ) )
}
return( $$q_target )
}
# Set the project template name
# $$1: Project template name
defineTest( setTemplate ) {
TEMPLATE = $$1
export( TEMPLATE )
}
# Set project target name
# $$1: Target name
# $$: Optional build mode, if empty get using buildMode()
defineTest( setTarget ) {
TARGET = $$targetForMode( $$1, $$2 )
export( TARGET )
}
# Set default directories for temporary files (object, rcc, ui, moc)
# $$1: The temporary directory to use as a base
defineTest( setTemporaryDirectories ) {
q_mode = $$buildMode()
OBJECTS_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/obj
UI_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/ui
MOC_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/moc
RCC_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/rcc
export( OBJECTS_DIR )
export( UI_DIR )
export( MOC_DIR )
export( RCC_DIR )
}
# Set project target directory
# $$1: The directory where to generate the project target
defineTest( setTargetDirectory ) {
DESTDIR = $$1
export( DESTDIR )
win32|cb_win32:CONFIG( shared ) {
DLLDESTDIR = $$1
export( DLLDESTDIR )
}
}
# Mimic an auto generated file where the content is replaced with qmake variable values
# $$1 = Template source file path
# $$2 = Generated target file path
defineTest( autoGenerateFile ) {
!build_pass {
generator.source = $${1}
generator.target = $${2}
# Replace slashes by back slashes on native windows host
win32:!cb_win32 {
generator.source = $$replace( generator.source, $${Q_SLASH}, $${Q_BACK_SLASH} )
generator.target = $$replace( generator.target, $${Q_SLASH}, $${Q_BACK_SLASH} )
}
# Delete existing file
exists( $${generator.target} ) {
win32:!cb_win32 {
system( "del $${generator.target}" )
} else {
system( "rm $${generator.target}" )
}
}
# Get template content
generator.content = $$cat( $${generator.source}, false )
# Find template variables name
#generator.variables = $$find( generator.content, "\\$\\$[^\s\$]+" )
# Generate the find variables command
generator.commands = "grep -E -i -o '\\$\\$[$${Q_OPENING_BRACE}]?[^ $${Q_QUOTE}$]+[$${Q_OPENING_BRACE}]?' $${generator.source}"
win32:!cb_win32:generator.commands = "grep command not available."
# Get template variables name
generator.variables = $$system( $${generator.commands} )
#message( cmd: $${generator.commands} )
#message( Variables: $$generator.variables )
# Transform each variable
for( variable, generator.variables ) {
name = $${variable}
name = $$replace( name, $${Q_QUOTE}, "" )
name = $$replace( name, $${Q_DOLLAR}, "" )
name = $$replace( name, $${Q_OPENING_BRACE}, "" )
name = $$replace( name, $${Q_CLOSING_BRACE}, "" )
generator.content = $$replace( generator.content, $${Q_DOLLAR}$${Q_DOLLAR}$${Q_OPENING_BRACE}$${name}$${Q_CLOSING_BRACE}, $$eval( $${name} ) )
generator.content = $$replace( generator.content, $${Q_DOLLAR}$${Q_DOLLAR}$${name}, $$eval( $${name} ) )
#message( --- Found: $$variable ($$name) - $$eval( $$name ) )
}
# escape characters that are special for windows echo command
win32:!cb_win32 {
generator.content = $$replace( generator.content, "\\^", "^^" )
generator.content = $$replace( generator.content, "<", "^<" )
generator.content = $$replace( generator.content, ">", "^>" )
generator.content = $$replace( generator.content, "\\|", "^|" )
generator.content = $$replace( generator.content, "&", "^&" )
# these should be escaped too but qmake values can't be ( or ) so we can't replace...
#generator.content = $$replace( generator.content, "\\(", "^(" )
#generator.content = $$replace( generator.content, "\\)", "^)" )
} else {
#mac:generator.content = $$replace( generator.content, $${Q_BACK_SLASH}, $${Q_BACK_SLASH}$${Q_BACK_SLASH}$${Q_BACK_SLASH} )
#else:generator.content = $$replace( generator.content, $${Q_BACK_SLASH}$${Q_BACK_SLASH}, $${Q_BACK_SLASH}$${Q_BACK_SLASH}$${Q_BACK_SLASH} )
generator.content = $$replace( generator.content, $${Q_BACK_SLASH}$${Q_BACK_SLASH}, $${Q_BACK_SLASH}$${Q_BACK_SLASH}$${Q_BACK_SLASH} )
generator.content = $$replace( generator.content, $${Q_QUOTE}, $${Q_BACK_SLASH}$${Q_QUOTE} )
}
message( Generating $${generator.target}... )
win32:!cb_win32 {
generator.content = $$replace( generator.content, "\\n", ">> $${generator.target} && echo." )
generator.commands = "echo ^ $${generator.content} >> $${generator.target}"
} else {
generator.commands = "echo \" $${generator.content}\" > $${generator.target}"
}
system( $${generator.commands} )
}
}