blob: a957617866d86dd61151f535e017543beb1bbcf8 [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':
18 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')
98
99env.Append( CPPPATH = ['#include'],
100 LIBPATH = lib_dir )
101short_platform = platform
102if short_platform.startswith('msvc'):
103 short_platform = short_platform[2:]
104env['LIB_PLATFORM'] = short_platform
105env['LIB_LINK_TYPE'] = 'lib' # static
106env['LIB_CRUNTIME'] = 'mt'
107env['LIB_NAME_SUFFIX'] = '${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}' # must match autolink naming convention
108env['JSONCPP_VERSION'] = JSONCPP_VERSION
109env['BUILD_DIR'] = env.Dir(build_dir)
110env['ROOTBUILD_DIR'] = env.Dir(rootbuild_dir)
111env['DIST_DIR'] = DIST_DIR
112class SrcDistAdder:
113 def __init__( self, env ):
114 self.env = env
115 def __call__( self, *args, **kw ):
116 apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) + args, kw )
117env['SRCDIST_ADD'] = SrcDistAdder( env )
118env['SRCDIST_TARGET'] = os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz' % env['JSONCPP_VERSION'] )
119env['SRCDIST_BUILDER'] = env.TarGz
120
121env_testing = env.Copy( )
122env_testing.Append( LIBS = ['json_${LIB_NAME_SUFFIX}'] )
123
124def buildJSONExample( env, target_sources, target_name ):
125 env = env.Copy()
126 env.Append( CPPPATH = ['#'] )
127 exe = env.Program( target=target_name,
128 source=target_sources )
129 env['SRCDIST_ADD']( source=[target_sources] )
130 global bin_dir
131 return env.Install( bin_dir, exe )
132
133def buildJSONTests( env, target_sources, target_name ):
134 jsontests_node = buildJSONExample( env, target_sources, target_name )
135 check_alias_target = env.Alias( 'check', jsontests_node, RunJSONTests( jsontests_node, jsontests_node ) )
136 env.AlwaysBuild( check_alias_target )
137
138def buildLibrary( env, target_sources, target_name ):
139 static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
140 source=target_sources )
141 shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
142 source=target_sources )
143 global lib_dir
144 env.Install( lib_dir, static_lib )
145 env.Install( lib_dir, shared_lib )
146 env['SRCDIST_ADD']( source=[target_sources] )
147
148Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests' )
149
150def buildProjectInDirectory( target_directory ):
151 global build_dir
152 target_build_dir = os.path.join( build_dir, target_directory )
153 target = os.path.join( target_directory, 'sconscript' )
154 SConscript( target, build_dir=target_build_dir, duplicate=0 )
155 env['SRCDIST_ADD']( source=[target] )
156
157
158def runJSONTests_action( target, source = None, env = None ):
159 # Add test scripts to python path
160 jsontest_path = Dir( '#test' ).abspath
161 sys.path.insert( 0, jsontest_path )
162 import runjsontests
163 return runjsontests.runAllTests( os.path.abspath(source), jsontest_path )
164
165def runJSONTests_string( target, source = None, env = None ):
166 return 'RunJSONTests("%s")' % source
167
168##def buildDoc( doxyfile_path ):
169## doc_cmd = env.Doxygen( doxyfile_path )
170
171import SCons.Action
172ActionFactory = SCons.Action.ActionFactory
173RunJSONTests = ActionFactory(runJSONTests_action, runJSONTests_string )
174
175env.Alias( 'check' )
176
177srcdist_cmd = env['SRCDIST_ADD']( source = """
178 AUTHORS README.txt SConstruct
179 """.split() )
180env.Alias( 'src-dist', srcdist_cmd )
181
182buildProjectInDirectory( 'src/jsontestrunner' )
183buildProjectInDirectory( 'src/lib_json' )
184buildProjectInDirectory( 'doc' )
Christopher Dunnf1a49462007-06-14 20:59:51 +0000185