Baptiste Lepilleur | 4cd8bae | 2007-03-15 22:11:38 +0000 | [diff] [blame] | 1 | import os
|
| 2 | import os.path
|
| 3 | import sys
|
| 4 |
|
| 5 | JSONCPP_VERSION = '0.1'
|
| 6 | DIST_DIR = '#dist'
|
| 7 |
|
| 8 | options = Options()
|
| 9 | options.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 |
|
| 15 | try:
|
| 16 | platform = ARGUMENTS['platform']
|
| 17 | except KeyError:
|
| 18 | print 'You must specify a "platform"'
|
| 19 | sys.exit(2)
|
| 20 |
|
| 21 | print "Building using PLATFORM =", platform
|
| 22 |
|
| 23 | rootbuild_dir = Dir('#buildscons')
|
| 24 | build_dir = os.path.join( '#buildscons', platform )
|
| 25 | bin_dir = os.path.join( '#bin', platform )
|
| 26 | lib_dir = os.path.join( '#libs', platform )
|
| 27 | sconsign_dir_path = Dir(build_dir).abspath
|
| 28 | sconsign_path = os.path.join( sconsign_dir_path, '.sconsign.dbm' )
|
| 29 |
|
| 30 | # Ensure build directory exist (SConsignFile fail otherwise!)
|
| 31 | if not os.path.exists( sconsign_dir_path ):
|
| 32 | os.makedirs( sconsign_dir_path )
|
| 33 |
|
| 34 | # Store all dependencies signature in a database
|
| 35 | SConsignFile( sconsign_path )
|
| 36 |
|
| 37 | env = Environment( ENV = {'PATH' : os.environ['PATH']},
|
| 38 | toolpath = ['scons-tools'],
|
| 39 | tools=[] ) #, tools=['default'] )
|
| 40 |
|
| 41 | if platform == 'suncc':
|
| 42 | env.Tool( 'sunc++' )
|
| 43 | env.Tool( 'sunlink' )
|
| 44 | env.Tool( 'sunar' )
|
| 45 | env.Append( LIBS = ['pthreads'] )
|
| 46 | elif 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
|
| 54 | elif 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'
|
| 59 | elif 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'
|
| 64 | elif 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'
|
| 69 | elif 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'
|
| 74 | elif platform == 'mingw':
|
| 75 | env.Tool( 'mingw' )
|
| 76 | env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
|
| 77 | elif platform == 'linux-gcc':
|
| 78 | env.Tool( 'default' )
|
| 79 | env.Append( LIBS = ['pthread'] )
|
| 80 | else:
|
| 81 | print "UNSUPPORTED PLATFORM."
|
| 82 | env.Exit(1)
|
| 83 |
|
| 84 | env.Tool('doxygen')
|
| 85 | env.Tool('substinfile')
|
| 86 | env.Tool('targz')
|
| 87 | env.Tool('srcdist')
|
| 88 |
|
| 89 | env.Append( CPPPATH = ['#include'],
|
| 90 | LIBPATH = lib_dir )
|
| 91 | short_platform = platform
|
| 92 | if short_platform.startswith('msvc'):
|
| 93 | short_platform = short_platform[2:]
|
| 94 | env['LIB_PLATFORM'] = short_platform
|
| 95 | env['LIB_LINK_TYPE'] = 'lib' # static
|
| 96 | env['LIB_CRUNTIME'] = 'mt'
|
| 97 | env['LIB_NAME_SUFFIX'] = '${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}' # must match autolink naming convention
|
| 98 | env['JSONCPP_VERSION'] = JSONCPP_VERSION
|
| 99 | env['BUILD_DIR'] = env.Dir(build_dir)
|
| 100 | env['ROOTBUILD_DIR'] = env.Dir(rootbuild_dir)
|
| 101 | env['DIST_DIR'] = DIST_DIR
|
| 102 | class 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 )
|
| 107 | env['SRCDIST_ADD'] = SrcDistAdder( env )
|
| 108 | env['SRCDIST_TARGET'] = os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz' % env['JSONCPP_VERSION'] )
|
| 109 | env['SRCDIST_BUILDER'] = env.TarGz
|
| 110 |
|
| 111 | env_testing = env.Copy( )
|
| 112 | env_testing.Append( LIBS = ['json_${LIB_NAME_SUFFIX}'] )
|
| 113 |
|
| 114 | def 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 |
|
| 123 | def 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 |
|
| 128 | def buildLibary( env, target_sources, target_name ):
|
| 129 | static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}',
|
| 130 | source=target_sources )
|
| 131 | global lib_dir
|
| 132 | env.Install( lib_dir, static_lib )
|
| 133 | env['SRCDIST_ADD']( source=[target_sources] )
|
| 134 |
|
| 135 | Export( 'env env_testing buildJSONExample buildLibary buildJSONTests' )
|
| 136 |
|
| 137 | def buildProjectInDirectory( target_directory ):
|
| 138 | global build_dir
|
| 139 | target_build_dir = os.path.join( build_dir, target_directory )
|
| 140 | target = os.path.join( target_directory, 'sconscript' )
|
| 141 | SConscript( target, build_dir=target_build_dir, duplicate=0 )
|
| 142 | env['SRCDIST_ADD']( source=[target] )
|
| 143 |
|
| 144 |
|
| 145 | def runJSONTests_action( target, source = None, env = None ):
|
| 146 | # Add test scripts to python path
|
| 147 | jsontest_path = Dir( '#test' ).abspath
|
| 148 | sys.path.insert( 0, jsontest_path )
|
| 149 | import runjsontests
|
| 150 | return runjsontests.runAllTests( os.path.abspath(source), jsontest_path )
|
| 151 |
|
| 152 | def runJSONTests_string( target, source = None, env = None ):
|
| 153 | return 'RunJSONTests("%s")' % source
|
| 154 |
|
| 155 | ##def buildDoc( doxyfile_path ):
|
| 156 | ## doc_cmd = env.Doxygen( doxyfile_path )
|
| 157 |
|
| 158 | import SCons.Action
|
| 159 | ActionFactory = SCons.Action.ActionFactory
|
| 160 | RunJSONTests = ActionFactory(runJSONTests_action, runJSONTests_string )
|
| 161 |
|
| 162 | env.Alias( 'check' )
|
| 163 |
|
| 164 | srcdist_cmd = env['SRCDIST_ADD']( source = """
|
| 165 | AUTHORS README.txt SConstruct
|
| 166 | """.split() )
|
| 167 | env.Alias( 'src-dist', srcdist_cmd )
|
| 168 |
|
| 169 | buildProjectInDirectory( 'src/jsontestrunner' )
|
| 170 | buildProjectInDirectory( 'src/lib_json' )
|
| 171 | buildProjectInDirectory( 'doc' )
|