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