blob: c714f39736befec3d1559d331e6e751a7a319910 [file] [log] [blame]
Christopher Dunne0d72242007-06-14 17:58:59 +00001import os
2import os.path
3import sys
4
5JSONCPP_VERSION = '0.1'
6DIST_DIR = '#dist'
7
8options = Options()
9options.Add( EnumOption('platform',
10 'Platform (compiler/stl) used to build the project',
11 'msvc71',
12 allowed_values='suncc vacpp mingw msvc6 msvc7 msvc71 msvc80 linux-gcc'.split(),
13 ignorecase=2) )
14
15try:
16 platform = ARGUMENTS['platform']
Christopher Dunnf1a49462007-06-14 20:59:51 +000017 if platform == 'linux-gcc':
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000018 CXX = 'g++' # not quite right, but env is not yet available.
19 import commands
20 version = commands.getoutput('%s -dumpversion' %CXX)
21 platform = 'linux-gcc-%s' %version
22 print "Using platform '%s'" %platform
23 LD_LIBRARY_PATH = os.environ.get('LD_LIBRARY_PATH', '')
24 LD_LIBRARY_PATH = "%s:libs/%s" %(LD_LIBRARY_PATH, platform)
25 os.environ['LD_LIBRARY_PATH'] = LD_LIBRARY_PATH
26 print "LD_LIBRARY_PATH =", LD_LIBRARY_PATH
Christopher Dunne0d72242007-06-14 17:58:59 +000027except KeyError:
28 print 'You must specify a "platform"'
29 sys.exit(2)
30
31print "Building using PLATFORM =", platform
32
33rootbuild_dir = Dir('#buildscons')
34build_dir = os.path.join( '#buildscons', platform )
35bin_dir = os.path.join( '#bin', platform )
36lib_dir = os.path.join( '#libs', platform )
37sconsign_dir_path = Dir(build_dir).abspath
38sconsign_path = os.path.join( sconsign_dir_path, '.sconsign.dbm' )
39
40# Ensure build directory exist (SConsignFile fail otherwise!)
41if not os.path.exists( sconsign_dir_path ):
42 os.makedirs( sconsign_dir_path )
43
44# Store all dependencies signature in a database
45SConsignFile( sconsign_path )
46
47env = Environment( ENV = {'PATH' : os.environ['PATH']},
48 toolpath = ['scons-tools'],
49 tools=[] ) #, tools=['default'] )
50
51if platform == 'suncc':
52 env.Tool( 'sunc++' )
53 env.Tool( 'sunlink' )
54 env.Tool( 'sunar' )
55 env.Append( LIBS = ['pthreads'] )
56elif platform == 'vacpp':
57 env.Tool( 'default' )
58 env.Tool( 'aixcc' )
59 env['CXX'] = 'xlC_r' #scons does not pick-up the correct one !
60 # using xlC_r ensure multi-threading is enabled:
61 # http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.vacpp7a.doc/compiler/ref/cuselect.htm
62 env.Append( CCFLAGS = '-qrtti=all',
63 LINKFLAGS='-bh:5' ) # -bh:5 remove duplicate symbol warning
64elif platform == 'msvc6':
65 env['MSVS_VERSION']='6.0'
66 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
67 env.Tool( tool )
68 env['CXXFLAGS']='-GR -GX /nologo /MT'
69elif platform == 'msvc70':
70 env['MSVS_VERSION']='7.0'
71 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
72 env.Tool( tool )
73 env['CXXFLAGS']='-GR -GX /nologo /MT'
74elif platform == 'msvc71':
75 env['MSVS_VERSION']='7.1'
76 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
77 env.Tool( tool )
78 env['CXXFLAGS']='-GR -GX /nologo /MT'
79elif platform == 'msvc80':
80 env['MSVS_VERSION']='8.0'
81 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
82 env.Tool( tool )
83 env['CXXFLAGS']='-GR -EHsc /nologo /MT'
84elif platform == 'mingw':
85 env.Tool( 'mingw' )
86 env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
Christopher Dunnf1a49462007-06-14 20:59:51 +000087elif platform.startswith('linux-gcc'):
Christopher Dunne0d72242007-06-14 17:58:59 +000088 env.Tool( 'default' )
89 env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" )
90else:
91 print "UNSUPPORTED PLATFORM."
92 env.Exit(1)
93
94env.Tool('doxygen')
95env.Tool('substinfile')
96env.Tool('targz')
97env.Tool('srcdist')
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000098env.Tool('glob')
Christopher Dunne0d72242007-06-14 17:58:59 +000099
100env.Append( CPPPATH = ['#include'],
101 LIBPATH = lib_dir )
102short_platform = platform
103if short_platform.startswith('msvc'):
104 short_platform = short_platform[2:]
105env['LIB_PLATFORM'] = short_platform
106env['LIB_LINK_TYPE'] = 'lib' # static
107env['LIB_CRUNTIME'] = 'mt'
108env['LIB_NAME_SUFFIX'] = '${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}' # must match autolink naming convention
109env['JSONCPP_VERSION'] = JSONCPP_VERSION
110env['BUILD_DIR'] = env.Dir(build_dir)
111env['ROOTBUILD_DIR'] = env.Dir(rootbuild_dir)
112env['DIST_DIR'] = DIST_DIR
113class SrcDistAdder:
114 def __init__( self, env ):
115 self.env = env
116 def __call__( self, *args, **kw ):
117 apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) + args, kw )
118env['SRCDIST_ADD'] = SrcDistAdder( env )
119env['SRCDIST_TARGET'] = os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz' % env['JSONCPP_VERSION'] )
120env['SRCDIST_BUILDER'] = env.TarGz
121
122env_testing = env.Copy( )
123env_testing.Append( LIBS = ['json_${LIB_NAME_SUFFIX}'] )
124
125def buildJSONExample( env, target_sources, target_name ):
126 env = env.Copy()
127 env.Append( CPPPATH = ['#'] )
128 exe = env.Program( target=target_name,
129 source=target_sources )
130 env['SRCDIST_ADD']( source=[target_sources] )
131 global bin_dir
132 return env.Install( bin_dir, exe )
133
134def buildJSONTests( env, target_sources, target_name ):
135 jsontests_node = buildJSONExample( env, target_sources, target_name )
136 check_alias_target = env.Alias( 'check', jsontests_node, RunJSONTests( jsontests_node, jsontests_node ) )
137 env.AlwaysBuild( check_alias_target )
138
139def buildLibrary( env, target_sources, target_name ):
140 static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
141 source=target_sources )
142 shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
143 source=target_sources )
144 global lib_dir
145 env.Install( lib_dir, static_lib )
146 env.Install( lib_dir, shared_lib )
147 env['SRCDIST_ADD']( source=[target_sources] )
148
149Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests' )
150
151def buildProjectInDirectory( target_directory ):
152 global build_dir
153 target_build_dir = os.path.join( build_dir, target_directory )
154 target = os.path.join( target_directory, 'sconscript' )
155 SConscript( target, build_dir=target_build_dir, duplicate=0 )
156 env['SRCDIST_ADD']( source=[target] )
157
158
159def runJSONTests_action( target, source = None, env = None ):
160 # Add test scripts to python path
161 jsontest_path = Dir( '#test' ).abspath
162 sys.path.insert( 0, jsontest_path )
163 import runjsontests
164 return runjsontests.runAllTests( os.path.abspath(source), jsontest_path )
165
166def runJSONTests_string( target, source = None, env = None ):
167 return 'RunJSONTests("%s")' % source
168
Christopher Dunne0d72242007-06-14 17:58:59 +0000169import SCons.Action
170ActionFactory = SCons.Action.ActionFactory
171RunJSONTests = ActionFactory(runJSONTests_action, runJSONTests_string )
172
173env.Alias( 'check' )
174
175srcdist_cmd = env['SRCDIST_ADD']( source = """
176 AUTHORS README.txt SConstruct
177 """.split() )
178env.Alias( 'src-dist', srcdist_cmd )
179
180buildProjectInDirectory( 'src/jsontestrunner' )
181buildProjectInDirectory( 'src/lib_json' )
182buildProjectInDirectory( 'doc' )
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +0000183#print env.Dump()
Christopher Dunnf1a49462007-06-14 20:59:51 +0000184