1 import os, sys, commands
2 env = Environment(ENV = os.environ)
4 # figure out a better way to configure this
5 if os.environ.has_key('CXX'):
6 env['CXX'] = os.environ['CXX']
8 if os.environ.has_key('DEBUG'):
9 env['DEBUG'] = os.environ['DEBUG']
11 if os.environ.has_key('CXXFLAGS'):
12 #env['CXXFLAGS'] = os.environ['CXXFLAGS']
13 env.Append(CXXFLAGS = os.environ['CXXFLAGS'])
15 if os.environ.has_key('LINKFLAGS'):
16 #env['LDFLAGS'] = os.environ['LDFLAGS']
17 env.Append(LINKFLAGS = os.environ['LINKFLAGS'])
21 ## Note: You need to either set BOOSTROOT to the root of a stock Boost distribution
22 ## or set BOOST_INCLUDES and BOOST_LIBS if Boost comes with your OS distro e.g. and
23 ## needs BOOST_INCLUDES=/usr/include/boost and BOOST_LIBS=/usr/lib like Ubuntu.
25 if os.environ.has_key('BOOSTROOT'):
26 os.environ['BOOST_ROOT'] = os.environ['BOOSTROOT']
28 if os.environ.has_key('BOOST_ROOT'):
29 env['BOOST_INCLUDES'] = os.environ['BOOST_ROOT']
30 env['BOOST_LIBS'] = os.path.join(os.environ['BOOST_ROOT'], 'stage', 'lib')
31 elif os.environ.has_key('BOOST_INCLUDES') and os.environ.has_key('BOOST_LIBS'):
32 env['BOOST_INCLUDES'] = os.environ['BOOST_INCLUDES']
33 env['BOOST_LIBS'] = os.environ['BOOST_LIBS']
35 raise SCons.Errors.UserError, "Neither BOOST_ROOT, nor BOOST_INCLUDES + BOOST_LIBS was set!"
38 if os.environ.has_key('OPENSSL_PATH'):
39 env.Append(CPPPATH = os.path.join(os.environ['OPENSSL_PATH'], 'include'))
40 env.Append(LIBPATH = os.environ['OPENSSL_PATH'])
42 if os.environ.has_key('WSPP_ENABLE_CPP11'):
43 env['WSPP_ENABLE_CPP11'] = True
45 env['WSPP_ENABLE_CPP11'] = False
47 boost_linkshared = False
49 def boostlibs(libnames,localenv):
50 if localenv['PLATFORM'].startswith('win'):
51 # Win/VC++ supports autolinking. nothing to do.
52 # http://www.boost.org/doc/libs/1_49_0/more/getting_started/windows.html#auto-linking
56 prefix = localenv['SHLIBPREFIX'] if boost_linkshared else localenv['LIBPREFIX']
57 suffix = localenv['SHLIBSUFFIX'] if boost_linkshared else localenv['LIBSUFFIX']
59 lib = File(os.path.join(localenv['BOOST_LIBS'], '%sboost_%s%s' % (prefix, name, suffix)))
63 if env['PLATFORM'].startswith('win'):
64 env.Append(CPPDEFINES = ['WIN32',
66 'WIN32_LEAN_AND_MEAN',
67 '_WIN32_WINNT=0x0600',
69 'BOOST_TEST_DYN_LINK',
71 '_WEBSOCKETPP_CPP11_MEMORY_',
72 '_WEBSOCKETPP_CPP11_FUNCTIONAL_'])
73 arch_flags = '/arch:SSE2'
74 opt_flags = '/Ox /Oi /fp:fast'
75 warn_flags = '/W3 /wd4996 /wd4995 /wd4355'
76 env['CCFLAGS'] = '%s /EHsc /GR /GS- /MD /nologo %s %s' % (warn_flags, arch_flags, opt_flags)
77 env['LINKFLAGS'] = '/INCREMENTAL:NO /MANIFEST /NOLOGO /OPT:REF /OPT:ICF /MACHINE:X86'
78 elif env['PLATFORM'] == 'posix':
79 if env.has_key('DEBUG'):
80 env.Append(CCFLAGS = ['-g', '-O0'])
82 env.Append(CPPDEFINES = ['NDEBUG'])
83 env.Append(CCFLAGS = ['-O1', '-fomit-frame-pointer'])
84 env.Append(CCFLAGS = ['-Wall'])
85 #env['LINKFLAGS'] = ''
86 elif env['PLATFORM'] == 'darwin':
87 if not os.environ.has_key('CXX'):
88 env['CXX'] = "clang++"
89 if env.has_key('DEBUG'):
90 env.Append(CCFLAGS = ['-g', '-O0'])
92 env.Append(CPPDEFINES = ['NDEBUG'])
93 env.Append(CCFLAGS = ['-O1', '-fomit-frame-pointer'])
94 env.Append(CCFLAGS = ['-Wall'])
95 #env['LINKFLAGS'] = ''
97 if env['PLATFORM'].startswith('win'):
98 #env['LIBPATH'] = env['BOOST_LIBS']
101 env.Append(LIBPATH = ['/usr/lib', '/usr/local/lib'])
103 # Compiler specific warning flags
104 if env['CXX'].startswith('g++'):
105 #env.Append(CCFLAGS = ['-Wconversion'])
106 env.Append(CCFLAGS = ['-Wcast-align'])
107 env.Append(CCFLAGS = ['-Wshadow'])
108 env.Append(CCFLAGS = ['-Wunused-parameter'])
109 elif env['CXX'].startswith('clang++'):
110 #env.Append(CCFLAGS = ['-Wcast-align'])
111 #env.Append(CCFLAGS = ['-Wglobal-constructors'])
112 #env.Append(CCFLAGS = ['-Wconversion'])
113 env.Append(CCFLAGS = ['-Wno-padded'])
114 env.Append(CCFLAGS = ['-Wshadow'])
115 env.Append(CCFLAGS = ['-Wunused-parameter'])
117 env.Append(CCFLAGS = ['-Wsometimes-uninitialized'])
118 env.Append(CCFLAGS = ['-Wuninitialized'])
120 #env.Append(CCFLAGS = ['-Weverything'])
121 #env.Append(CCFLAGS = ['-Wno-documentation'])
122 #env.Append(CCFLAGS = ['-Wno-weak-vtables'])
123 #env.Append(CCFLAGS = ['-Wno-global-constructors'])
124 #env.Append(CCFLAGS = ['-Wno-sign-conversion'])
125 #env.Append(CCFLAGS = ['-Wno-exit-time-destructors'])
139 if env['PLATFORM'] == 'posix':
140 platform_libs = ['pthread', 'rt']
141 tls_libs = ['ssl', 'crypto']
143 elif env['PLATFORM'] == 'darwin':
144 tls_libs = ['ssl', 'crypto']
146 elif env['PLATFORM'].startswith('win'):
147 # Win/VC++ supports autolinking. nothing to do.
150 ## Append WebSocket++ path
151 env.Append(CPPPATH = ['#'])
153 ##### Set up C++11 environment
154 polyfill_libs = [] # boost libraries used as drop in replacements for incomplete
155 # C++11 STL implementations
156 env_cpp11 = env.Clone ()
158 if env_cpp11['CXX'].startswith('g++'):
159 # TODO: check g++ version
160 GCC_VERSION = commands.getoutput(env_cpp11['CXX'] + ' -dumpversion')
162 if GCC_VERSION > "4.4.0":
163 print "C++11 build environment partially enabled"
164 env_cpp11.Append(WSPP_CPP11_ENABLED = "true",CXXFLAGS = ['-std=c++0x'],TOOLSET = ['g++'],CPPDEFINES = ['_WEBSOCKETPP_CPP11_STL_'])
166 print "C++11 build environment is not supported on this version of G++"
167 elif env_cpp11['CXX'].startswith('clang++'):
168 print "C++11 build environment enabled"
169 env.Append(CXXFLANGS = ['-stdlib=libc++'],LINKFLAGS=['-stdlib=libc++'])
170 env_cpp11.Append(WSPP_CPP11_ENABLED = "true",CXXFLAGS = ['-std=c++0x','-stdlib=libc++'],LINKFLAGS = ['-stdlib=libc++'],TOOLSET = ['clang++'],CPPDEFINES = ['_WEBSOCKETPP_CPP11_STL_'])
172 # look for optional second boostroot compiled with clang's libc++ STL library
173 # this prevents warnings/errors when linking code built with two different
174 # incompatible STL libraries.
175 if os.environ.has_key('BOOST_ROOT_CPP11'):
176 env_cpp11['BOOST_INCLUDES'] = os.environ['BOOST_ROOT_CPP11']
177 env_cpp11['BOOST_LIBS'] = os.path.join(os.environ['BOOST_ROOT_CPP11'], 'stage', 'lib')
178 elif os.environ.has_key('BOOST_INCLUDES_CPP11') and os.environ.has_key('BOOST_LIBS_CPP11'):
179 env_cpp11['BOOST_INCLUDES'] = os.environ['BOOST_INCLUDES_CPP11']
180 env_cpp11['BOOST_LIBS'] = os.environ['BOOST_LIBS_CPP11']
182 print "C++11 build environment disabled"
184 # if the build system is known to allow the isystem modifier for library include
185 # values then use it for the boost libraries. Otherwise just add them to the
186 # regular CPPPATH values.
187 if env['CXX'].startswith('g++') or env['CXX'].startswith('clang'):
188 env.Append(CPPFLAGS = '-isystem ' + env['BOOST_INCLUDES'])
190 env.Append(CPPPATH = [env['BOOST_INCLUDES']])
191 env.Append(LIBPATH = [env['BOOST_LIBS']])
193 # if the build system is known to allow the isystem modifier for library include
194 # values then use it for the boost libraries. Otherwise just add them to the
195 # regular CPPPATH values.
196 if env_cpp11['CXX'].startswith('g++') or env_cpp11['CXX'].startswith('clang'):
197 env_cpp11.Append(CPPFLAGS = '-isystem ' + env_cpp11['BOOST_INCLUDES'])
199 env_cpp11.Append(CPPPATH = [env_cpp11['BOOST_INCLUDES']])
200 env_cpp11.Append(LIBPATH = [env_cpp11['BOOST_LIBS']])
202 releasedir = 'build/release/'
203 debugdir = 'build/debug/'
204 testdir = 'build/test/'
205 builddir = releasedir
209 Export('platform_libs')
212 Export('polyfill_libs')
218 if not env['PLATFORM'].startswith('win'):
219 # Unit tests, add test folders with SConscript files to to_test list.
220 to_test = ['utility','http','logger','random','processors','message_buffer','extension','transport/iostream','transport/asio','roles','endpoint','connection','transport'] #,'http','processors','connection'
223 new_tests = SConscript('#/test/'+t+'/SConscript',variant_dir = testdir + t, duplicate = 0)
225 new_alias = Alias('test', [a], a.abspath)
226 AlwaysBuild(new_alias)
228 # Main test application
229 #main = SConscript('#/examples/dev/SConscript',variant_dir = builddir + 'dev',duplicate = 0)
232 echo_server = SConscript('#/examples/echo_server/SConscript',variant_dir = builddir + 'echo_server',duplicate = 0)
235 echo_client = SConscript('#/examples/echo_client/SConscript',variant_dir = builddir + 'echo_client',duplicate = 0)
239 echo_server_tls = SConscript('#/examples/echo_server_tls/SConscript',variant_dir = builddir + 'echo_server_tls',duplicate = 0)
240 echo_server_both = SConscript('#/examples/echo_server_both/SConscript',variant_dir = builddir + 'echo_server_both',duplicate = 0)
243 broadcast_server = SConscript('#/examples/broadcast_server/SConscript',variant_dir = builddir + 'broadcast_server',duplicate = 0)
246 testee_server = SConscript('#/examples/testee_server/SConscript',variant_dir = builddir + 'testee_server',duplicate = 0)
249 testee_client = SConscript('#/examples/testee_client/SConscript',variant_dir = builddir + 'testee_client',duplicate = 0)
252 scratch_client = SConscript('#/examples/scratch_client/SConscript',variant_dir = builddir + 'scratch_client',duplicate = 0)
255 scratch_server = SConscript('#/examples/scratch_server/SConscript',variant_dir = builddir + 'scratch_server',duplicate = 0)
259 debug_client = SConscript('#/examples/debug_client/SConscript',variant_dir = builddir + 'debug_client',duplicate = 0)
262 debug_server = SConscript('#/examples/debug_server/SConscript',variant_dir = builddir + 'debug_server',duplicate = 0)
265 subprotocol_server = SConscript('#/examples/subprotocol_server/SConscript',variant_dir = builddir + 'subprotocol_server',duplicate = 0)
268 telemetry_server = SConscript('#/examples/telemetry_server/SConscript',variant_dir = builddir + 'telemetry_server',duplicate = 0)
270 # external_io_service
271 external_io_service = SConscript('#/examples/external_io_service/SConscript',variant_dir = builddir + 'external_io_service',duplicate = 0)
273 if not env['PLATFORM'].startswith('win'):
275 iostream_server = SConscript('#/examples/iostream_server/SConscript',variant_dir = builddir + 'iostream_server',duplicate = 0)
278 telemetry_client = SConscript('#/examples/telemetry_client/SConscript',variant_dir = builddir + 'telemetry_client',duplicate = 0)
281 print_server = SConscript('#/examples/print_server/SConscript',variant_dir = builddir + 'print_server',duplicate = 0)