* now the twoC geometry pass the tests.
[hkl.git] / SConstruct
blobc5863608cdb45afcab0fa41a08ce2c60201b3a41
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 print os.name
36 if os.name == 'nt':
37 platform_name = 'win32'
38 dirs_platform = []
39 elif os.name == 'posix' and sys.platform != 'cygwin':
40 platform_name = sys.platform
41 #dirs_platform = ['binding/python', 'src/gui']
42 dirs_platform = []
44 #---------------------------------------------------------
45 # Handling options
46 #----------------------------------------------------------
47 option_file = 'config-' + platform_name + '.py'
49 opts = Options(option_file)
50 opts.AddOptions(
51 # debug or release build
52 EnumOption('mode', 'Building method', default_build_mode, allowed_values = ('debug', 'release')),
53 BoolOption('profile', 'Whether or not enable profiling', False),
54 # cppunit
55 BoolOption('test', 'Build and run the unit test', True),
56 PathOption('cppunit_lib_path', 'Path to cppunit library directory', None),
57 PathOption('cppunit_inc_path', 'Path to cppunit includes directory', None),
60 #---------------------------------------------------------
61 # Setting up environment
62 #---------------------------------------------------------
63 env = Environment(toolpath = ['tool'], tools = ['default', 'doxygen'], options = opts)
65 # create the build directory
66 build_dir = os.path.join(env['mode'], platform_name)
67 if not os.path.isdir(build_dir):
68 os.makedirs(build_dir)
70 # -h will print out help info
71 Help(opts.GenerateHelpText(env))
73 #add the default cxxflags and ldflags depending on the platform
74 cflags = []
75 cxxflags = []
76 cppdefines = []
77 linkflags = []
79 if platform_name == 'linux2':
80 cflags += ['-Wall']
81 cxxflags += ['-Wall']
82 elif platform_name == 'win32':
83 cflags += ['/GX', '/MD', '/GR']
84 cxxflags += ['/GX', '/MD', '/GR']
86 #add the debug flag if needed
87 mode = None
88 if env.has_key('mode'):
89 mode = env['mode']
90 if mode == 'debug':
91 if platform_name == 'win32':
92 cflags += ['/ZI']
93 cxxflags += ['/ZI']
94 elif platform_name == 'linux2':
95 cflags += ['-g', '-O0']
96 cxxflags += ['-g', '-O0']
97 elif mode == 'release':
98 cppdefines += ['NDEBUG']
99 if platform_name == 'linux2':
100 cflags += ['-O2']
101 cxxflags += ['-O2']
102 elif platform_name == 'win32':
103 cflags += ['/Op']
104 cxxflags += ['/Op']
106 env.AppendUnique(CFLAGS = cflags)
107 env.AppendUnique(CXXFLAGS = cxxflags)
108 env.AppendUnique(CPPDEFINES = cppdefines)
109 env.AppendUnique(LINKFLAGS = linkflags)
111 # Create a builder for tests
112 def builder_unit_test(target, source, env):
113 app = str(source[0].abspath)
114 if os.spawnl(os.P_WAIT, app, app) == 0:
115 open(str(target[0]),'w').write("PASSED\n")
116 else:
117 return 1
119 bld = Builder(action = builder_unit_test)
120 env.Append(BUILDERS = {'Test' : bld})
121 opts.Save(option_file, env)
123 #----------------------------------------------------------
124 # Start building
125 #----------------------------------------------------------
127 #put the SConsignFile in one place
128 sconsign_file = os.path.join(build_dir, '.sconsign')
129 env.SConsignFile(sconsign_file)
131 #no default target add manually
132 Default(None)
133 dirs = dirs_common + dirs_platform
134 for dir in dirs:
135 file = os.path.join(dir, 'SConscript')
136 env.SConscript(file, build_dir = os.path.join(build_dir, dir), duplicate = 0, exports = 'env')