Windows: Link debug build against debug wiiuse. Can't keep linking to the release...
[dolphin.git] / SConstruct
blob9307cfa7733f9bbd215a3b542401c1350c0571c2
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 EnumVariable('pgo', 'Profile-Guided Optimization (generate or use)', 'none',
40 allowed_values = ('none', 'generate', 'use'), ignorecase = 2),
41 BoolVariable('shared_glew', 'Use system shared libGLEW', True),
42 BoolVariable('shared_lzo', 'Use system shared liblzo2', True),
43 BoolVariable('shared_sdl', 'Use system shared libSDL', True),
44 BoolVariable('shared_sfml', 'Use system shared libsfml-network', True),
45 BoolVariable('shared_soil', 'Use system shared libSOIL', True),
46 BoolVariable('shared_zlib', 'Use system shared libz', True),
47 PathVariable('CC', 'The C compiler', 'gcc', PathVariable.PathAccept),
48 PathVariable('CXX', 'The C++ compiler', 'g++', PathVariable.PathAccept),
51 # Save the given command line options
52 vars.Update(env)
53 vars.Save('args.cache', env)
55 # Die on unknown variables
56 unknown = vars.UnknownVariables()
57 if unknown:
58 print "Unknown variables:", unknown.keys()
59 Exit(1)
61 # Verbose compile
62 if not env['verbose']:
63 env['ARCOMSTR'] = "Archiving $TARGET"
64 env['ASCOMSTR'] = "Assembling $TARGET"
65 env['ASPPCOMSTR'] = "Assembling $TARGET"
66 env['CCCOMSTR'] = "Compiling $TARGET"
67 env['CXXCOMSTR'] = "Compiling $TARGET"
68 env['LINKCOMSTR'] = "Linking $TARGET"
69 env['RANLIBCOMSTR'] = "Indexing $TARGET"
70 env['SHCCCOMSTR'] = "Compiling $TARGET"
71 env['SHCXXCOMSTR'] = "Compiling $TARGET"
72 env['SHLINKCOMSTR'] = "Linking $TARGET"
73 env['TARCOMSTR'] = "Creating $TARGET"
75 if not env['flavor'] == 'debug':
76 env['CCFLAGS'] += ['-O3']
77 if env['flavor'] == 'release':
78 env['CCFLAGS'] += ['-fomit-frame-pointer']
79 elif not env['flavor'] == 'fastlog':
80 env['CCFLAGS'] += ['-ggdb']
81 env['CCFLAGS'] += ['-fno-exceptions', '-fno-strict-aliasing']
82 if env['CCVERSION'] >= '4.2.0':
83 env['CCFLAGS'] += ['-fvisibility=hidden']
84 env['CXXFLAGS'] += ['-fvisibility-inlines-hidden']
86 if env['lint']:
87 env['CCFLAGS'] += ['-Werror']
88 env['CCFLAGS'] += ['-Wall', '-Wextra']
89 env['CCFLAGS'] += ['-Wno-missing-field-initializers', '-Wno-unused-parameter']
90 env['CCFLAGS'] += ['-Wpacked', '-Wpointer-arith', '-Wshadow', '-Wwrite-strings']
91 if env['CCVERSION'] < '4.2.0':
92 env['CCFLAGS'] += ['-Wno-pragmas']
93 if env['CCVERSION'] >= '4.3.0':
94 env['CCFLAGS'] += ['-Wno-array-bounds', '-Wno-unused-result']
96 env['CPPDEFINES'] = []
97 if env['flavor'] == 'debug':
98 env['CPPDEFINES'] += ['_DEBUG']
99 elif env['flavor'] == 'fastlog':
100 env['CPPDEFINES'] += ['DEBUGFAST']
101 env['CPPPATH'] = ['#Source/PluginSpecs']
102 env['LIBPATH'] = []
103 env['LIBS'] = []
105 # Object files
106 env['build_dir'] = 'Build' + os.sep + platform.system() + \
107 '-' + platform.machine() + '-' + env['flavor']
109 # Static libs go here
110 env['local_libs'] = '#' + env['build_dir'] + os.sep + 'libs' + os.sep
112 # Default install path
113 if not env.has_key('install') or env['install'] == 'local':
114 env['prefix'] = 'Binary' + os.sep + platform.system() + \
115 '-' + platform.machine()
116 if env['flavor'] == 'debug' or env['flavor'] == 'prof':
117 env['prefix'] += '-' + env['flavor']
119 rev = utils.GenerateRevFile(env['flavor'], '.', None)
121 # OS X specifics
122 if sys.platform == 'darwin':
123 ccld = ['-arch', 'x86_64', '-arch', 'i386', '-mmacosx-version-min=10.5']
124 ccld += ['--sysroot=/Developer/SDKs/MacOSX10.5.sdk']
125 env['CCFLAGS'] += ccld
126 env['CCFLAGS'] += ['-msse3']
127 env['CC'] = "gcc-4.2 -ObjC"
128 env['CXX'] = "g++-4.2 -ObjC++"
129 env['FRAMEWORKS'] += ['AppKit', 'CoreFoundation', 'CoreServices']
130 env['FRAMEWORKS'] += ['AudioUnit', 'CoreAudio']
131 env['FRAMEWORKS'] += ['IOBluetooth', 'IOKit', 'OpenGL']
132 env['LIBPATH'] += ['/usr/lib']
133 env['LIBS'] = ['iconv', 'SDL']
134 env['LINKFLAGS'] += ccld
135 env['LINKFLAGS'] += ['-Wl,-search_paths_first', '-Wl,-Z']
136 env['LINKFLAGS'] += ['-F/System/Library/Frameworks']
138 if platform.mac_ver()[0] < '10.6.0':
139 env['HAVE_OPENCL'] = 0
140 else:
141 env['CCFLAGS'] += ['-Wextra-tokens', '-Wnewline-eof']
142 env['CCFLAGS'] += ['-iframework' +
143 '/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks']
144 env['CCFLAGS'] += ['-iframework' +
145 '/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks']
146 env['CPPDEFINES'] += [('HAVE_OPENCL', 1)]
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['CPPDEFINES'] += ['HAVE_CONFIG_H']
192 env['CPPPATH'].insert(0, '#') # Make sure we pick up our own config.h
193 if sys.platform == 'linux2':
194 env['CPPDEFINES'] += [('_FILE_OFFSET_BITS', 64), '_LARGEFILE_SOURCE']
195 env['CXXFLAGS'] += ['-Wno-deprecated'] # XXX <hash_map>
196 env['LINKFLAGS'] += ['-pthread', '-ldl']
197 env['RPATH'] = []
199 conf = env.Configure(config_h = "#config.h", custom_tests = {
200 'CheckPKG' : utils.CheckPKG,
201 'CheckPKGConfig' : utils.CheckPKGConfig,
202 'CheckPortaudio' : utils.CheckPortaudio,
203 'CheckSDL' : utils.CheckSDL,
204 'CheckWXConfig' : wxconfig.CheckWXConfig,
207 if not conf.CheckPKGConfig('0.15.0'):
208 print "Can't find pkg-config, some tests will fail"
210 if env['shared_glew']:
211 env['shared_glew'] = conf.CheckPKG('GLEW')
212 if env['shared_sdl']:
213 env['shared_sdl'] = conf.CheckPKG('SDL')
214 if env['shared_zlib']:
215 env['shared_zlib'] = conf.CheckPKG('z')
216 if env['shared_lzo']:
217 env['shared_lzo'] = conf.CheckPKG('lzo2')
218 # TODO: Check the version of sfml. It should be at least version 1.5
219 if env['shared_sfml']:
220 env['shared_sfml'] = conf.CheckPKG('sfml-network') and \
221 conf.CheckCXXHeader("SFML/Network/Ftp.hpp")
222 if env['shared_soil']:
223 env['shared_soil'] = conf.CheckPKG('SOIL')
224 for var in env.items():
225 if var[0].startswith('shared_') and var[1] == False:
226 print "Shared library " + var[0][7:] + " not detected, " \
227 "falling back to the static library"
229 if env['nowx']:
230 env['HAVE_WX'] = 0
231 else:
232 env['HAVE_WX'] = conf.CheckWXConfig(2.8, 'aui adv core base'.split(),
233 env['flavor'] == 'debug')
234 conf.Define('HAVE_WX', env['HAVE_WX'])
235 wxconfig.ParseWXConfig(env)
236 if not env['HAVE_WX']:
237 print "wxWidgets not found - see config.log"
238 Exit(1)
240 env['HAVE_BLUEZ'] = conf.CheckPKG('bluez')
241 conf.Define('HAVE_BLUEZ', env['HAVE_BLUEZ'])
243 env['HAVE_ALSA'] = conf.CheckPKG('alsa')
244 conf.Define('HAVE_ALSA', env['HAVE_ALSA'])
245 env['HAVE_AO'] = conf.CheckPKG('ao')
246 conf.Define('HAVE_AO', env['HAVE_AO'])
247 env['HAVE_OPENAL'] = conf.CheckPKG('openal')
248 conf.Define('HAVE_OPENAL', env['HAVE_OPENAL'])
249 env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890)
250 conf.Define('HAVE_PORTAUDIO', env['HAVE_PORTAUDIO'])
251 env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse')
252 conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO'])
254 env['HAVE_X11'] = conf.CheckPKG('x11')
255 env['HAVE_XRANDR'] = env['HAVE_X11'] and conf.CheckPKG('xrandr')
256 conf.Define('HAVE_XRANDR', env['HAVE_XRANDR'])
257 conf.Define('HAVE_X11', env['HAVE_X11'])
259 if env['HAVE_WX'] and not conf.CheckPKG('gtk+-2.0'):
260 print "gtk+-2.0 developement headers not detected"
261 print "gtk+-2.0 is required to build the WX GUI"
262 Exit(1)
264 if not conf.CheckPKG('GL'):
265 print "Must have OpenGL to build"
266 Exit(1)
267 if not conf.CheckPKG('GLU'):
268 print "Must have GLU to build"
269 Exit(1)
270 if not conf.CheckPKG('Cg') and sys.platform == 'linux2':
271 print "Must have Cg toolkit from NVidia to build"
272 Exit(1)
273 if not conf.CheckPKG('CgGL') and sys.platform == 'linux2':
274 print "Must have CgGL to build"
275 Exit(1)
277 env['HAVE_OPENCL'] = int(conf.CheckPKG('OpenCL') and \
278 conf.CheckCXXHeader("CL/cl.h"))
279 conf.Define('HAVE_OPENCL', env['HAVE_OPENCL'])
281 # PGO - Profile Guided Optimization
282 if env['pgo'] == 'generate':
283 env['CCFLAGS'] += ['-fprofile-generate']
284 env['LINKFLAGS'] += ['-fprofile-generate']
285 if env['pgo'] == 'use':
286 env['CCFLAGS'] += ['-fprofile-use']
287 env['LINKFLAGS'] += ['-fprofile-use']
289 # Profiling
290 if env['flavor'] == 'prof':
291 proflibs = ['/usr/lib/oprofile', '/usr/local/lib/oprofile']
292 env['LIBPATH'] += ['proflibs']
293 env['RPATH'] += ['proflibs']
294 if conf.CheckPKG('opagent'):
295 conf.Define('USE_OPROFILE', 1)
296 else:
297 print "Can't build prof without oprofile, disabling"
299 tarname = 'dolphin-' + rev
300 env['TARFLAGS'] = '-cj'
301 env['TARSUFFIX'] = '.tar.bz2'
303 if env['install'] == 'local':
304 env['binary_dir'] = '#' + env['prefix']
305 env['data_dir'] = '#' + env['prefix']
306 env['plugin_dir'] = '#' + env['prefix'] + '/plugins'
307 if env['bundle']:
308 env.Tar(tarname, env['prefix'])
309 else:
310 env['prefix'] = Dir(env['prefix']).abspath
311 env['binary_dir'] = env['prefix'] + '/bin'
312 env['data_dir'] = env['prefix'] + "/share/dolphin-emu"
313 env['plugin_dir'] = env['prefix'] + '/lib/dolphin-emu'
314 conf.Define('DATA_DIR', "\"" + env['data_dir'] + "/\"")
315 conf.Define('LIBS_DIR', "\"" + env['prefix'] + '/lib/dolphin-emu/' + "\"")
316 # Setup destdir for package building
317 # Warning: The program will not run from this location.
318 # It is assumed the package will later install it to the prefix.
319 if env.has_key('destdir'):
320 env['destdir'] = Dir(env['destdir']).abspath
321 env['binary_dir'] = env['destdir'] + env['binary_dir']
322 env['data_dir'] = env['destdir'] + env['data_dir']
323 env['plugin_dir'] = env['destdir'] + env['plugin_dir']
324 env['prefix'] = env['destdir'] + env['prefix']
325 if env['bundle']:
326 env.Command(tarname + env['TARSUFFIX'], env['prefix'],
327 'tar ' + env['TARFLAGS'] + 'C ' + env['destdir'] + \
328 ' -f ' + tarname + env['TARSUFFIX'] + ' ' + \
329 env['prefix'].split(env['destdir'], 1)[1][1:])
331 conf.Define('USER_DIR', "\"" + env['userdir'] + "\"")
333 # After all configuration tests are done
334 conf.Finish()
336 env.Alias('install', env['prefix'])
338 # Local (static) libraries must be first in the search path for the build in
339 # order that they can override system libraries, but they must not be found
340 # during autoconfiguration as they will then be detected as system libraries.
341 env['LIBPATH'].insert(0, env['local_libs'])
343 dirs = [
344 'Externals/Bochs_disasm',
345 #'Externals/CLRun',
346 'Externals/Lua',
347 'Externals/WiiUse/Src',
348 'Externals/GLew',
349 'Externals/LZO',
350 #'Externals/OpenAL',
351 'Externals/SDL',
352 'Externals/SOIL',
353 'Externals/SFML/src',
354 #'Externals/wxWidgets',
355 'Externals/zlib',
356 'Source/Core/AudioCommon/Src',
357 'Source/Core/Common/Src',
358 'Source/Core/Core/Src',
359 'Source/Core/DSPCore/Src',
360 'Source/Core/DebuggerUICommon/Src',
361 'Source/Core/DebuggerWX/Src',
362 'Source/Core/DiscIO/Src',
363 'Source/Core/DolphinWX/Src',
364 'Source/Core/InputCommon/Src',
365 'Source/Core/InputUICommon/Src',
366 'Source/Core/VideoCommon/Src',
367 'Source/DSPTool/Src',
368 'Source/Plugins/Plugin_DSP_HLE/Src',
369 'Source/Plugins/Plugin_DSP_LLE/Src',
370 #'Source/Plugins/Plugin_VideoDX11/Src',
371 #'Source/Plugins/Plugin_VideoDX9/Src',
372 #'Source/Plugins/Plugin_VideoMerge/Src',
373 'Source/Plugins/Plugin_VideoOGL/Src',
374 'Source/Plugins/Plugin_VideoSoftware/Src',
375 'Source/UnitTests',
378 # Now that platform configuration is done, propagate it to modules
379 for subdir in dirs:
380 SConscript(dirs = subdir, duplicate = 0, exports = 'env',
381 variant_dir = env['build_dir'] + os.sep + subdir)
382 if subdir.startswith('Source/Core'):
383 env['CPPPATH'] += ['#' + subdir]
385 # Print a nice progress indication when not compiling
386 Progress(['-\r', '\\\r', '|\r', '/\r'], interval = 5)
388 # Generate help, printing current status of options
389 Help(vars.GenerateHelpText(env))