Oops, I disabled tilting.
[dolphin.git] / SConstruct
blob6a09bc3ab3aa765ee32338f87ca3e42961b03e4c
1 # -*- python -*-
3 import os
4 import sys
5 import platform
7 # Home made tests
8 sys.path.append('SconsTests')
9 import wxconfig
10 import utils
12 # Some features need at least SCons 1.2
13 EnsureSConsVersion(1, 2)
15 warnings = [
16 'all',
17 'write-strings',
18 'shadow',
19 'pointer-arith',
20 'packed',
21 'no-conversion',
24 compileFlags = [
25 '-fno-exceptions',
26 '-fno-strict-aliasing',
27 '-msse2',
28 '-fPIC',
31 cppDefines = [
32 ( '_FILE_OFFSET_BITS', 64),
33 '_LARGEFILE_SOURCE',
34 'GCC_HASCLASSVISIBILITY',
37 basedir = os.getcwd() + '/'
39 include_paths = [
40 basedir + 'Source/Core/Common/Src',
41 basedir + 'Source/Core/DiscIO/Src',
42 basedir + 'Source/PluginSpecs',
43 basedir + 'Source/Core/Core/Src',
44 basedir + 'Source/Core/DebuggerWX/Src',
45 basedir + 'Externals/Bochs_disasm',
46 basedir + 'Externals/Lua',
47 basedir + 'Externals/WiiUseSrc/Src',
48 basedir + 'Source/Core/VideoCommon/Src',
49 basedir + 'Source/Core/InputCommon/Src',
50 basedir + 'Source/Core/InputUICommon/Src',
51 basedir + 'Source/Core/AudioCommon/Src',
52 basedir + 'Source/Core/DebuggerUICommon/Src',
53 basedir + 'Source/Core/DolphinWX/Src',
54 basedir + 'Source/Core/DSPCore/Src',
57 dirs = [
58 'Externals/Bochs_disasm',
59 'Externals/Lua',
60 'Externals/MemcardManager',
61 'Externals/WiiUseSrc/Src',
62 'Source/Core/Common/Src',
63 'Source/Core/Core/Src',
64 'Source/Core/DiscIO/Src',
65 'Source/Core/VideoCommon/Src',
66 'Source/Core/InputCommon/Src',
67 'Source/Core/AudioCommon/Src',
68 'Source/Core/DebuggerUICommon/Src',
69 'Source/Core/DSPCore/Src',
70 'Source/DSPTool/Src',
71 'Source/Core/InputUICommon/Src/',
72 'Source/Plugins/Plugin_VideoOGL/Src',
73 'Source/Plugins/Plugin_VideoSoftware/Src',
74 'Source/Plugins/Plugin_DSP_HLE/Src',
75 'Source/Plugins/Plugin_DSP_LLE/Src',
76 'Source/Plugins/Plugin_Wiimote/Src',
77 'Source/Plugins/Plugin_WiimoteNew/Src/',
78 'Source/Core/DolphinWX/Src',
79 'Source/Core/DebuggerWX/Src',
80 'Source/UnitTests/',
83 builders = {}
84 if sys.platform == 'darwin':
85 from plistlib import writePlist
86 def createPlist(target, source, env):
87 properties = {}
88 for srcNode in source:
89 properties.update(srcNode.value)
90 for dstNode in target:
91 writePlist(properties, str(dstNode))
92 builders['Plist'] = Builder(action = createPlist)
94 # Handle command line options
95 vars = Variables('args.cache')
97 vars.AddVariables(
98 BoolVariable('verbose', 'Set to show compilation lines', False),
99 BoolVariable('bundle', 'Set to create distribution bundle', False),
100 BoolVariable('lint', 'Set for lint build (extra warnings)', False),
101 BoolVariable('nowx', 'Set for building with no WX libs', False),
102 EnumVariable('flavor', 'Choose a build flavor', 'release',
103 allowed_values = ('release','devel','debug','fastlog','prof'),
104 ignorecase = 2),
105 PathVariable('wxconfig', 'Path to wxconfig', None),
106 ('CC', 'The C compiler', 'gcc'),
107 ('CXX', 'The C++ compiler', 'g++'),
110 if not sys.platform == 'win32' and not sys.platform == 'darwin':
111 vars.AddVariables(
112 PathVariable('destdir',
113 'Temporary install location (for package building)',
114 None, PathVariable.PathAccept),
115 EnumVariable('install',
116 'Choose a local or global installation', 'local',
117 allowed_values = ('local', 'global'), ignorecase = 2),
118 PathVariable('prefix',
119 'Installation prefix (only used for a global build)',
120 '/usr', PathVariable.PathAccept),
121 PathVariable('userdir',
122 'Set the name of the user data directory in home',
123 '.dolphin-emu', PathVariable.PathAccept),
124 BoolVariable('opencl', 'Build with OpenCL', False),
125 EnumVariable('pgo', 'Profile-Guided Optimization (generate or use)',
126 'none', allowed_values = ('none', 'generate', 'use'),
127 ignorecase = 2),
128 BoolVariable('shared_glew', 'Use system shared libGLEW', True),
129 BoolVariable('shared_lzo', 'Use system shared liblzo2', True),
130 BoolVariable('shared_sdl', 'Use system shared libSDL', True),
131 BoolVariable('shared_sfml', 'Use system shared libsfml-network', True),
132 BoolVariable('shared_soil', 'Use system shared libSOIL', True),
133 BoolVariable('shared_zlib', 'Use system shared libz', True),
136 env = Environment(
137 CPPPATH = include_paths,
138 RPATH = [],
139 LIBS = [],
140 LIBPATH = [],
141 BUILDERS = builders,
142 variables = vars,
145 if sys.platform == 'win32':
146 env['tools'] = ['mingw']
147 env['ENV'] = os.environ
148 else:
149 env['ENV'] = {
150 'PATH' : os.environ['PATH'],
151 'HOME' : os.environ['HOME'],
152 'PKG_CONFIG_PATH' : os.environ.get('PKG_CONFIG_PATH')
155 # Save the given command line options
156 vars.Save('args.cache', env)
158 # Verbose compile
159 if not env['verbose']:
160 env['CCCOMSTR'] = "Compiling $TARGET"
161 env['CXXCOMSTR'] = "Compiling $TARGET"
162 env['ARCOMSTR'] = "Archiving $TARGET"
163 env['LINKCOMSTR'] = "Linking $TARGET"
164 env['ASCOMSTR'] = "Assembling $TARGET"
165 env['ASPPCOMSTR'] = "Assembling $TARGET"
166 env['SHCCCOMSTR'] = "Compiling shared $TARGET"
167 env['SHCXXCOMSTR'] = "Compiling shared $TARGET"
168 env['SHLINKCOMSTR'] = "Linking shared $TARGET"
169 env['RANLIBCOMSTR'] = "Indexing $TARGET"
171 # Build flavor
172 flavour = env['flavor']
173 if (flavour == 'debug'):
174 compileFlags.append('-ggdb')
175 cppDefines.append('_DEBUG') #enables LOGGING
176 # FIXME: this disable wx debugging how do we make it work?
177 cppDefines.append('NDEBUG')
178 elif (flavour == 'devel'):
179 compileFlags.append('-ggdb')
180 elif (flavour == 'fastlog'):
181 compileFlags.append('-O3')
182 cppDefines.append('DEBUGFAST')
183 elif (flavour == 'prof'):
184 compileFlags.append('-O3')
185 compileFlags.append('-ggdb')
186 elif (flavour == 'release'):
187 compileFlags.append('-O3')
188 compileFlags.append('-fomit-frame-pointer');
189 # More warnings
190 if env['lint']:
191 warnings.append('error')
192 # Should check for the availability of these (in GCC 4.3 or newer)
193 if sys.platform != 'darwin':
194 warnings.append('no-array-bounds')
195 warnings.append('no-unused-result')
196 # wxWidgets causes too many warnings with these
197 #warnings.append('unreachable-code')
198 #warnings.append('float-equal')
200 # Add the warnings to the compile flags
201 compileFlags += [ ('-W' + warning) for warning in warnings ]
203 env['CCFLAGS'] = compileFlags
204 env['CPPDEFINES'] = cppDefines
205 if not sys.platform == 'win32':
206 env['CXXFLAGS'] = ['-fvisibility-inlines-hidden']
207 cppDefines.append('LUA_USE_LINUX')
209 # Configuration tests section
210 tests = {'CheckWXConfig' : wxconfig.CheckWXConfig,
211 'CheckPKGConfig' : utils.CheckPKGConfig,
212 'CheckPKG' : utils.CheckPKG,
213 'CheckSDL' : utils.CheckSDL,
214 'CheckPortaudio' : utils.CheckPortaudio,
217 # Object files
218 env['build_dir'] = os.path.join(basedir, 'Build',
219 platform.system() + '-' + platform.machine() + '-' + env['flavor'] + os.sep)
221 # Static libs go here
222 env['local_libs'] = env['build_dir'] + os.sep + 'libs' + os.sep
224 # Where do we run from
225 env['base_dir'] = os.getcwd()+ '/'
227 # Install paths
228 extra=''
229 if flavour == 'debug':
230 extra = '-debug'
231 elif flavour == 'prof':
232 extra = '-prof'
234 # Set up the install locations
235 if sys.platform == 'linux2' and env['install'] == 'global':
236 env['prefix'] = os.path.join(env['prefix'] + os.sep)
237 env['binary_dir'] = env['prefix'] + 'bin/'
238 env['plugin_dir'] = env['prefix'] + 'lib/dolphin-emu/'
239 env['data_dir'] = env['prefix'] + "share/dolphin-emu/"
240 else:
241 env['prefix'] = os.path.join(env['base_dir'] + 'Binary',
242 platform.system() + '-' + platform.machine() + extra + os.sep)
243 env['binary_dir'] = env['prefix']
244 env['plugin_dir'] = env['prefix'] + 'plugins/'
245 env['data_dir'] = env['prefix']
246 if sys.platform == 'darwin':
247 env['plugin_dir'] = env['prefix'] + 'Dolphin.app/Contents/PlugIns/'
248 env['data_dir'] = env['prefix'] + 'Dolphin.app/Contents/'
250 shared = {}
251 shared['glew'] = shared['lzo'] = shared['sdl'] = \
252 shared['soil'] = shared['sfml'] = shared['zlib'] = 0
253 wxmods = ['aui', 'adv', 'core', 'base', 'gl']
254 env['HAVE_OPENCL'] = 0
255 env['HAVE_WX'] = 0
257 # OS X specifics
258 if sys.platform == 'darwin':
259 compileFlags.append('-mmacosx-version-min=10.5')
260 if not env['nowx']:
261 cppDefines.append('HAVE_WX=1')
262 conf = env.Configure(custom_tests = tests)
263 # wxWidgets 2.9 has Cocoa support
264 env['HAVE_WX'] = conf.CheckWXConfig(2.9, wxmods, 0)
265 wxconfig.ParseWXConfig(env)
266 # Make sure that the libraries claimed by wx-config are valid
267 if not conf.CheckLib('wx_baseu-2.9'):
268 print "WX libraries not found - see config.log"
269 Exit(1)
270 conf.Finish()
271 # wx-config wants us to link with the OS X QuickTime framework
272 # which is not available for x86_64 and we don't use it anyway.
273 # Strip it out to silence some harmless linker warnings.
274 if env['FRAMEWORKS'].count('QuickTime'):
275 env['FRAMEWORKS'].remove('QuickTime')
276 env['CC'] = "gcc-4.2"
277 env['CFLAGS'] = ['-x', 'objective-c']
278 env['CXX'] = "g++-4.2"
279 env['CXXFLAGS'] = ['-x', 'objective-c++']
280 env['CCFLAGS'] += ['-arch', 'x86_64', '-arch', 'i386']
281 env['LIBS'] += ['iconv']
282 env['LINKFLAGS'] += ['-arch', 'x86_64', '-arch', 'i386']
283 env['FRAMEWORKS'] += ['AppKit', 'CoreFoundation', 'CoreServices']
284 env['FRAMEWORKS'] += ['IOBluetooth', 'IOKit', 'OpenGL']
285 env['FRAMEWORKS'] += ['AudioUnit', 'CoreAudio']
286 if platform.mac_ver()[0] >= '10.6.0':
287 env['HAVE_OPENCL'] = 1
288 env['LINKFLAGS'] += ['-weak_framework', 'OpenCL']
289 env['FRAMEWORKS'] += ['Cg']
291 if not sys.platform == 'win32' and not sys.platform == 'darwin':
292 conf = env.Configure(custom_tests = tests,
293 config_h="Source/Core/Common/Src/Config.h")
295 if not conf.CheckPKGConfig('0.15.0'):
296 print "Can't find pkg-config, some tests will fail"
298 env['LINKFLAGS'] += ['-pthread']
300 if env['shared_glew']:
301 shared['glew'] = conf.CheckPKG('GLEW')
302 if env['shared_sdl']:
303 shared['sdl'] = conf.CheckPKG('SDL')
304 if env['shared_zlib']:
305 shared['zlib'] = conf.CheckPKG('z')
306 if env['shared_lzo']:
307 shared['lzo'] = conf.CheckPKG('lzo2')
308 # TODO: Check the version of sfml. It should be at least version 1.5
309 if env['shared_sfml']:
310 shared['sfml'] = conf.CheckPKG('sfml-network') and \
311 conf.CheckCXXHeader("SFML/Network/Ftp.hpp")
312 if env['shared_soil']:
313 shared['soil'] = conf.CheckPKG('SOIL')
314 for lib in shared:
315 if not shared[lib]:
316 print "Shared library " + lib + " not detected, " \
317 "falling back to the static library"
319 if not env['nowx']:
320 # wxGLCanvas does not play well with wxGTK
321 wxmods.remove('gl')
322 env['HAVE_WX'] = conf.CheckWXConfig(2.8, wxmods, 0)
323 wxconfig.ParseWXConfig(env)
324 if not env['HAVE_WX']:
325 print "WX libraries not found - see config.log"
326 Exit(1)
328 conf.Define('HAVE_WX', env['HAVE_WX'])
330 env['HAVE_BLUEZ'] = conf.CheckPKG('bluez')
331 conf.Define('HAVE_BLUEZ', env['HAVE_BLUEZ'])
333 env['HAVE_ALSA'] = conf.CheckPKG('alsa')
334 conf.Define('HAVE_ALSA', env['HAVE_ALSA'])
336 env['HAVE_AO'] = conf.CheckPKG('ao')
337 conf.Define('HAVE_AO', env['HAVE_AO'])
339 env['HAVE_OPENAL'] = conf.CheckPKG('openal')
340 conf.Define('HAVE_OPENAL', env['HAVE_OPENAL'])
342 env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890)
343 conf.Define('HAVE_PORTAUDIO', env['HAVE_PORTAUDIO'])
345 env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse-simple')
346 conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO'])
348 env['HAVE_X11'] = conf.CheckPKG('x11')
349 env['HAVE_XRANDR'] = env['HAVE_X11'] and conf.CheckPKG('xrandr')
350 conf.Define('HAVE_XRANDR', env['HAVE_XRANDR'])
351 conf.Define('HAVE_X11', env['HAVE_X11'])
353 # Check for GTK 2.0 or newer
354 if env['HAVE_WX'] and not conf.CheckPKG('gtk+-2.0'):
355 print "gtk+-2.0 developement headers not detected"
356 print "gtk+-2.0 is required to build the WX GUI"
357 Exit(1)
359 if not conf.CheckPKG('GL'):
360 print "Must have OpenGL to build"
361 Exit(1)
362 if not conf.CheckPKG('GLU'):
363 print "Must have GLU to build"
364 Exit(1)
365 if not conf.CheckPKG('Cg'):
366 print "Must have Cg toolkit from NVidia to build"
367 Exit(1)
368 if not conf.CheckPKG('CgGL'):
369 print "Must have CgGl to build"
370 Exit(1)
372 if env['opencl']:
373 env['HAVE_OPENCL'] = conf.CheckPKG('OpenCL')
375 conf.Define('USER_DIR', "\"" + env['userdir'] + "\"")
376 if (env['install'] == 'global'):
377 conf.Define('DATA_DIR', "\"" + env['data_dir'] + "\"")
378 conf.Define('LIBS_DIR', "\"" + env['prefix'] + 'lib/' + "\"")
380 # PGO - Profile Guided Optimization
381 if env['pgo']=='generate':
382 compileFlags.append('-fprofile-generate')
383 env['LINKFLAGS']='-fprofile-generate'
384 if env['pgo']=='use':
385 compileFlags.append('-fprofile-use')
386 env['LINKFLAGS']='-fprofile-use'
388 # Profiling
389 if (flavour == 'prof'):
390 proflibs = [ '/usr/lib/oprofile', '/usr/local/lib/oprofile' ]
391 env['LIBPATH'].append(proflibs)
392 env['RPATH'].append(proflibs)
393 if conf.CheckPKG('opagent'):
394 conf.Define('USE_OPROFILE', 1)
395 else:
396 print "Can't build prof without oprofile, disabling"
398 conf.Define('HAVE_OPENCL', env['HAVE_OPENCL'])
400 # After all configuration tests are done
401 conf.Finish()
403 # Local (static) libraries must be first in the search path for the build in
404 # order that they can override system libraries, but they must not be found
405 # during autoconfiguration as they will then be detected as system libraries.
406 env['LIBPATH'].insert(0, env['local_libs'])
408 if not shared['glew']:
409 env['CPPPATH'] += [basedir + 'Externals/GLew/include']
410 dirs += ['Externals/GLew']
411 if not shared['lzo']:
412 env['CPPPATH'] += [basedir + 'Externals/LZO']
413 dirs += ['Externals/LZO']
414 if not shared['sdl']:
415 env['CPPPATH'] += [basedir + 'Externals/SDL']
416 env['CPPPATH'] += [basedir + 'Externals/SDL/include']
417 dirs += ['Externals/SDL']
418 if not shared['soil']:
419 env['CPPPATH'] += [basedir + 'Externals/SOIL']
420 dirs += ['Externals/SOIL']
421 if not shared['sfml']:
422 env['CPPPATH'] += [basedir + 'Externals/SFML/include']
423 dirs += ['Externals/SFML/src']
424 if not shared['zlib']:
425 env['CPPPATH'] += [basedir + 'Externals/zlib']
426 dirs += ['Externals/zlib']
428 rev = utils.GenerateRevFile(env['flavor'],
429 "Source/Core/Common/Src/svnrev_template.h",
430 "Source/Core/Common/Src/svnrev.h")
432 # Print a nice progress indication when not compiling
433 Progress(['-\r', '\\\r', '|\r', '/\r'], interval=5)
435 # Setup destdir for package building
436 # Warning: The program will not run from this location. It is assumed the
437 # package will later install it to the prefix as it was defined before this.
438 if env.has_key('destdir'):
439 env['prefix'] = env['destdir'] + env['prefix']
440 env['plugin_dir'] = env['destdir'] + env['plugin_dir']
441 env['binary_dir'] = env['destdir'] + env['binary_dir']
442 env['data_dir'] = env['destdir'] + env['data_dir']
444 # Die on unknown variables
445 unknown = vars.UnknownVariables()
446 if unknown:
447 print "Unknown variables:", unknown.keys()
448 Exit(1)
450 # Generate help
451 Help(vars.GenerateHelpText(env))
453 Export('env')
455 for subdir in dirs:
456 SConscript(
457 subdir + os.sep + 'SConscript',
458 variant_dir = env[ 'build_dir' ] + subdir + os.sep,
459 duplicate=0
462 # Data install
463 if sys.platform == 'darwin':
464 env.Install(env['data_dir'], 'Data/Sys')
465 env.Install(env['data_dir'], 'Data/User')
466 else:
467 env.InstallAs(env['data_dir'] + 'sys', 'Data/Sys')
468 env.InstallAs(env['data_dir'] + 'user', 'Data/User')
470 env.Alias('install', env['prefix'])
472 if env['bundle']:
473 if sys.platform == 'linux2':
474 # Make tar ball (TODO put inside normal dir)
475 tar_env = env.Clone()
476 tarball = tar_env.Tar('dolphin-' + rev + '.tar.bz2', env['prefix'])
477 tar_env.Append(TARFLAGS='-j', TARCOMSTR="Creating release tarball")
478 env.Clean(all, tarball)
479 elif sys.platform == 'darwin':
480 app = env['binary_dir'] + 'Dolphin.app'
481 dmg = env['binary_dir'] + 'Dolphin-r' + rev + '.dmg'
482 env.Command('.', app + '/Contents/MacOS/Dolphin', 'rm -f ' + dmg +
483 ' && hdiutil create -srcfolder ' + app + ' -format UDBZ ' + dmg +
484 ' && hdiutil internet-enable -yes ' + dmg)
485 env.Clean(all, dmg)