Fix an issue that caused the DSP-LLE window to be openned twice in windows. (Thanks...
[dolphin.git] / SConstruct
bloba26fd1c58180d2314c29f4b7f1edc494c1f38908
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 # Handle command line options
16 vars = Variables('args.cache')
18 vars.AddVariables(
19 BoolVariable('verbose', 'Set to show compilation lines', False),
20 BoolVariable('bundle', 'Set to create distribution bundle', False),
21 BoolVariable('lint', 'Set for lint build (fail on warnings)', False),
22 BoolVariable('nowx', 'Set for building with no WX libs', False),
23 PathVariable('wxconfig', 'Path to wxconfig', None),
24 EnumVariable('flavor', 'Choose a build flavor', 'release',
25 allowed_values = ('release','devel','debug','fastlog','prof'),
26 ignorecase = 2),
29 if not sys.platform == 'win32' and not sys.platform == 'darwin':
30 vars.AddVariables(
31 PathVariable('destdir',
32 'Temporary install location (for package building)',
33 None, PathVariable.PathAccept),
34 EnumVariable('install',
35 'Choose a local or global installation', 'local',
36 allowed_values = ('local', 'global'), ignorecase = 2),
37 PathVariable('prefix',
38 'Installation prefix (only used for a global build)',
39 '/usr', PathVariable.PathAccept),
40 PathVariable('userdir',
41 'Set the name of the user data directory in home',
42 '.dolphin-emu', PathVariable.PathAccept),
43 BoolVariable('opencl', 'Build with OpenCL', False),
44 EnumVariable('pgo', 'Profile-Guided Optimization (generate or use)',
45 'none', allowed_values = ('none', 'generate', 'use'),
46 ignorecase = 2),
47 BoolVariable('shared_glew', 'Use system shared libGLEW', True),
48 BoolVariable('shared_lzo', 'Use system shared liblzo2', True),
49 BoolVariable('shared_sdl', 'Use system shared libSDL', True),
50 BoolVariable('shared_sfml', 'Use system shared libsfml-network', True),
51 BoolVariable('shared_soil', 'Use system shared libSOIL', True),
52 BoolVariable('shared_zlib', 'Use system shared libz', True),
53 ('CC', 'The C compiler', 'gcc'),
54 ('CXX', 'The C++ compiler', 'g++'),
57 env = Environment(ENV = os.environ, variables = vars)
58 Export('env')
60 # Die on unknown variables
61 unknown = vars.UnknownVariables()
62 if unknown:
63 print "Unknown variables:", unknown.keys()
64 Exit(1)
66 # Save the given command line options
67 vars.Save('args.cache', env)
69 cppDefines = [
70 ( '_FILE_OFFSET_BITS', 64),
71 '_LARGEFILE_SOURCE',
72 'GCC_HASCLASSVISIBILITY',
75 ccFlags = [
76 '-Wall',
77 '-Wpacked',
78 '-Wpointer-arith',
79 '-Wshadow',
80 '-Wwrite-strings',
81 '-fPIC',
82 '-fno-exceptions',
83 '-fno-strict-aliasing',
84 '-fvisibility=hidden',
85 '-msse2',
88 if env['CCVERSION'] >= '4.3.0': ccFlags += [
89 '-Wno-array-bounds', # False positives
90 '-Wno-unused-result', # Too many syscalls
93 # Build flavor
94 if env['flavor'] == 'debug':
95 ccFlags.append('-ggdb')
96 cppDefines.append('_DEBUG') #enables LOGGING
97 # FIXME: this disable wx debugging how do we make it work?
98 cppDefines.append('NDEBUG')
99 elif env['flavor'] == 'devel':
100 ccFlags.append('-ggdb')
101 elif env['flavor'] == 'fastlog':
102 ccFlags.append('-O3')
103 cppDefines.append('DEBUGFAST')
104 elif env['flavor'] == 'prof':
105 ccFlags.append('-O3')
106 ccFlags.append('-ggdb')
107 elif env['flavor'] == 'release':
108 ccFlags.append('-O3')
109 ccFlags.append('-fomit-frame-pointer');
111 if env['flavor'] == 'debug':
112 extra = '-debug'
113 elif env['flavor'] == 'prof':
114 extra = '-prof'
115 else:
116 extra = ''
118 if env['lint']:
119 ccFlags.append('-Werror')
121 # Verbose compile
122 if not env['verbose']:
123 env['ARCOMSTR'] = "Archiving $TARGET"
124 env['ASCOMSTR'] = "Assembling $TARGET"
125 env['ASPPCOMSTR'] = "Assembling $TARGET"
126 env['CCCOMSTR'] = "Compiling $TARGET"
127 env['CXXCOMSTR'] = "Compiling $TARGET"
128 env['LINKCOMSTR'] = "Linking $TARGET"
129 env['RANLIBCOMSTR'] = "Indexing $TARGET"
130 env['SHCCCOMSTR'] = "Compiling $TARGET"
131 env['SHCXXCOMSTR'] = "Compiling $TARGET"
132 env['SHLINKCOMSTR'] = "Linking $TARGET"
133 env['TARCOMSTR'] = "Creating $TARGET"
135 dirs = [
136 'Externals/Bochs_disasm',
137 'Externals/Lua',
138 'Externals/MemcardManager',
139 'Externals/WiiUse/Src',
140 'Source/Core/AudioCommon/Src',
141 'Source/Core/Common/Src',
142 'Source/Core/Core/Src',
143 'Source/Core/DSPCore/Src',
144 'Source/Core/DebuggerUICommon/Src',
145 'Source/Core/DebuggerWX/Src',
146 'Source/Core/DiscIO/Src',
147 'Source/Core/DolphinWX/Src',
148 'Source/Core/InputCommon/Src',
149 'Source/Core/InputUICommon/Src',
150 'Source/Core/VideoCommon/Src',
151 'Source/DSPTool/Src',
152 'Source/Plugins/Plugin_DSP_HLE/Src',
153 'Source/Plugins/Plugin_DSP_LLE/Src',
154 'Source/Plugins/Plugin_VideoOGL/Src',
155 'Source/Plugins/Plugin_VideoSoftware/Src',
156 'Source/Plugins/Plugin_Wiimote/Src',
157 'Source/Plugins/Plugin_WiimoteNew/Src',
158 'Source/UnitTests',
161 # Object files
162 env['build_dir'] = 'Build' + os.sep + platform.system() + \
163 '-' + platform.machine() + '-' + env['flavor']
165 # Static libs go here
166 env['local_libs'] = '#' + env['build_dir'] + os.sep + 'libs' + os.sep
168 # Default install path
169 if not env.has_key('install') or env['install'] == 'local':
170 env['prefix'] = 'Binary' + os.sep + platform.system() + \
171 '-' + platform.machine() + extra
173 # Configuration tests section
174 tests = {'CheckWXConfig' : wxconfig.CheckWXConfig,
175 'CheckPKGConfig' : utils.CheckPKGConfig,
176 'CheckPKG' : utils.CheckPKG,
177 'CheckSDL' : utils.CheckSDL,
178 'CheckPortaudio' : utils.CheckPortaudio,
181 rev = utils.GenerateRevFile(env['flavor'],
182 "Source/Core/Common/Src/svnrev_template.h",
183 "Source/Core/Common/Src/svnrev.h")
185 env['CCFLAGS'] = ccFlags
186 env['CPPDEFINES'] = cppDefines
187 env['CPPPATH'] = ['#' + path for path in dirs]
188 env['CPPPATH'] += ['#Source/PluginSpecs']
189 env['CXXFLAGS'] = ['-fvisibility-inlines-hidden']
190 env['LIBPATH'] = []
191 env['LIBS'] = []
192 env['RPATH'] = []
194 # OS X specifics
195 if sys.platform == 'darwin':
196 gccflags = ['-arch', 'x86_64', '-arch', 'i386', '-mmacosx-version-min=10.5']
197 env['CCFLAGS'] += gccflags
198 env['CCFLAGS'] += ['-Wextra-tokens', '-Wnewline-eof']
199 env['CC'] = "gcc-4.2 -ObjC"
200 env['CXX'] = "g++-4.2 -ObjC++"
201 env['FRAMEWORKS'] += ['AppKit', 'CoreFoundation', 'CoreServices']
202 env['FRAMEWORKS'] += ['AudioUnit', 'CoreAudio']
203 env['FRAMEWORKS'] += ['IOBluetooth', 'IOKit', 'OpenGL']
204 env['LIBS'] += ['iconv']
205 env['LINKFLAGS'] += gccflags
206 env['LINKFLAGS'] += ['-Z', '-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib',
207 '-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks',
208 '-F/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks']
209 if platform.mac_ver()[0] < '10.6.0':
210 env['HAVE_OPENCL'] = 0
211 else:
212 env['HAVE_OPENCL'] = 1
213 env['LINKFLAGS'] += ['-weak_framework', 'OpenCL']
214 if env['nowx']:
215 env['HAVE_WX'] = 0
216 else:
217 conf = env.Configure(custom_tests = tests)
218 env['HAVE_WX'] = conf.CheckWXConfig(2.9,
219 ['aui', 'adv', 'core', 'base', 'gl'], 0)
220 conf.Finish()
221 # wx-config wants us to link with the OS X QuickTime framework
222 # which is not available for x86_64 and we don't use it anyway.
223 # Strip it out to silence some harmless linker warnings.
224 # In the 10.5 SDK, Carbon is only partially built for x86_64.
225 frameworks = env['FRAMEWORKS']
226 wxconfig.ParseWXConfig(env)
227 if env['CPPDEFINES'].count('WXUSINGDLL'):
228 env['FRAMEWORKS'] = frameworks
229 env['CPPPATH'] += ['#Externals']
230 env['FRAMEWORKS'] += ['Cg']
231 env['LINKFLAGS'] += ['-FExternals/Cg']
232 env['shared_zlib'] = True
233 env['data_dir'] = '#' + env['prefix'] + '/Dolphin.app/Contents/Resources'
234 env['plugin_dir'] = '#' + env['prefix'] + '/Dolphin.app/Contents/PlugIns'
235 env.Install(env['data_dir'], 'Data/Sys')
236 env.Install(env['data_dir'], 'Data/User')
237 dirs += ['Externals/dylibbundler']
238 if env['bundle']:
239 app = env['prefix'] + '/Dolphin.app'
240 dmg = env['prefix'] + '/Dolphin-r' + rev + '.dmg'
241 env.Command(dmg, app, 'rm -f ' + dmg +
242 ' && hdiutil create -srcfolder ' + app + ' -format UDBZ ' + dmg +
243 ' && hdiutil internet-enable -yes ' + dmg)
245 elif sys.platform == 'win32':
246 env['tools'] = ['mingw']
247 dirs += ['Source/Plugins/Plugin_VideoDX9/Src']
248 dirs += ['Source/Plugins/Plugin_VideoDX11/Src']
250 else:
251 env['CCFLAGS'] += ['-pthread']
252 env['CXXFLAGS'] += ['-Wno-deprecated'] # XXX <hash_map>
253 env['CPPPATH'].insert(0, '#')
254 env['LINKFLAGS'] += ['-pthread']
255 conf = env.Configure(custom_tests = tests, config_h="#config.h")
257 if not conf.CheckPKGConfig('0.15.0'):
258 print "Can't find pkg-config, some tests will fail"
260 if env['shared_glew']:
261 env['shared_glew'] = conf.CheckPKG('GLEW')
262 if env['shared_sdl']:
263 env['shared_sdl'] = conf.CheckPKG('SDL')
264 if env['shared_zlib']:
265 env['shared_zlib'] = conf.CheckPKG('z')
266 if env['shared_lzo']:
267 env['shared_lzo'] = conf.CheckPKG('lzo2')
268 # TODO: Check the version of sfml. It should be at least version 1.5
269 if env['shared_sfml']:
270 env['shared_sfml'] = conf.CheckPKG('sfml-network') and \
271 conf.CheckCXXHeader("SFML/Network/Ftp.hpp")
272 if env['shared_soil']:
273 env['shared_soil'] = conf.CheckPKG('SOIL')
274 for var in env.items():
275 if var[0].startswith('shared_') and var[1] == False:
276 print "Shared library " + var[0][7:] + " not detected, " \
277 "falling back to the static library"
279 if env['nowx']:
280 env['HAVE_WX'] = 0
281 else:
282 env['HAVE_WX'] = conf.CheckWXConfig(2.8,
283 ['aui', 'adv', 'core', 'base'], 0)
284 conf.Define('HAVE_WX', env['HAVE_WX'])
285 wxconfig.ParseWXConfig(env)
286 if not env['HAVE_WX']:
287 print "WX libraries not found - see config.log"
288 Exit(1)
290 conf.CheckPKG('usbhid')
292 env['HAVE_BLUEZ'] = conf.CheckPKG('bluez')
293 conf.Define('HAVE_BLUEZ', env['HAVE_BLUEZ'])
295 env['HAVE_ALSA'] = conf.CheckPKG('alsa')
296 conf.Define('HAVE_ALSA', env['HAVE_ALSA'])
297 env['HAVE_AO'] = conf.CheckPKG('ao')
298 conf.Define('HAVE_AO', env['HAVE_AO'])
299 env['HAVE_OPENAL'] = conf.CheckPKG('openal')
300 conf.Define('HAVE_OPENAL', env['HAVE_OPENAL'])
301 env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890)
302 conf.Define('HAVE_PORTAUDIO', env['HAVE_PORTAUDIO'])
303 env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse-simple')
304 conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO'])
306 env['HAVE_X11'] = conf.CheckPKG('x11')
307 env['HAVE_XRANDR'] = env['HAVE_X11'] and conf.CheckPKG('xrandr')
308 conf.Define('HAVE_XRANDR', env['HAVE_XRANDR'])
309 conf.Define('HAVE_X11', env['HAVE_X11'])
311 # Check for GTK 2.0 or newer
312 if env['HAVE_WX'] and not conf.CheckPKG('gtk+-2.0'):
313 print "gtk+-2.0 developement headers not detected"
314 print "gtk+-2.0 is required to build the WX GUI"
315 Exit(1)
317 if not conf.CheckPKG('GL'):
318 print "Must have OpenGL to build"
319 Exit(1)
320 if not conf.CheckPKG('GLU'):
321 print "Must have GLU to build"
322 Exit(1)
323 if not conf.CheckPKG('Cg') and sys.platform == 'linux2':
324 print "Must have Cg toolkit from NVidia to build"
325 Exit(1)
326 if not conf.CheckPKG('CgGL') and sys.platform == 'linux2':
327 print "Must have CgGL to build"
328 Exit(1)
330 if env['opencl']:
331 env['HAVE_OPENCL'] = conf.CheckPKG('OpenCL')
332 conf.Define('HAVE_OPENCL', env['HAVE_OPENCL'])
333 else:
334 env['HAVE_OPENCL'] = 0
336 # PGO - Profile Guided Optimization
337 if env['pgo']=='generate':
338 ccFlags.append('-fprofile-generate')
339 env['LINKFLAGS']='-fprofile-generate'
340 if env['pgo']=='use':
341 ccFlags.append('-fprofile-use')
342 env['LINKFLAGS']='-fprofile-use'
344 # Profiling
345 if (env['flavor'] == 'prof'):
346 proflibs = [ '/usr/lib/oprofile', '/usr/local/lib/oprofile' ]
347 env['LIBPATH'].append(proflibs)
348 env['RPATH'].append(proflibs)
349 if conf.CheckPKG('opagent'):
350 conf.Define('USE_OPROFILE', 1)
351 else:
352 print "Can't build prof without oprofile, disabling"
354 tarname = 'dolphin-' + rev
355 env['TARFLAGS'] = '-cj'
356 env['TARSUFFIX'] = '.tar.bz2'
358 if env['install'] == 'local':
359 env['binary_dir'] = '#' + env['prefix']
360 env['data_dir'] = '#' + env['prefix']
361 env['plugin_dir'] = '#' + env['prefix'] + '/plugins'
362 if env['bundle']:
363 env.Tar(tarname, env['prefix'])
364 else:
365 env['prefix'] = Dir(env['prefix']).abspath
366 env['binary_dir'] = env['prefix'] + '/bin'
367 env['data_dir'] = env['prefix'] + "/share/dolphin-emu"
368 env['plugin_dir'] = env['prefix'] + '/lib/dolphin-emu'
369 conf.Define('DATA_DIR', "\"" + env['data_dir'] + "\"")
370 conf.Define('LIBS_DIR', "\"" + env['prefix'] + '/lib/' + "\"")
371 # Setup destdir for package building
372 # Warning: The program will not run from this location.
373 # It is assumed the package will later install it to the prefix.
374 if env.has_key('destdir'):
375 env['destdir'] = Dir(env['destdir']).abspath
376 env['binary_dir'] = env['destdir'] + env['binary_dir']
377 env['data_dir'] = env['destdir'] + env['data_dir']
378 env['plugin_dir'] = env['destdir'] + env['plugin_dir']
379 env['prefix'] = env['destdir'] + env['prefix']
380 if env['bundle']:
381 env.Command(tarname + env['TARSUFFIX'], env['prefix'],
382 'tar ' + env['TARFLAGS'] + 'C ' + env['destdir'] + \
383 ' -f ' + tarname + env['TARSUFFIX'] + ' ' + \
384 env['prefix'].split(env['destdir'], 1)[1][1:])
386 conf.Define('USER_DIR', "\"" + env['userdir'] + "\"")
388 # After all configuration tests are done
389 conf.Finish()
391 # Data install
392 env.InstallAs(env['data_dir'] + '/sys', 'Data/Sys')
393 env.InstallAs(env['data_dir'] + '/user', 'Data/User')
395 env.Alias('install', env['prefix'])
397 # Local (static) libraries must be first in the search path for the build in
398 # order that they can override system libraries, but they must not be found
399 # during autoconfiguration as they will then be detected as system libraries.
400 env['LIBPATH'].insert(0, env['local_libs'])
402 if not env.has_key('shared_glew') or not env['shared_glew']:
403 env['CPPPATH'] += ['#Externals/GLew/include']
404 dirs += ['Externals/GLew']
405 if not env.has_key('shared_lzo') or not env['shared_lzo']:
406 env['CPPPATH'] += ['#Externals/LZO']
407 dirs += ['Externals/LZO']
408 if not env.has_key('shared_sdl') or not env['shared_sdl']:
409 env['CPPPATH'] += ['#Externals/SDL']
410 env['CPPPATH'] += ['#Externals/SDL/include']
411 dirs += ['Externals/SDL']
412 if not env.has_key('shared_soil') or not env['shared_soil']:
413 env['CPPPATH'] += ['#Externals/SOIL']
414 dirs += ['Externals/SOIL']
415 if not env.has_key('shared_sfml') or not env['shared_sfml']:
416 env['CPPPATH'] += ['#Externals/SFML/include']
417 dirs += ['Externals/SFML/src']
418 if not env.has_key('shared_zlib') or not env['shared_zlib']:
419 env['CPPPATH'] += ['#Externals/zlib']
420 dirs += ['Externals/zlib']
422 for subdir in dirs:
423 SConscript(subdir + os.sep + 'SConscript',
424 variant_dir = env['build_dir'] + os.sep + subdir, duplicate = 0)
426 # Print a nice progress indication when not compiling
427 Progress(['-\r', '\\\r', '|\r', '/\r'], interval = 5)
429 # Generate help
430 Help(vars.GenerateHelpText(env))