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