Mercurial > fife-parpg
comparison SConstruct @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | 94470d79576f |
children | 2a1259ce2b95 |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 import os, sys | 1 import os, sys |
2 from utils.util_scripts.path import path as upath | 2 import utils.scons.scons_utils as utils |
3 | 3 from distutils.sysconfig import get_python_lib |
4 opts = Options('options.py', ARGUMENTS) | 4 |
5 opts.Add(BoolOption('debug', 'Build with debuginfos and without optimisations', 1)) | 5 _sep = os.path.sep |
6 opts.Add(BoolOption('tests', 'Build testcases in unit_tests', 0)) | 6 |
7 opts.Add(BoolOption('noengine', 'Prevents building of engine, use e.g. for util/test tweaking', 0)) | 7 vars = Variables() |
8 opts.Add(BoolOption('opengl', 'Compile OpenGL support', 1)) | 8 vars.Add(PathVariable('DESTDIR', |
9 opts.Add(EnumOption('script', 'Selects generated scripting language bindings', 'python', allowed_values=('python', 'lua'))) | 9 'Destination directory (prepended to prefix)', |
10 opts.Add(BoolOption('profile', 'Build with profiling information', 0)) | 10 None, |
11 opts.Add(BoolOption('projectfiles_only', "Creates IDE project files only. If defined, won't build code. " + | 11 PathVariable.PathAccept )) |
12 "Note that normal builds generate these files also automatically.", 0)) | 12 |
13 opts.Add(BoolOption('utils', 'Build utilities', 0)) | 13 #propagate the invoking users complete external environment |
14 opts.Add(BoolOption('ext', 'Build external dependencies', 0)) | 14 env = Environment(variables = vars, |
15 opts.Add(BoolOption('docs', "Generates static analysis documentation into doc-folder. If defined, won't build code", 0)) | 15 ENV = os.environ, |
16 opts.Add(BoolOption('zip', 'Enable ZIP archive support', 1)) | 16 DESTDIR = '${DESTDIR}') |
17 opts.Add(BoolOption('log', 'Enables logging for the engine', 1)) | 17 |
18 | 18 env.EnsureSConsVersion(1,2) |
19 opts.Add(BoolOption('rend_camzone', 'Enables camera zone renderer', 0)) | 19 |
20 opts.Add(BoolOption('rend_grid', 'Enables grid renderer', 0)) | 20 #************************************************************************** |
21 | 21 #add any command line options here |
22 # Platform-specific prefix directories | 22 #************************************************************************** |
23 if sys.platform == 'linux2': | 23 AddOption('--release', |
24 opts.Add(PathOption('PREFIX', 'Directory to install under', '/usr')) | 24 dest='release', |
25 | 25 action="store_true", |
26 #env = Environment(options = opts, ENV = {'PATH' : os.environ['PATH']}) | 26 help='Builds the release version of the binaries', |
27 env = Environment(options = opts, ENV = os.environ) | 27 default=False) |
28 env.Replace(SCONS_ROOT_PATH=str(upath('.').abspath())) | 28 |
29 rootp = env['SCONS_ROOT_PATH'] | 29 AddOption('--disable-opengl', |
30 | 30 dest='disable-opengl', |
31 Help(opts.GenerateHelpText(env)) | 31 action="store_true", |
32 | 32 help='Disable OpenGL support', |
33 # helper functions | 33 default=False) |
34 def tryConfigCommand(context, cmd): | 34 |
35 ret = context.TryAction(cmd)[0] | 35 AddOption('--disable-zip', |
36 context.Result(ret) | 36 dest='disable-zip', |
37 if ret: | 37 action="store_true", |
38 context.env.ParseConfig(cmd) | 38 help='Disable ZIP archive support', |
39 default=False) | |
40 | |
41 AddOption('--disable-log', | |
42 dest='disable-log', | |
43 action="store_true", | |
44 help='Disable engine logging support', | |
45 default=False) | |
46 | |
47 AddOption('--enable-rend-camzone', | |
48 dest='enable-rend-camzone', | |
49 action="store_true", | |
50 help='Enables camera zone renderer', | |
51 default=False) | |
52 | |
53 AddOption('--enable-rend-grid', | |
54 dest='enable-rend-grid', | |
55 action="store_true", | |
56 help='Enables camera grid renderer', | |
57 default=False) | |
58 | |
59 AddOption('--enable-profile', | |
60 dest='enable-profile', | |
61 action="store_true", | |
62 help='Build with profiling information', | |
63 default=False) | |
64 | |
65 AddOption('--prefix', | |
66 dest='prefix', | |
67 nargs=1, type='string', | |
68 action='store', | |
69 metavar='DIR', | |
70 help='installation prefix') | |
71 | |
72 AddOption('--python-prefix', | |
73 dest='python-prefix', | |
74 nargs=1, type='string', | |
75 action='store', | |
76 metavar='DIR', | |
77 help='Python module installation prefix') | |
78 | |
79 #************************************************************************** | |
80 #save command line options here | |
81 #************************************************************************** | |
82 if GetOption('release'): | |
83 debug = 0 | |
84 else: | |
85 debug = 1 | |
86 | |
87 if GetOption('disable-opengl'): | |
88 opengl = 0 | |
89 else: | |
90 opengl = 1 | |
91 | |
92 if GetOption('disable-zip'): | |
93 zip = 0 | |
94 else: | |
95 zip = 1 | |
96 | |
97 if GetOption('disable-log'): | |
98 log = 0 | |
99 else: | |
100 log = 1 | |
101 | |
102 if GetOption('enable-rend-camzone'): | |
103 rend_camzone = 1 | |
104 else: | |
105 rend_camzone = 0 | |
106 | |
107 if GetOption('enable-rend-grid'): | |
108 rend_grid = 1 | |
109 else: | |
110 rend_grid = 0 | |
111 | |
112 if GetOption('enable-profile'): | |
113 profile = 1 | |
114 else: | |
115 profile = 0 | |
116 | |
117 #set the default installation directories. | |
118 prefix = GetOption('prefix') | |
119 if prefix is None: | |
120 if sys.platform == 'win32': | |
121 prefix = '\\fife' | |
122 elif sys.platform == 'darwin': | |
123 prefix = '/opt/local' | |
124 else: | |
125 prefix = '/usr/local' | |
126 | |
127 pythonprefix = GetOption('python-prefix') | |
128 if pythonprefix is None: | |
129 pythonprefix = get_python_lib() | |
130 | |
131 if env.has_key('DESTDIR'): | |
132 prefix = env['DESTDIR'] + prefix | |
133 pythonprefix = env['DESTDIR'] + pythonprefix | |
134 | |
135 #************************************************************************** | |
136 #get platform specific information | |
137 #************************************************************************** | |
138 platformConfig = utils.getPlatformConfig() | |
139 env = platformConfig.initEnvironment(env) | |
140 env = platformConfig.addExtras(env, opengl) | |
141 | |
142 #************************************************************************** | |
143 #define custom library/header check functions | |
144 #************************************************************************** | |
145 conf = Configure(env, | |
146 custom_tests = {'checkPKG': utils.checkPKG, | |
147 'checkConf': utils.checkConf }, | |
148 conf_dir = os.path.join('#','build','.sconf_temp'), | |
149 log_file = os.path.join('#','build','config.log'), | |
150 clean=True) | |
151 | |
152 def checkForLib(lib, header='', language='c++'): | |
153 ret = conf.checkPKG(lib) | |
154 if not ret: | |
155 ret = conf.checkConf(lib) | |
156 if not ret: | |
157 if len(header): | |
158 ret = conf.CheckLibWithHeader(libs=lib, header=header, language=language) | |
159 else: | |
160 ret = conf.CheckLib(library=lib, language=language) | |
161 | |
39 return ret | 162 return ret |
40 | 163 |
41 def importConfig(config): | 164 def checkForLibs(liblist, required=1, language='c++'): |
42 module = __import__(config) | 165 ret = 0 |
43 parts = config.split('.') | 166 for lib, header in liblist: |
44 for part in parts[1:]: | 167 if (isinstance(lib, tuple)): |
45 module = getattr(module, part) | 168 for item in lib: |
46 return module | 169 ret = checkForLib(item, header, language) |
47 | 170 |
48 def getPlatformConfig(): | 171 if ret: |
49 pathparts = ('build', '%s-config' % sys.platform) | 172 env.AppendUnique(LIBS = [item]) |
50 filename = os.path.join(*pathparts) | 173 break |
51 sconsfilename = '.'.join(pathparts) | |
52 if os.path.exists(filename + '.py'): | |
53 return importConfig(sconsfilename) | |
54 else: | |
55 print 'no custom platform-config found (searched: %s.py)' % filename | |
56 filename += '-dist' | |
57 sconsfilename += '-dist' | |
58 if os.path.exists(filename + '.py'): | |
59 return importConfig(sconsfilename) | |
60 print 'no platform-config found (searched: %s.py)' % filename | |
61 Exit(1) | |
62 | |
63 # custom checks | |
64 def checkPKG(context, name): | |
65 context.Message('Checking for %s (using pkg-config)... ' % name) | |
66 return tryConfigCommand(context, 'pkg-config --libs --cflags \'%s\'' % name) | |
67 | |
68 def checkConf(context, name): | |
69 binary = '%s-config' % name.lower() | |
70 context.Message('Checking for %s (using %s)... ' % (name, binary)) | |
71 configcall = '%s --libs --cflags' %binary | |
72 return tryConfigCommand(context, configcall) | |
73 | |
74 def checkSimpleLib(context, liblist, header = '', lang = 'c++', required = 1): | |
75 for lib in liblist: | |
76 ret = checkPKG(context, lib) | |
77 if ret: | |
78 return ret | |
79 | |
80 ret = checkConf(context, lib) | |
81 if ret: | |
82 return ret | |
83 | |
84 if len(header): | |
85 ret = conf.CheckLibWithHeader(lib, header, lang) | |
86 else: | 174 else: |
87 ret = conf.CheckLib(lib,language=lang) | 175 ret = checkForLib(lib, header, language) |
88 | 176 if ret: |
89 if ret: | 177 env.AppendUnique(LIBS=[lib]) |
90 # print "ret: " + ret | 178 |
91 if not lib in conf.env['LIBS']: | 179 if required and not ret: |
92 conf.env.Append(LIBS = [lib]) | 180 if (isinstance(lib, tuple)): |
93 return ret | 181 for item in lib: |
94 | 182 print 'Required lib %s not found!' %item |
95 if required: | 183 else: |
96 print 'required lib %s not found :(' % lib | 184 print 'Required lib %s not found!' %lib |
97 Exit(1) | 185 Exit(1) |
98 | 186 |
99 return False | 187 #************************************************************************** |
100 | 188 #check the existence of required libraries and headers |
101 if env['projectfiles_only']: | 189 #************************************************************************** |
102 Export('env') | 190 required_libs = platformConfig.getRequiredLibs(opengl) |
103 SConscript(['engine/SConscript']) | 191 optional_libs = platformConfig.getOptionalLibs(opengl) |
104 elif env['docs']: | 192 |
105 _jp = os.path.join | 193 required_headers = platformConfig.getRequiredHeaders(opengl) |
106 # should prolly be done using scons builders... | 194 |
107 try: | 195 # do not run the check for dependencies if you are running |
108 print "removing old documentation directories" | 196 # a clean or building the external dependencies |
109 upath('doc/doxygen/html').rmtree() | 197 if not GetOption('clean') and 'ext' not in COMMAND_LINE_TARGETS: |
110 except OSError: | 198 if required_libs: |
111 pass | 199 checkForLibs(required_libs, required = 1) |
112 print "generating new doxygen documentation" | 200 if optional_libs: |
113 os.system('doxygen ' + _jp('doc', 'doxygen', 'doxyfile')) | 201 checkForLibs(optional_libs, required = 0) |
114 print "doxygen documentation created succesfully" | 202 if required_headers: |
115 | 203 for h in required_headers: |
116 elif env['ext']: | 204 conf.CheckHeader(h) |
117 Export('env') | 205 |
118 SConscript('ext/SConscript') | 206 #************************************************************************** |
119 else: | 207 #set variables based on command line options |
120 platformConfig = getPlatformConfig() | 208 #************************************************************************** |
121 env = platformConfig.initEnvironment(env) | 209 if debug: |
122 conf = Configure(env, | 210 env.AppendUnique(CXXFLAGS=['-ggdb', '-O0', '-D_DEBUG']) |
123 custom_tests = {'checkConf': checkConf, 'checkPKG': checkPKG, 'checkSimpleLib': checkSimpleLib}, | 211 engine_var_dir = os.path.join('build','engine','debug') |
124 conf_dir = '#/build/.sconf_temp', | 212 tests_var_dir = os.path.join('build','tests','debug') |
125 log_file = '#/build/config.log') | 213 print "Building DEBUG binaries..." |
126 | 214 else: |
127 platformConfig.addExtras(conf) | 215 env.AppendUnique(CXXFLAGS=['-O2']) |
128 env = conf.Finish() | 216 engine_var_dir = os.path.join('build','engine','release') |
129 | 217 tests_var_dir = os.path.join('build','tests','release') |
130 if sys.platform == "win32": | 218 print "Building RELEASE binaries..." |
131 env.Append(CPPFLAGS = ['-Wall']) | 219 |
132 else: | 220 if opengl: |
133 env.Append(CPPFLAGS = ['-Wall']) # removed old style cast warnings for now (swig creates these) | 221 env.Append(CPPDEFINES = ['HAVE_OPENGL']) |
134 | 222 if zip: |
135 if env['debug'] == 1: | 223 env.Append(CPPDEFINES = ['HAVE_ZIP']) |
136 env.Append(CPPFLAGS = ['-ggdb', '-O0']) | 224 if log: |
137 else: | 225 env.Append(CPPDEFINES = ['LOG_ENABLED']) |
138 if os.getenv('CXXFLAGS'): | 226 if rend_camzone: |
139 env.Append(CPPFLAGS = Split(os.environ['CXXFLAGS'])) | 227 env.Append(CPPDEFINES = ['RENDER_CAMZONES']) |
140 else: | 228 if rend_grid: |
141 env.Append(CPPFLAGS = ['-O2']) | 229 env.Append(CPPDEFINES = ['RENDER_GRID']) |
142 | 230 if profile: |
143 if env['profile']: | 231 env.Append(CPPFLAGS = ['-pg']) |
144 env.Append(CPPFLAGS = ['-pg']) | 232 env.Append(LINKFLAGS = ['-pg']) |
145 env.Append(LINKFLAGS = ['-pg']) | 233 |
146 | 234 #last but not least get any CXXFLAGS passed to scons via command line |
147 definemap = { | 235 if ARGUMENTS.get('CXXFLAGS'): |
148 'opengl': 'HAVE_OPENGL', | 236 env.AppendUnique(CXXFLAGS = Split(ARGUMENTS.get('CXXFLAGS'))) |
149 'zip': 'HAVE_ZIP', | 237 else: |
150 'log': 'LOG_ENABLED', | 238 env.AppendUnique(CXXFLAGS=['-Wall', '-Wno-unused']) |
151 'rend_camzone': 'RENDER_CAMZONES', | 239 |
152 'rend_grid': 'RENDER_GRID', | 240 #************************************************************************** |
153 } | 241 #global compiler flags used for ALL targets |
154 for k, v in definemap.items(): | 242 #************************************************************************** |
155 if env[k]: | 243 env.Append(CPPPATH='#engine/core') |
156 env.Append(CPPDEFINES = [v]) | 244 |
157 | 245 #************************************************************************** |
158 Export('env') | 246 #variables to pass to the SConscript |
159 | 247 #TODO: clean this up a bit. Should probably make sure unittest++ exists. |
160 if not env['noengine']: | 248 #************************************************************************** |
161 SConscript('engine/SConscript') | 249 opts = {'SRC' : os.path.join(os.getcwd(), 'engine',), |
162 | 250 'DEBUG' : debug, |
163 env.Append(LIBPATH = ['#/engine']) | 251 'PREFIX' : prefix, |
164 | 252 'TESTLIBS' : ['fife', 'UnitTest++'], |
165 if env['tests']: | 253 'PYTHON_PREFIX' : pythonprefix, |
166 SConscript('tests/core_tests/SConscript') | 254 'WRAP_COPY_DEST' : os.path.join('#engine', 'swigwrappers', 'python'), |
167 | 255 'PYLIB_COPY_DEST' : os.path.join('#engine', 'python', 'fife')} |
168 if env['utils']: | 256 |
169 SConscript([str(p) for p in upath('utils').walkfiles('SConscript')]) | 257 if debug: |
170 | 258 opts['LIBPATH'] = os.path.join(os.getcwd(), 'build', 'engine', 'debug') |
171 # vim: set filetype=python: | 259 else: |
260 opts['LIBPATH'] = os.path.join(os.getcwd(), 'build', 'engine', 'release') | |
261 | |
262 #************************************************************************** | |
263 #target for static and shared libraries | |
264 #************************************************************************** | |
265 Export('env') | |
266 | |
267 #build the engine | |
268 env.SConscript('engine/SConscript', variant_dir=engine_var_dir, duplicate=0, exports='opts') | |
269 | |
270 #build the engine tests | |
271 env.SConscript('tests/core_tests/SConscript', variant_dir=tests_var_dir, duplicate=0, exports='opts') | |
272 | |
273 #build the external dependencies | |
274 env.SConscript('ext/SConscript') | |
275 | |
276 #************************************************************************** | |
277 #documentation target | |
278 #************************************************************************** | |
279 def generate_docs(target = None, source = None, env = None): | |
280 os.system('doxygen $SOURCES') | |
281 | |
282 doc_builder = Builder(action = generate_docs) | |
283 env.Append(BUILDERS = {'BuildDocs': doc_builder}) | |
284 Alias('docs', env.BuildDocs('docs', os.path.join('doc', 'doxygen', 'doxyfile'))) | |
285 | |
286 #************************************************************************** | |
287 #Set the default target | |
288 #************************************************************************** | |
289 #clear the default target | |
290 Default() | |
291 #make fife-python the default target | |
292 Default('fife-python') | |
293 | |
294 # vim: set filetype=python: | |
295 |