blob: 2c216cc2ca2711da5bd3d2eaca3fb4e1efc785e6 [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
79options = Options()
80options.Add( EnumOption('platform',
81 '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'
140elif platform == 'msvc70':
141 env['MSVS_VERSION']='7.0'
142 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
143 env.Tool( tool )
144 env['CXXFLAGS']='-GR -GX /nologo /MT'
145elif platform == 'msvc71':
146 env['MSVS_VERSION']='7.1'
147 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
148 env.Tool( tool )
149 env['CXXFLAGS']='-GR -GX /nologo /MT'
150elif platform == 'msvc80':
151 env['MSVS_VERSION']='8.0'
152 for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
153 env.Tool( tool )
154 env['CXXFLAGS']='-GR -EHsc /nologo /MT'
155elif platform == 'mingw':
156 env.Tool( 'mingw' )
157 env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
Christopher Dunnf1a49462007-06-14 20:59:51 +0000158elif platform.startswith('linux-gcc'):
Christopher Dunne0d72242007-06-14 17:58:59 +0000159 env.Tool( 'default' )
160 env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" )
161else:
162 print "UNSUPPORTED PLATFORM."
163 env.Exit(1)
164
165env.Tool('doxygen')
166env.Tool('substinfile')
167env.Tool('targz')
168env.Tool('srcdist')
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +0000169env.Tool('glob')
Christopher Dunne0d72242007-06-14 17:58:59 +0000170
171env.Append( CPPPATH = ['#include'],
172 LIBPATH = lib_dir )
173short_platform = platform
174if short_platform.startswith('msvc'):
175 short_platform = short_platform[2:]
176env['LIB_PLATFORM'] = short_platform
177env['LIB_LINK_TYPE'] = 'lib' # static
178env['LIB_CRUNTIME'] = 'mt'
179env['LIB_NAME_SUFFIX'] = '${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}' # must match autolink naming convention
180env['JSONCPP_VERSION'] = JSONCPP_VERSION
181env['BUILD_DIR'] = env.Dir(build_dir)
182env['ROOTBUILD_DIR'] = env.Dir(rootbuild_dir)
183env['DIST_DIR'] = DIST_DIR
184class SrcDistAdder:
185 def __init__( self, env ):
186 self.env = env
187 def __call__( self, *args, **kw ):
188 apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) + args, kw )
189env['SRCDIST_ADD'] = SrcDistAdder( env )
190env['SRCDIST_TARGET'] = os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz' % env['JSONCPP_VERSION'] )
191env['SRCDIST_BUILDER'] = env.TarGz
192
193env_testing = env.Copy( )
194env_testing.Append( LIBS = ['json_${LIB_NAME_SUFFIX}'] )
195
196def buildJSONExample( env, target_sources, target_name ):
197 env = env.Copy()
198 env.Append( CPPPATH = ['#'] )
199 exe = env.Program( target=target_name,
200 source=target_sources )
201 env['SRCDIST_ADD']( source=[target_sources] )
202 global bin_dir
203 return env.Install( bin_dir, exe )
204
205def buildJSONTests( env, target_sources, target_name ):
206 jsontests_node = buildJSONExample( env, target_sources, target_name )
207 check_alias_target = env.Alias( 'check', jsontests_node, RunJSONTests( jsontests_node, jsontests_node ) )
208 env.AlwaysBuild( check_alias_target )
209
210def buildLibrary( env, target_sources, target_name ):
211 static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
212 source=target_sources )
213 shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
214 source=target_sources )
215 global lib_dir
216 env.Install( lib_dir, static_lib )
217 env.Install( lib_dir, shared_lib )
218 env['SRCDIST_ADD']( source=[target_sources] )
219
220Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests' )
221
222def buildProjectInDirectory( target_directory ):
223 global build_dir
224 target_build_dir = os.path.join( build_dir, target_directory )
225 target = os.path.join( target_directory, 'sconscript' )
226 SConscript( target, build_dir=target_build_dir, duplicate=0 )
227 env['SRCDIST_ADD']( source=[target] )
228
229
230def runJSONTests_action( target, source = None, env = None ):
231 # Add test scripts to python path
232 jsontest_path = Dir( '#test' ).abspath
233 sys.path.insert( 0, jsontest_path )
234 import runjsontests
235 return runjsontests.runAllTests( os.path.abspath(source), jsontest_path )
236
237def runJSONTests_string( target, source = None, env = None ):
238 return 'RunJSONTests("%s")' % source
239
Christopher Dunne0d72242007-06-14 17:58:59 +0000240import SCons.Action
241ActionFactory = SCons.Action.ActionFactory
242RunJSONTests = ActionFactory(runJSONTests_action, runJSONTests_string )
243
244env.Alias( 'check' )
245
246srcdist_cmd = env['SRCDIST_ADD']( source = """
247 AUTHORS README.txt SConstruct
248 """.split() )
249env.Alias( 'src-dist', srcdist_cmd )
250
251buildProjectInDirectory( 'src/jsontestrunner' )
252buildProjectInDirectory( 'src/lib_json' )
Christopher Dunn8f5ddcf2009-05-11 20:04:10 +0000253#buildProjectInDirectory( 'doc' ) # THIS IS BROKEN.
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +0000254#print env.Dump()
Christopher Dunnf1a49462007-06-14 20:59:51 +0000255