Uh oh!
There was an error while loading. Please reload this page.
forked from open-source-parsers/jsoncpp
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
Latest commit
248 lines (215 loc) · 9.35 KB
/
Copy pathSConstruct
File metadata and controls
248 lines (215 loc) · 9.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
"""
Notes:
- shared library support is buggy: it assumes that a static and dynamic library can be build from the same object files. This is not true on many platforms. For this reason it is only enabled on linux-gcc at the current time.
To add a platform:
- add its name in options allowed_values below
- add tool initialization for this platform. Search for "if platform == 'suncc'" as an example.
"""
importos
importos.path
importsys
JSONCPP_VERSION=open(File('#version').abspath,'rt').read().strip()
DIST_DIR='#dist'
options=Variables()
options.Add( EnumVariable('platform',
'Platform (compiler/stl) used to build the project',
'msvc71',
allowed_values='suncc vacpp mingw msvc6 msvc7 msvc71 msvc80 msvc90 linux-gcc'.split(),
ignorecase=2) )
try:
platform=ARGUMENTS['platform']
ifplatform=='linux-gcc':
CXX='g++'# not quite right, but env is not yet available.
importcommands
version=commands.getoutput('%s -dumpversion'%CXX)
platform='linux-gcc-%s'%version
print"Using platform '%s'"%platform
LD_LIBRARY_PATH=os.environ.get('LD_LIBRARY_PATH', '')
LD_LIBRARY_PATH="%s:libs/%s"%(LD_LIBRARY_PATH, platform)
os.environ['LD_LIBRARY_PATH'] =LD_LIBRARY_PATH
print"LD_LIBRARY_PATH =", LD_LIBRARY_PATH
exceptKeyError:
print'You must specify a "platform"'
sys.exit(2)
print"Building using PLATFORM =", platform
rootbuild_dir=Dir('#buildscons')
build_dir=os.path.join( '#buildscons', platform )
bin_dir=os.path.join( '#bin', platform )
lib_dir=os.path.join( '#libs', platform )
sconsign_dir_path=Dir(build_dir).abspath
sconsign_path=os.path.join( sconsign_dir_path, '.sconsign.dbm' )
# Ensure build directory exist (SConsignFile fail otherwise!)
ifnotos.path.exists( sconsign_dir_path ):
os.makedirs( sconsign_dir_path )
# Store all dependencies signature in a database
SConsignFile( sconsign_path )
defmake_environ_vars():
"""Returns a dictionnary with environment variable to use when compiling."""
# PATH is required to find the compiler
# TEMP is required for at least mingw
# LD_LIBRARY_PATH & co is required on some system for the compiler
vars= {}
fornamein ('PATH', 'TEMP', 'TMP', 'LD_LIBRARY_PATH', 'LIBRARY_PATH'):
ifnameinos.environ:
vars[name] =os.environ[name]
returnvars
env=Environment( ENV=make_environ_vars(),
toolpath= ['scons-tools'],
tools=[] ) #, tools=['default'] )
ifplatform=='suncc':
env.Tool( 'sunc++' )
env.Tool( 'sunlink' )
env.Tool( 'sunar' )
env.Append( CCFLAGS= ['-mt'] )
elifplatform=='vacpp':
env.Tool( 'default' )
env.Tool( 'aixcc' )
env['CXX'] ='xlC_r'#scons does not pick-up the correct one !
# using xlC_r ensure multi-threading is enabled:
# http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.vacpp7a.doc/compiler/ref/cuselect.htm
env.Append( CCFLAGS='-qrtti=all',
LINKFLAGS='-bh:5' ) # -bh:5 remove duplicate symbol warning
elifplatform=='msvc6':
env['MSVS_VERSION']='6.0'
fortoolin ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
env.Tool( tool )
env['CXXFLAGS']='-GR -GX /nologo /MT'
elifplatform=='msvc70':
env['MSVS_VERSION']='7.0'
fortoolin ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
env.Tool( tool )
env['CXXFLAGS']='-GR -GX /nologo /MT'
elifplatform=='msvc71':
env['MSVS_VERSION']='7.1'
fortoolin ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
env.Tool( tool )
env['CXXFLAGS']='-GR -GX /nologo /MT'
elifplatform=='msvc80':
env['MSVS_VERSION']='8.0'
fortoolin ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
env.Tool( tool )
env['CXXFLAGS']='-GR -EHsc /nologo /MT'
elifplatform=='msvc90':
env['MSVS_VERSION']='9.0'
# Scons 1.2 fails to detect the correct location of the platform SDK.
# So we propagate those from the environment. This requires that the
# user run vcvars32.bat before compiling.
if'INCLUDE'inos.environ:
env['ENV']['INCLUDE'] =os.environ['INCLUDE']
if'LIB'inos.environ:
env['ENV']['LIB'] =os.environ['LIB']
fortoolin ['msvc', 'msvs', 'mslink', 'masm', 'mslib']:
env.Tool( tool )
env['CXXFLAGS']='-GR -EHsc /nologo /MT'
elifplatform=='mingw':
env.Tool( 'mingw' )
env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
elifplatform.startswith('linux-gcc'):
env.Tool( 'default' )
env.Append( LIBS= ['pthread'], CCFLAGS=os.environ.get("CXXFLAGS", "-Wall"), LINKFLAGS=os.environ.get("LDFLAGS", "") )
env['SHARED_LIB_ENABLED'] =True
else:
print"UNSUPPORTED PLATFORM."
env.Exit(1)
env.Tool('targz')
env.Tool('srcdist')
env.Tool('globtool')
env.Append( CPPPATH= ['#include'],
LIBPATH=lib_dir )
short_platform=platform
ifshort_platform.startswith('msvc'):
short_platform=short_platform[2:]
# Notes: on Windows you need to rebuild the source for each variant
# Build script does not support that yet so we only build static libraries.
# This also fails on AIX because both dynamic and static library ends with
# extension .a.
env['SHARED_LIB_ENABLED'] =env.get('SHARED_LIB_ENABLED', False)
env['LIB_PLATFORM'] =short_platform
env['LIB_LINK_TYPE'] ='lib'# static
env['LIB_CRUNTIME'] ='mt'
env['LIB_NAME_SUFFIX'] ='${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}'# must match autolink naming convention
env['JSONCPP_VERSION'] =JSONCPP_VERSION
env['BUILD_DIR'] =env.Dir(build_dir)
env['ROOTBUILD_DIR'] =env.Dir(rootbuild_dir)
env['DIST_DIR'] =DIST_DIR
if'TarGz'inenv['BUILDERS']:
classSrcDistAdder:
def__init__( self, env ):
self.env=env
def__call__( self, *args, **kw ):
apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) +args, kw )
env['SRCDIST_BUILDER'] =env.TarGz
else: # If tarfile module is missing
classSrcDistAdder:
def__init__( self, env ):
pass
def__call__( self, *args, **kw ):
pass
env['SRCDIST_ADD'] =SrcDistAdder( env )
env['SRCDIST_TARGET'] =os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz'%env['JSONCPP_VERSION'] )
env_testing=env.Clone( )
env_testing.Append( LIBS= ['json_${LIB_NAME_SUFFIX}'] )
defbuildJSONExample( env, target_sources, target_name ):
env=env.Clone()
env.Append( CPPPATH= ['#'] )
exe=env.Program( target=target_name,
source=target_sources )
env['SRCDIST_ADD']( source=[target_sources] )
globalbin_dir
returnenv.Install( bin_dir, exe )
defbuildJSONTests( env, target_sources, target_name ):
jsontests_node=buildJSONExample( env, target_sources, target_name )
check_alias_target=env.Alias( 'check', jsontests_node, RunJSONTests( jsontests_node, jsontests_node ) )
env.AlwaysBuild( check_alias_target )
defbuildUnitTests( env, target_sources, target_name ):
jsontests_node=buildJSONExample( env, target_sources, target_name )
check_alias_target=env.Alias( 'check', jsontests_node,
RunUnitTests( jsontests_node, jsontests_node ) )
env.AlwaysBuild( check_alias_target )
defbuildLibrary( env, target_sources, target_name ):
static_lib=env.StaticLibrary( target=target_name+'_${LIB_NAME_SUFFIX}',
source=target_sources )
globallib_dir
env.Install( lib_dir, static_lib )
ifenv['SHARED_LIB_ENABLED']:
shared_lib=env.SharedLibrary( target=target_name+'_${LIB_NAME_SUFFIX}',
source=target_sources )
env.Install( lib_dir, shared_lib )
env['SRCDIST_ADD']( source=[target_sources] )
Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests buildUnitTests' )
defbuildProjectInDirectory( target_directory ):
globalbuild_dir
target_build_dir=os.path.join( build_dir, target_directory )
target=os.path.join( target_directory, 'sconscript' )
SConscript( target, build_dir=target_build_dir, duplicate=0 )
env['SRCDIST_ADD']( source=[target] )
defrunJSONTests_action( target, source=None, env=None ):
# Add test scripts to python path
jsontest_path=Dir( '#test' ).abspath
sys.path.insert( 0, jsontest_path )
data_path=os.path.join( jsontest_path, 'data' )
importrunjsontests
returnrunjsontests.runAllTests( os.path.abspath(source[0].path), data_path )
defrunJSONTests_string( target, source=None, env=None ):
return'RunJSONTests("%s")'%source[0]
importSCons.Action
ActionFactory=SCons.Action.ActionFactory
RunJSONTests=ActionFactory(runJSONTests_action, runJSONTests_string )
defrunUnitTests_action( target, source=None, env=None ):
# Add test scripts to python path
jsontest_path=Dir( '#test' ).abspath
sys.path.insert( 0, jsontest_path )
importrununittests
returnrununittests.runAllTests( os.path.abspath(source[0].path) )
defrunUnitTests_string( target, source=None, env=None ):
return'RunUnitTests("%s")'%source[0]
RunUnitTests=ActionFactory(runUnitTests_action, runUnitTests_string )
env.Alias( 'check' )
srcdist_cmd=env['SRCDIST_ADD']( source="""
AUTHORS README.md SConstruct
""".split() )
env.Alias( 'src-dist', srcdist_cmd )
buildProjectInDirectory( 'src/jsontestrunner' )
buildProjectInDirectory( 'src/lib_json' )
buildProjectInDirectory( 'src/test_lib_json' )
#print env.Dump()