* remove a bug to compile with VC6
[hkl.git] / SConstruct
bloba257e2b8b0ca4479c2062387dd0b3bd70ad415d1
1 # vi:filetype=python:expandtab:tabstop=2:shiftwidth=2
2 import os, sys
4 #sys.path.append('tool')
6 #----------------------------------------------------------
7 # Required runtime environment
8 #----------------------------------------------------------
10 # FIXME: I remember lyx requires higher version of python?
11 EnsurePythonVersion(1, 5)
12 # Please use at least 0.96.91 (not 0.96.1)
13 EnsureSConsVersion(0, 96, 91)
15 #----------------------------------------------------------
16 # Global definitions
17 #----------------------------------------------------------
19 # some global settings
20 PACKAGE_VERSION = '2.3.0'
21 DEVEL_VERSION = True
22 default_build_mode = 'debug'
24 PACKAGE = 'hkl'
25 PACKAGE_BUGREPORT = 'picca@synchrotron-soleil.fr'
26 PACKAGE_NAME = 'hkl'
27 PACKAGE_TARNAME = 'hkl'
28 PACKAGE_STRING = '%s %s' % (PACKAGE_NAME, PACKAGE_VERSION)
30 dirs_common = ['src', 'test', 'doc']
32 #----------------------------------------------------------
33 # platform dependent settings
34 #----------------------------------------------------------
35 if os.name == 'nt':
36 platform_name = 'win32'
37 dirs_platform = []
38 elif os.name == 'posix' and sys.platform != 'cygwin':
39 platform_name = sys.platform
40 dirs_platform = ['binding/python', 'src/gui']
42 #---------------------------------------------------------
43 # Handling options
44 #----------------------------------------------------------
45 option_file = 'config-' + platform_name + '.py'
47 opts = Options(option_file)
48 opts.AddOptions(
49 # debug or release build
50 EnumOption('mode', 'Building method', default_build_mode, allowed_values = ('debug', 'release')),
51 BoolOption('profile', 'Whether or not enable profiling', False),
52 # cppunit
53 BoolOption('test', 'Build and run the unit test', True),
54 PathOption('cppunit_lib_path', 'Path to cppunit library directory', None),
55 PathOption('cppunit_inc_path', 'Path to cppunit includes directory', None),
58 #---------------------------------------------------------
59 # Setting up environment
60 #---------------------------------------------------------
61 env = Environment(toolpath = ['tool'], tools = ['default', 'doxygen'], options = opts)
63 # create the build directory
64 build_dir = os.path.join(env['mode'], platform_name)
65 if not os.path.isdir(build_dir):
66 os.makedirs(build_dir)
68 # -h will print out help info
69 Help(opts.GenerateHelpText(env))
71 #add the default cxxflags and ldflags depending on the platform
72 cxxflags = []
73 linkflags = []
75 if platform_name == 'linux2':
76 cxxflags += ['-Wall']
77 elif platform_name == 'win32':
78 cxxflags += ['/GX', '/MD', '/GR']
80 #add the debug flag if needed
81 mode = None
82 if env.has_key('mode'):
83 mode = env['mode']
84 if mode == 'debug':
85 if platform_name == 'win32':
86 cxxflags += ['/ZI']
87 elif platform_name == 'linux2':
88 cxxflags += ['-g', '-O0']
89 elif mode == 'release':
90 if platform_name == 'linux2':
91 cxxflags += ['-O2']
92 elif platform_name == 'win32':
93 cxxflags += ['/Op']
95 env.AppendUnique(CXXFLAGS = cxxflags)
96 env.AppendUnique(LINKFLAGS = linkflags)
98 # Create a builder for tests
99 def builder_unit_test(target, source, env):
100 app = str(source[0].abspath)
101 if os.spawnl(os.P_WAIT, app, app) == 0:
102 open(str(target[0]),'w').write("PASSED\n")
103 else:
104 return 1
106 bld = Builder(action = builder_unit_test)
107 env.Append(BUILDERS = {'Test' : bld})
108 opts.Save(option_file, env)
110 #----------------------------------------------------------
111 # Start building
112 #----------------------------------------------------------
114 #put the SConsignFile in one place
115 sconsign_file = os.path.join(build_dir, '.sconsign')
116 env.SConsignFile(sconsign_file)
118 #no default target add manually
119 Default(None)
120 dirs = dirs_common + dirs_platform
121 for dir in dirs:
122 file = os.path.join(dir, 'SConscript')
123 env.SConscript(file, build_dir = os.path.join(build_dir, dir), duplicate = 0, exports = 'env')