New Wiimote Plugin: Fix Emulated Wiimote Problem.(fixes issue 3230) Made the "Connect...
[dolphin.git] / SConstruct
blob2ca4d5a804730a5c2d35530a2023ca4baac26978
1 # -*- python -*-
3 import os
4 import sys
5 import platform
7 # Home made tests
8 from SconsTests import utils
9 from SconsTests import wxconfig
11 # Some features need at least SCons 1.2
12 EnsureSConsVersion(1, 2)
14 # Construction presets for platform
15 env = Environment(ENV = os.environ)
17 # Handle command line options
18 vars = Variables('args.cache')
20 vars.AddVariables(
21 BoolVariable('verbose', 'Set to show compilation lines', False),
22 BoolVariable('bundle', 'Set to create distribution bundle', False),
23 BoolVariable('lint', 'Set for lint build (fail on warnings)', False),
24 BoolVariable('nowx', 'Set for building without wxWidgets', False),
25 PathVariable('wxconfig', 'Path to wxconfig', None),
26 EnumVariable('flavor', 'Choose a build flavor', 'release', allowed_values =
27 ('release','devel','debug','fastlog','prof'), ignorecase = 2),
30 if env['PLATFORM'] == 'posix': vars.AddVariables(
31 PathVariable('destdir', 'Temporary install location (for package building)',
32 None, PathVariable.PathAccept),
33 EnumVariable('install', 'Choose a local or global installation', 'local',
34 allowed_values = ('local', 'global'), ignorecase = 2),
35 PathVariable('prefix', 'Installation prefix (only used for a global build)',
36 '/usr', PathVariable.PathAccept),
37 PathVariable('userdir', 'Set the name of the user data directory in home',
38 '.dolphin-emu', PathVariable.PathAccept),
39 BoolVariable('opencl', 'Build with OpenCL', False),
40 EnumVariable('pgo', 'Profile-Guided Optimization (generate or use)', 'none',
41 allowed_values = ('none', 'generate', 'use'), ignorecase = 2),
42 BoolVariable('shared_glew', 'Use system shared libGLEW', True),
43 BoolVariable('shared_lzo', 'Use system shared liblzo2', True),
44 BoolVariable('shared_sdl', 'Use system shared libSDL', True),
45 BoolVariable('shared_sfml', 'Use system shared libsfml-network', True),
46 BoolVariable('shared_soil', 'Use system shared libSOIL', True),
47 BoolVariable('shared_zlib', 'Use system shared libz', True),
48 PathVariable('CC', 'The C compiler', 'gcc', PathVariable.PathAccept),
49 PathVariable('CXX', 'The C++ compiler', 'g++', PathVariable.PathAccept),
52 # Save the given command line options
53 vars.Update(env)
54 vars.Save('args.cache', env)
56 # Die on unknown variables
57 unknown = vars.UnknownVariables()
58 if unknown:
59 print "Unknown variables:", unknown.keys()
60 Exit(1)
62 # Verbose compile
63 if not env['verbose']:
64 env['ARCOMSTR'] = "Archiving $TARGET"
65 env['ASCOMSTR'] = "Assembling $TARGET"
66 env['ASPPCOMSTR'] = "Assembling $TARGET"
67 env['CCCOMSTR'] = "Compiling $TARGET"
68 env['CXXCOMSTR'] = "Compiling $TARGET"
69 env['LINKCOMSTR'] = "Linking $TARGET"
70 env['RANLIBCOMSTR'] = "Indexing $TARGET"
71 env['SHCCCOMSTR'] = "Compiling $TARGET"
72 env['SHCXXCOMSTR'] = "Compiling $TARGET"
73 env['SHLINKCOMSTR'] = "Linking $TARGET"
74 env['TARCOMSTR'] = "Creating $TARGET"
76 if not env['flavor'] == 'debug':
77 env['CCFLAGS'] += ['-O3']
78 if env['flavor'] == 'release':
79 env['CCFLAGS'] += ['-fomit-frame-pointer']
80 elif not env['flavor'] == 'fastlog':
81 env['CCFLAGS'] += ['-ggdb']
82 env['CCFLAGS'] += ['-fno-exceptions', '-fno-strict-aliasing']
83 if env['CCVERSION'] >= '4.2.0':
84 env['CCFLAGS'] += ['-fvisibility=hidden']
85 env['CXXFLAGS'] += ['-fvisibility-inlines-hidden']
87 if env['lint']:
88 env['CCFLAGS'] += ['-Werror']
89 env['CCFLAGS'] += ['-Wall', '-Wextra']
90 env['CCFLAGS'] += ['-Wno-missing-field-initializers', '-Wno-unused-parameter']
91 env['CCFLAGS'] += ['-Wpacked', '-Wpointer-arith', '-Wshadow', '-Wwrite-strings']
92 if env['CCVERSION'] < '4.2.0':
93 env['CCFLAGS'] += ['-Wno-pragmas']
94 if env['CCVERSION'] >= '4.3.0':
95 env['CCFLAGS'] += ['-Wno-array-bounds', '-Wno-unused-result']
97 env['CPPDEFINES'] = []
98 if env['flavor'] == 'debug':
99 env['CPPDEFINES'] += ['_DEBUG']
100 elif env['flavor'] == 'fastlog':
101 env['CPPDEFINES'] += ['DEBUGFAST']
102 env['CPPPATH'] = ['#Source/PluginSpecs']
103 env['LIBPATH'] = []
104 env['LIBS'] = []
106 # Object files
107 env['build_dir'] = 'Build' + os.sep + platform.system() + \
108 '-' + platform.machine() + '-' + env['flavor']
110 # Static libs go here
111 env['local_libs'] = '#' + env['build_dir'] + os.sep + 'libs' + os.sep
113 # Default install path
114 if not env.has_key('install') or env['install'] == 'local':
115 env['prefix'] = 'Binary' + os.sep + platform.system() + \
116 '-' + platform.machine()
117 if env['flavor'] == 'debug' or env['flavor'] == 'prof':
118 env['prefix'] += '-' + env['flavor']
120 rev = utils.GenerateRevFile(env['flavor'], '.', None)
122 # OS X specifics
123 if sys.platform == 'darwin':
124 ccld = ['-arch', 'x86_64', '-arch', 'i386', '-mmacosx-version-min=10.5']
125 env['CCFLAGS'] += ccld
126 env['CCFLAGS'] += ['-msse3']
127 env['CC'] = "gcc-4.2 -ObjC"
128 env['CXX'] = "g++-4.2 -ObjC++"
129 #env['FRAMEWORKPATH'] += [
130 # '/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks',
131 # '/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks']
132 env['FRAMEWORKS'] += ['AppKit', 'CoreFoundation', 'CoreServices']
133 env['FRAMEWORKS'] += ['AudioUnit', 'CoreAudio']
134 env['FRAMEWORKS'] += ['IOBluetooth', 'IOKit', 'OpenGL']
135 env['LIBPATH'] += ['/Developer/SDKs/MacOSX10.5.sdk/usr/lib']
136 env['LIBS'] = ['gcc_s.10.5', 'iconv']
137 env['LINKFLAGS'] += ccld
138 env['LINKFLAGS'] += ['-Wl,-search_paths_first', '-Wl,-Z']
139 env['LINKFLAGS'] += [
140 '-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks',
141 '-F/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks']
143 if platform.mac_ver()[0] < '10.6.0':
144 env['HAVE_OPENCL'] = 0
145 else:
146 env['CCFLAGS'] += ['-Wextra-tokens', '-Wnewline-eof']
147 env['HAVE_OPENCL'] = 1
148 env['FRAMEWORKSFLAGS'] = ['-weak_framework', 'OpenCL']
150 if env['nowx']:
151 env['HAVE_WX'] = 0
152 else:
153 wxenv = env.Clone(LIBPATH = '')
154 conf = wxenv.Configure(conf_dir = None, log_file = None,
155 custom_tests = {'CheckWXConfig' : wxconfig.CheckWXConfig})
156 env['HAVE_WX'] = \
157 conf.CheckWXConfig(2.9, 'aui adv core base gl'.split(),
158 env['flavor'] == 'debug')
159 conf.Finish()
160 if not env['HAVE_WX']:
161 print "wxWidgets 2.9 not found using " + env['wxconfig']
162 Exit(1)
163 wxconfig.ParseWXConfig(wxenv)
164 env['CPPDEFINES'] += ['__WXOSX_COCOA__']
165 env['CPPPATH'] = wxenv['CPPPATH']
166 if not wxenv['CPPDEFINES'].count('WXUSINGDLL'):
167 env['FRAMEWORKS'] = wxenv['FRAMEWORKS']
168 env['LIBPATH'] += wxenv['LIBPATH']
169 env['LIBS'] = wxenv['LIBS']
171 env['CPPPATH'] += ['#Externals']
172 env['FRAMEWORKPATH'] += ['Externals/Cg']
173 env['FRAMEWORKS'] += ['Cg']
174 env['shared_zlib'] = True
176 env['data_dir'] = '#' + env['prefix'] + '/Dolphin.app/Contents/Resources'
177 env['plugin_dir'] = '#' + env['prefix'] + '/Dolphin.app/Contents/PlugIns'
179 if env['bundle']:
180 app = env['prefix'] + '/Dolphin.app'
181 dmg = env['prefix'] + '/Dolphin-r' + rev + '.dmg'
182 env.Command(dmg, app, 'rm -f ' + dmg +
183 ' && hdiutil create -srcfolder ' + app + ' -format UDBZ ' + dmg +
184 ' && hdiutil internet-enable -yes ' + dmg)
186 elif sys.platform == 'win32':
187 pass
189 else:
190 env['CCFLAGS'] += ['-fPIC', '-msse2']
191 env['CPPPATH'].insert(0, '#') # Make sure we pick up our own config.h
192 if sys.platform == 'linux2':
193 env['CPPDEFINES'] += [('_FILE_OFFSET_BITS', 64), '_LARGEFILE_SOURCE']
194 env['CXXFLAGS'] += ['-Wno-deprecated'] # XXX <hash_map>
195 env['LINKFLAGS'] += ['-pthread']
196 env['RPATH'] = []
198 conf = env.Configure(config_h = "#config.h", custom_tests = {
199 'CheckPKG' : utils.CheckPKG,
200 'CheckPKGConfig' : utils.CheckPKGConfig,
201 'CheckPortaudio' : utils.CheckPortaudio,
202 'CheckSDL' : utils.CheckSDL,
203 'CheckWXConfig' : wxconfig.CheckWXConfig,
206 if not conf.CheckPKGConfig('0.15.0'):
207 print "Can't find pkg-config, some tests will fail"
209 if env['shared_glew']:
210 env['shared_glew'] = conf.CheckPKG('GLEW')
211 if env['shared_sdl']:
212 env['shared_sdl'] = conf.CheckPKG('SDL')
213 if env['shared_zlib']:
214 env['shared_zlib'] = conf.CheckPKG('z')
215 if env['shared_lzo']:
216 env['shared_lzo'] = conf.CheckPKG('lzo2')
217 # TODO: Check the version of sfml. It should be at least version 1.5
218 if env['shared_sfml']:
219 env['shared_sfml'] = conf.CheckPKG('sfml-network') and \
220 conf.CheckCXXHeader("SFML/Network/Ftp.hpp")
221 if env['shared_soil']:
222 env['shared_soil'] = conf.CheckPKG('SOIL')
223 for var in env.items():
224 if var[0].startswith('shared_') and var[1] == False:
225 print "Shared library " + var[0][7:] + " not detected, " \
226 "falling back to the static library"
228 if env['nowx']:
229 env['HAVE_WX'] = 0
230 else:
231 env['HAVE_WX'] = conf.CheckWXConfig(2.8, 'aui adv core base'.split(),
232 env['flavor'] == 'debug')
233 conf.Define('HAVE_WX', env['HAVE_WX'])
234 wxconfig.ParseWXConfig(env)
235 if not env['HAVE_WX']:
236 print "wxWidgets not found - see config.log"
237 Exit(1)
239 env['HAVE_BLUEZ'] = conf.CheckPKG('bluez')
240 conf.Define('HAVE_BLUEZ', env['HAVE_BLUEZ'])
242 env['HAVE_ALSA'] = conf.CheckPKG('alsa')
243 conf.Define('HAVE_ALSA', env['HAVE_ALSA'])
244 env['HAVE_AO'] = conf.CheckPKG('ao')
245 conf.Define('HAVE_AO', env['HAVE_AO'])
246 env['HAVE_OPENAL'] = conf.CheckPKG('openal')
247 conf.Define('HAVE_OPENAL', env['HAVE_OPENAL'])
248 env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890)
249 conf.Define('HAVE_PORTAUDIO', env['HAVE_PORTAUDIO'])
250 env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse')
251 conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO'])
253 env['HAVE_X11'] = conf.CheckPKG('x11')
254 env['HAVE_XRANDR'] = env['HAVE_X11'] and conf.CheckPKG('xrandr')
255 conf.Define('HAVE_XRANDR', env['HAVE_XRANDR'])
256 conf.Define('HAVE_X11', env['HAVE_X11'])
258 if env['HAVE_WX'] and not conf.CheckPKG('gtk+-2.0'):
259 print "gtk+-2.0 developement headers not detected"
260 print "gtk+-2.0 is required to build the WX GUI"
261 Exit(1)
263 if not conf.CheckPKG('GL'):
264 print "Must have OpenGL to build"
265 Exit(1)
266 if not conf.CheckPKG('GLU'):
267 print "Must have GLU to build"
268 Exit(1)
269 if not conf.CheckPKG('Cg') and sys.platform == 'linux2':
270 print "Must have Cg toolkit from NVidia to build"
271 Exit(1)
272 if not conf.CheckPKG('CgGL') and sys.platform == 'linux2':
273 print "Must have CgGL to build"
274 Exit(1)
276 if env['opencl']:
277 env['HAVE_OPENCL'] = conf.CheckPKG('OpenCL')
278 conf.Define('HAVE_OPENCL', env['HAVE_OPENCL'])
279 else:
280 env['HAVE_OPENCL'] = 0
282 # PGO - Profile Guided Optimization
283 if env['pgo'] == 'generate':
284 env['CCFLAGS'] += ['-fprofile-generate']
285 env['LINKFLAGS'] += ['-fprofile-generate']
286 if env['pgo'] == 'use':
287 env['CCFLAGS'] += ['-fprofile-use']
288 env['LINKFLAGS'] += ['-fprofile-use']
290 # Profiling
291 if env['flavor'] == 'prof':
292 proflibs = ['/usr/lib/oprofile', '/usr/local/lib/oprofile']
293 env['LIBPATH'] += ['proflibs']
294 env['RPATH'] += ['proflibs']
295 if conf.CheckPKG('opagent'):
296 conf.Define('USE_OPROFILE', 1)
297 else:
298 print "Can't build prof without oprofile, disabling"
300 tarname = 'dolphin-' + rev
301 env['TARFLAGS'] = '-cj'
302 env['TARSUFFIX'] = '.tar.bz2'
304 if env['install'] == 'local':
305 env['binary_dir'] = '#' + env['prefix']
306 env['data_dir'] = '#' + env['prefix']
307 env['plugin_dir'] = '#' + env['prefix'] + '/plugins'
308 if env['bundle']:
309 env.Tar(tarname, env['prefix'])
310 else:
311 env['prefix'] = Dir(env['prefix']).abspath
312 env['binary_dir'] = env['prefix'] + '/bin'
313 env['data_dir'] = env['prefix'] + "/share/dolphin-emu"
314 env['plugin_dir'] = env['prefix'] + '/lib/dolphin-emu'
315 conf.Define('DATA_DIR', "\"" + env['data_dir'] + "/\"")
316 conf.Define('LIBS_DIR', "\"" + env['prefix'] + '/lib/' + "\"")
317 # Setup destdir for package building
318 # Warning: The program will not run from this location.
319 # It is assumed the package will later install it to the prefix.
320 if env.has_key('destdir'):
321 env['destdir'] = Dir(env['destdir']).abspath
322 env['binary_dir'] = env['destdir'] + env['binary_dir']
323 env['data_dir'] = env['destdir'] + env['data_dir']
324 env['plugin_dir'] = env['destdir'] + env['plugin_dir']
325 env['prefix'] = env['destdir'] + env['prefix']
326 if env['bundle']:
327 env.Command(tarname + env['TARSUFFIX'], env['prefix'],
328 'tar ' + env['TARFLAGS'] + 'C ' + env['destdir'] + \
329 ' -f ' + tarname + env['TARSUFFIX'] + ' ' + \
330 env['prefix'].split(env['destdir'], 1)[1][1:])
332 conf.Define('USER_DIR', "\"" + env['userdir'] + "\"")
334 # After all configuration tests are done
335 conf.Finish()
337 env.Alias('install', env['prefix'])
339 # Local (static) libraries must be first in the search path for the build in
340 # order that they can override system libraries, but they must not be found
341 # during autoconfiguration as they will then be detected as system libraries.
342 env['LIBPATH'].insert(0, env['local_libs'])
344 dirs = [
345 'Externals/Bochs_disasm',
346 #'Externals/CLRun',
347 'Externals/Lua',
348 'Externals/MemcardManager',
349 'Externals/WiiUse/Src',
350 'Externals/GLew',
351 'Externals/LZO',
352 #'Externals/OpenAL',
353 'Externals/SDL',
354 'Externals/SOIL',
355 'Externals/SFML/src',
356 #'Externals/wxWidgets',
357 'Externals/zlib',
358 'Source/Core/AudioCommon/Src',
359 'Source/Core/Common/Src',
360 'Source/Core/Core/Src',
361 'Source/Core/DSPCore/Src',
362 'Source/Core/DebuggerUICommon/Src',
363 'Source/Core/DebuggerWX/Src',
364 'Source/Core/DiscIO/Src',
365 'Source/Core/DolphinWX/Src',
366 'Source/Core/InputCommon/Src',
367 'Source/Core/InputUICommon/Src',
368 'Source/Core/VideoCommon/Src',
369 'Source/DSPTool/Src',
370 'Source/Plugins/Plugin_DSP_HLE/Src',
371 'Source/Plugins/Plugin_DSP_LLE/Src',
372 #'Source/Plugins/Plugin_VideoDX11/Src',
373 #'Source/Plugins/Plugin_VideoDX9/Src',
374 'Source/Plugins/Plugin_VideoOGL/Src',
375 'Source/Plugins/Plugin_VideoSoftware/Src',
376 'Source/Plugins/Plugin_Wiimote/Src',
377 'Source/Plugins/Plugin_WiimoteNew/Src',
378 'Source/UnitTests',
381 # Now that platform configuration is done, propagate it to modules
382 for subdir in dirs:
383 SConscript(dirs = subdir, duplicate = 0, exports = 'env',
384 variant_dir = env['build_dir'] + os.sep + subdir)
385 if subdir.startswith('Source/Core'):
386 env['CPPPATH'] += ['#' + subdir]
388 # Print a nice progress indication when not compiling
389 Progress(['-\r', '\\\r', '|\r', '/\r'], interval = 5)
391 # Generate help, printing current status of options
392 Help(vars.GenerateHelpText(env))