blob: de0671034e59165c3312a59cc22b6f01342069ea [file] [log] [blame]
Baptiste Lepilleur32927b02008-01-21 08:37:06 +00001"""
2Build system can be clean-up by sticking to a few core production factory, with automatic dependencies resolution.
34 basic project productions:
4- library
5- binary
6- documentation
7- tests
8
9* Library:
10 Input:
11 - dependencies (other libraries)
12 - headers: include path & files
13 - sources
14 - generated sources
15 - resources
16 - generated resources
17 Production:
18 - Static library
19 - Dynamic library
20 - Naming rule
21 Life-cycle:
22 - Library compilation
23 - Compilation as a dependencies
24 - Run-time
25 - Packaging
26 Identity:
27 - Name
28 - Version
29* Binary:
30 Input:
31 - dependencies (other libraries)
32 - headers: include path & files (usually empty)
33 - sources
34 - generated sources
35 - resources
36 - generated resources
37 - supported variant (optimized/debug, dll/static...)
38 Production:
39 - Binary executable
40 - Manifest [on some platforms]
41 - Debug symbol [on some platforms]
42 Life-cycle:
43 - Compilation
44 - Run-time
45 - Packaging
46 Identity:
47 - Name
48 - Version
49* Documentation:
50 Input:
51 - dependencies (libraries, binaries)
52 - additional sources
53 - generated sources
54 - resources
55 - generated resources
56 - supported variant (public/internal)
57 Production:
58 - HTML documentation
59 - PDF documentation
60 - CHM documentation
61 Life-cycle:
62 - Documentation
63 - Packaging
64 - Test
65 Identity:
66 - Name
67 - Version
68"""
69
70
71
Christopher Dunne0d72242007-06-14 17:58:59 +000072import os
73import os.path
74import sys
75
76JSONCPP_VERSION = '0.1'
77DIST_DIR = '#dist'
78
Christopher Dunn060c45a2009-05-24 22:22:08 +000079options = Variables()
80options.Add( EnumVariable('platform',
Christopher Dunne0d72242007-06-14 17:58:59 +000081 'Platform (compiler/stl) used to build the project',
82 'msvc71',
83 allowed_values='suncc vacpp mingw msvc6 msvc7 msvc71 msvc80 linux-gcc'.split(),
84 ignorecase=2) )
85
86try:
87 platform = ARGUMENTS['platform']
Christopher Dunnf1a49462007-06-14 20:59:51 +000088 if platform == 'linux-gcc':
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000089 CXX = 'g++' # not quite right, but env is not yet available.
90 import commands
91 version = commands.getoutput('%s -dumpversion' %CXX)
92 platform = 'linux-gcc-%s' %version
93 print "Using platform '%s'" %platform
94 LD_LIBRARY_PATH = os.environ.get('LD_LIBRARY_PATH', '')
95 LD_LIBRARY_PATH = "%s:libs/%s" %(LD_LIBRARY_PATH, platform)
96 os.environ['LD_LIBRARY_PATH'] = LD_LIBRARY_PATH
97 print "LD_LIBRARY_PATH =", LD_LIBRARY_PATH
Christopher Dunne0d72242007-06-14 17:58:59 +000098except KeyError:
99 print 'You must specify a "platform"'
100 sys.exit(2)
101
102print "Building using PLATFORM =", platform
103
104rootbuild_dir = Dir('#buildscons')
105build_dir = os.path.join( '#buildscons', platform )
106bin_dir = os.path.join( '#bin', platform )
107lib_dir = os.path.join( '#libs', platform )
108sconsign_dir_path = Dir(build_dir).abspath
109sconsign_path = os.path.join( sconsign_dir_path, '.sconsign.dbm' )
110
111# Ensure build directory exist (SConsignFile fail otherwise!)
112if not os.path.exists( sconsign_dir_path ):
113 os.makedirs( sconsign_dir_path )
114
115# Store all dependencies signature in a database
116SConsignFile( sconsign_path )
117
118env = Environment( ENV = {'PATH' : os.environ['PATH']},
119 toolpath = ['scons-tools'],
120 tools=[] ) #, tools=['default'] )
121
122if platform == 'suncc':
123 env.Tool( 'sunc++' )
124 env.Tool( 'sunlink' )
125 env.Tool( 'sunar' )
126 env.Append( LIBS = ['pthreads'] )
127elif platform == 'vacpp':
128 env.Tool( 'default' )
129 env.Tool( 'aixcc' )
130 env['CXX'] = 'xlC_r' #scons does not pick-up the correct one !
131 # using xlC_r ensure multi-threading is enabled:
132 # http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.vacpp7a.doc/compiler/ref/cuselect.htm
133 env.Append( CCFLAGS = '-qrtti=all',
134 LINKFLAGS='-bh:5' ) # -bh:5 remove duplicate symbol warning
135elif platform == 'msvc6':
136 env['MSVS_VERSION']='6.0'
137 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
138 env.Tool( tool )
139 env['CXXFLAGS']='-GR -GX /nologo /MT'
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000140 env['SHARED_LIB_ENABLED'] = False
Christopher Dunne0d72242007-06-14 17:58:59 +0000141elif platform == 'msvc70':
142 env['MSVS_VERSION']='7.0'
143 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
144 env.Tool( tool )
145 env['CXXFLAGS']='-GR -GX /nologo /MT'
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000146 env['SHARED_LIB_ENABLED'] = False
Christopher Dunne0d72242007-06-14 17:58:59 +0000147elif platform == 'msvc71':
148 env['MSVS_VERSION']='7.1'
149 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
150 env.Tool( tool )
151 env['CXXFLAGS']='-GR -GX /nologo /MT'
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000152 env['SHARED_LIB_ENABLED'] = False
Christopher Dunne0d72242007-06-14 17:58:59 +0000153elif platform == 'msvc80':
154 env['MSVS_VERSION']='8.0'
155 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
156 env.Tool( tool )
157 env['CXXFLAGS']='-GR -EHsc /nologo /MT'
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000158 env['SHARED_LIB_ENABLED'] = False
Christopher Dunne0d72242007-06-14 17:58:59 +0000159elif platform == 'mingw':
160 env.Tool( 'mingw' )
161 env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000162 env['SHARED_LIB_ENABLED'] = False
Christopher Dunnf1a49462007-06-14 20:59:51 +0000163elif platform.startswith('linux-gcc'):
Christopher Dunne0d72242007-06-14 17:58:59 +0000164 env.Tool( 'default' )
165 env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" )
166else:
167 print "UNSUPPORTED PLATFORM."
168 env.Exit(1)
169
170env.Tool('doxygen')
171env.Tool('substinfile')
172env.Tool('targz')
173env.Tool('srcdist')
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000174env.Tool('globtool')
Christopher Dunne0d72242007-06-14 17:58:59 +0000175
176env.Append( CPPPATH = ['#include'],
177 LIBPATH = lib_dir )
178short_platform = platform
179if short_platform.startswith('msvc'):
180 short_platform = short_platform[2:]
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000181# Notes: on Windows you need to rebuild the source for each variant
182# Build script does not support that yet so we only build static libraries.
183env['SHARED_LIB_ENABLED'] = env.get('SHARED_LIB_ENABLED', True)
Christopher Dunne0d72242007-06-14 17:58:59 +0000184env['LIB_PLATFORM'] = short_platform
185env['LIB_LINK_TYPE'] = 'lib' # static
186env['LIB_CRUNTIME'] = 'mt'
187env['LIB_NAME_SUFFIX'] = '${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}' # must match autolink naming convention
188env['JSONCPP_VERSION'] = JSONCPP_VERSION
189env['BUILD_DIR'] = env.Dir(build_dir)
190env['ROOTBUILD_DIR'] = env.Dir(rootbuild_dir)
191env['DIST_DIR'] = DIST_DIR
192class SrcDistAdder:
193 def __init__( self, env ):
194 self.env = env
195 def __call__( self, *args, **kw ):
196 apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) + args, kw )
197env['SRCDIST_ADD'] = SrcDistAdder( env )
198env['SRCDIST_TARGET'] = os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz' % env['JSONCPP_VERSION'] )
199env['SRCDIST_BUILDER'] = env.TarGz
200
Christopher Dunn060c45a2009-05-24 22:22:08 +0000201env_testing = env.Clone( )
Christopher Dunne0d72242007-06-14 17:58:59 +0000202env_testing.Append( LIBS = ['json_${LIB_NAME_SUFFIX}'] )
203
204def buildJSONExample( env, target_sources, target_name ):
Christopher Dunn060c45a2009-05-24 22:22:08 +0000205 env = env.Clone()
Christopher Dunne0d72242007-06-14 17:58:59 +0000206 env.Append( CPPPATH = ['#'] )
207 exe = env.Program( target=target_name,
208 source=target_sources )
209 env['SRCDIST_ADD']( source=[target_sources] )
210 global bin_dir
211 return env.Install( bin_dir, exe )
212
213def buildJSONTests( env, target_sources, target_name ):
214 jsontests_node = buildJSONExample( env, target_sources, target_name )
215 check_alias_target = env.Alias( 'check', jsontests_node, RunJSONTests( jsontests_node, jsontests_node ) )
216 env.AlwaysBuild( check_alias_target )
217
218def buildLibrary( env, target_sources, target_name ):
219 static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
220 source=target_sources )
Christopher Dunne0d72242007-06-14 17:58:59 +0000221 global lib_dir
222 env.Install( lib_dir, static_lib )
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000223 if env['SHARED_LIB_ENABLED']:
224 shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
225 source=target_sources )
226 env.Install( lib_dir, shared_lib )
Christopher Dunne0d72242007-06-14 17:58:59 +0000227 env['SRCDIST_ADD']( source=[target_sources] )
228
229Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests' )
230
231def buildProjectInDirectory( target_directory ):
232 global build_dir
233 target_build_dir = os.path.join( build_dir, target_directory )
234 target = os.path.join( target_directory, 'sconscript' )
235 SConscript( target, build_dir=target_build_dir, duplicate=0 )
236 env['SRCDIST_ADD']( source=[target] )
237
238
239def runJSONTests_action( target, source = None, env = None ):
240 # Add test scripts to python path
241 jsontest_path = Dir( '#test' ).abspath
242 sys.path.insert( 0, jsontest_path )
243 import runjsontests
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000244 return runjsontests.runAllTests( os.path.abspath(source[0].path), jsontest_path )
Christopher Dunne0d72242007-06-14 17:58:59 +0000245
246def runJSONTests_string( target, source = None, env = None ):
Baptiste Lepilleur64e07e52009-11-18 21:27:06 +0000247 return 'RunJSONTests("%s")' % source[0]
Christopher Dunne0d72242007-06-14 17:58:59 +0000248
Christopher Dunne0d72242007-06-14 17:58:59 +0000249import SCons.Action
250ActionFactory = SCons.Action.ActionFactory
251RunJSONTests = ActionFactory(runJSONTests_action, runJSONTests_string )
252
253env.Alias( 'check' )
254
255srcdist_cmd = env['SRCDIST_ADD']( source = """
256 AUTHORS README.txt SConstruct
257 """.split() )
258env.Alias( 'src-dist', srcdist_cmd )
259
260buildProjectInDirectory( 'src/jsontestrunner' )
261buildProjectInDirectory( 'src/lib_json' )
Christopher Dunn060c45a2009-05-24 22:22:08 +0000262buildProjectInDirectory( 'doc' )
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +0000263#print env.Dump()
Christopher Dunnf1a49462007-06-14 20:59:51 +0000264