-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxconfig.py
239 lines (195 loc) · 8.05 KB
/
wxconfig.py
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
#
# SCons python library: wxWidgets configuration
#
# \author Willem van Engen <[email protected]>
# \date created 2006/10/16
# \version v 1.3.2.2 2006/11/24 14:26:47 willem Exp
#
import os, os.path
import re
import sys
import glob
import string
# Runs a system command and returns return value and output
def SystemBacktick(program):
# Run and return result
pipe = os.popen(program + ' 2>&1') # TODO: properly redirect stderr to stdout
output = pipe.read()
retcode = pipe.close() or 0
return [retcode, output]
def SystemWXConfig(env, args):
if sys.platform=='win32':
return SystemBacktick(env['wxconfig']+' '+args+env['wxconfig_postargs'])
else:
return SystemBacktick(env['wxconfig']+' '+args+env['wxconfig_postargs'])
# Check version of wx-config
# It succeeds with a warning if version check failed.
def CheckWXConfigVersion(context, version):
releaseversion = SystemWXConfig(context.env,'--release')[1]
try:
if float(version) > float(releaseversion.strip()):
return False
except (ValueError, TypeError):
context.Message('version check failed, but ok... ')
return True
return True
# Check if requested components exist in wxWidgets
def CheckWXConfigComponents(context, libraries):
# set components, method depending on wxWidgets version
if CheckWXConfigVersion(context, '2.6'):
context.env['wxconfig_postargs'] += ' '+string.join(libraries,',')
return SystemWXConfig(context.env, '--libs ')[0] == 0
# version 2.4 or below, only gl is an optional component with special flag
if 'gl' in libraries:
context.env['wxconfig'] += ' --gl-libs'
return SystemWXConfig(context.env, '--libs')[0] == 0
# no optional components can be checked, it should be allright
return True
# Find wx-config with suitable settings. It tries to use a debug configuration if requested,
# but reverts to release or default when that fails.
def CheckWXConfigWin(context, version, debug):
context.Message('Checking for wxWidgets >= %s... '%version)
# Compiler detection is needed for wx-config-win so it can produce
# suitable flags
cxx=context.env['CXX'];
# HACK for scons 1.2 on Windows where env['CXX'] == '$CC'
while cxx[0] == '$':
cxx = context.env[cxx[1:]];
# end HACK
# some helper variables
if cxx == 'cl':
compiler = "vc";
elif cxx == 'g++':
compiler = "gcc";
elif cxx == 'dmc': # TODO: Needs revision
compiler = "dmc";
context.env['wxconfig_compiler'] = compiler;
context.Message('Detecting compiler >= %s... '%compiler)
# Try to find it in path
wx_prog = context.env.WhereIs(context.env['wxconfig'])
if wx_prog == None:
# You could supply wx-config.exe as a fallback option.
#wx_prog = os.path.join('scons','wx-config')
context.Message('wx-config not found...')
return False
context.env['wxconfig'] = wx_prog
# Some environment variables are required for wx-config to work, check them.
if 'WXWIN' not in context.env['ENV']:
# TODO: maybe try some default location like "C:\Program Files\wxWidgets-*" or registry
context.Message('please set WXWIN in environment... ')
return False
# If there's no WXCFG, either there is only one config or we try to find out.
if 'WXCFG' not in context.env['ENV']:
# TODO: try to find one in some sensible order from alternatives
# Current guess is: visual studio static, non-unicode
# Try debugging version first if requested, else fallback to release
if debug:
args = "--debug=true"
if SystemWXConfig(context.env, args + ' --libs')[0] == 0:
return CheckWXConfigVersion(context, version)
# Non-debug
args = "--debug=false"
if SystemWXConfig(context.env, args + ' --libs')[0] == 0:
# this is the only configuration: use it
return CheckWXConfigVersion(context, version)
context.Message('please set WXCFG in environment... ')
return False
# WXCFG is in environment, nice.
# Try a debugging version if requested: postfix WXCFG with 'd'
if debug:
oldwxcfg = context.env['ENV']['WXCFG']
context.env['ENV']['WXCFG'] += 'd'
if SystemWXConfig(context.env,'--libs')[0] == 0:
return CheckWXConfigVersion(context, version)
# Failed: revert to plain WXCFG, use existing environment
context.env['ENV']['WXCFG'] = oldwxcfg
if SystemWXConfig(context.env,'--libs')[0] == 0:
return CheckWXConfigVersion(context, version)
# Everything failed ...
return False
def CheckWXConfigPosixFind(context, debug):
# Find a wx-config compatible pathname
# wx*-config --> wx*-[0-9]+\.[0-9]+-config / wx<platform>-<version>-config
dbglist = []
rellist = []
cfgre = re.compile('.*?\/wx(\w+?)(d?)-(\d+\.\d+)-config')
for dir in context.env['ENV']['PATH'].split(':'):
for cfgprog in glob.glob(os.path.join(dir,'wx*-config')):
m = cfgre.match(cfgprog)
if m and not m.group(1) == 'base':
# add to either debug or release list
if m.group(2) == '':
rellist.append(cfgprog)
else:
dbglist.append(cfgprog)
# TODO: sort on version
# Now pick the right one
if debug and len(dbglist)>0:
return dbglist[0]
if len(rellist)>0:
return rellist[0]
# Too bad
return False
def CheckWXConfigPosix(context, version, debug):
# TODO: try several wx-config names
context.Message('Checking for wxWidgets >= %s... '%version)
# If supplied wx-config doesn't work, try to find another one
if SystemWXConfig(context.env,'--libs')[0] != 0:
wx_prog = CheckWXConfigPosixFind(context, debug)
if not wx_prog:
context.Message('not found... ')
return False
context.env['wxconfig'] = wx_prog
if not debug:
return CheckWXConfigVersion(context, version)
# use `wx-config --debug` if it's in its help
helpoutput = SystemWXConfig(context.env,'--help')[1]
if helpoutput.find('--debug') != -1:
context.Message('--debug')
if SystemWXConfig(context.env,'--debug --libs')[0] == 0:
context.env['wxconfig'] = context.env['wxconfig'] +' --debug'
return CheckWXConfigVersion(context, version)
# If it's plain wx-config, we may need to look for another one for debugging
if context.env['wxconfig'] == 'wx-config':
wx_prog = CheckWXConfigPosixFind(context, debug)
if wx_prog:
context.env['wxconfig'] = wx_prog
# TODO: possibly warning message when using release instead of debug
return CheckWXConfigVersion(context, version)
def CheckWXConfig(context, version, components, debug = False):
context.env['wxconfig_postargs']=''
build_platform=context.env['build_platform']
target_platform=context.env['target_platform']
# Get wx-config invocation and check version
if build_platform=='win32' and target_platform=='win32':
res = CheckWXConfigWin(context, version, debug)
else:
res = CheckWXConfigPosix(context, version, debug)
# Make sure we have the required libraries
if res:
res = CheckWXConfigComponents(context, components)
if not res:
context.Message('not all components found ['+string.join(components,',')+']... ')
context.Result(res)
return res
def ParseWXConfig(env):
build_platform=env['build_platform']
target_platform=env['target_platform']
# Windows doesn't work with ParseConfig (yet) :(
if build_platform=='win32' and target_platform=='win32':
# Use wx-config, yay!
# ParseConfig() on windows is broken, so the following is done instead
compilerFlag = "--compiler=%s " % env['wxconfig_compiler']
cflags = SystemWXConfig(env,compilerFlag + '--cxxflags')[1]
env.AppendUnique(CPPFLAGS = cflags.strip().split(' '))
libs = SystemWXConfig(env,compilerFlag + '--libs')[1]
env.AppendUnique(LINKFLAGS = libs.strip().split(' '))
rcflags = SystemWXConfig(env,compilerFlag + '--rcflags')[1]
env.AppendUnique(RCFLAGS = rcflags.strip().split(' '));
elif target_platform == 'darwin':
# MacOSX doesn't handle '-framework foobar' correctly, do that separately.
env.ParseConfig(env['wxconfig']+' --cxxflags'+env['wxconfig_postargs'])
env.AppendUnique(LINKFLAGS=SystemWXConfig(env,'--libs'+env['wxconfig_postargs'])[1])
else:
# Here ParseConfig should really work
env.ParseConfig(env['wxconfig']+' --cxxflags --libs'+env['wxconfig_postargs'])