diff --git a/SConstruct b/SConstruct index 7045798332..f8192198e6 100644 --- a/SConstruct +++ b/SConstruct @@ -7,24 +7,115 @@ #env = Environment(PREFIX = GetOption('prefix')) -env = Environment() # Initialize the environment +import os, sys +env = Environment(ENV = os.environ) + +## Boost +## +## Note: You need to either set BOOSTROOT to the root of a stock Boost distribution +## or set BOOST_INCLUDES and BOOST_LIBS if Boost comes with your OS distro e.g. and +## needs BOOST_INCLUDES=/usr/include/boost and BOOST_LIBS=/usr/lib like Ubuntu. +## +if os.environ.has_key('BOOSTROOT'): + env['BOOST_INCLUDES'] = os.environ['BOOSTROOT'] + env['BOOST_LIBS'] = os.path.join(os.environ['BOOSTROOT'], 'stage', 'lib') +elif os.environ.has_key('BOOST_INCLUDES') and os.environ.has_key('BOOST_LIBS'): + env['BOOST_INCLUDES'] = os.environ['BOOST_INCLUDES'] + env['BOOST_LIBS'] = os.environ['BOOST_LIBS'] +else: + raise SCons.Errors.UserError, "Neither BOOSTROOT, nor BOOST_INCLUDES + BOOST_LIBS was set!" + +env.Append(CPPPATH = [env['BOOST_INCLUDES']]) +env.Append(LIBPATH = [env['BOOST_LIBS']]) + +boost_linkshared = False + +def boostlibs(libnames): + if env['PLATFORM'].startswith('win'): + # Win/VC++ supports autolinking. nothing to do. + # http://www.boost.org/doc/libs/1_49_0/more/getting_started/windows.html#auto-linking + return [] + else: + libs = [] + prefix = 'SHLIBPREFIX' if boost_linkshared else 'LIBPREFIX' + suffix = 'SHLIBSUFFIX' if boost_linkshared else 'LIBSUFFIX' + for name in libnames: + lib = File(os.path.join(env['BOOST_LIBS'], '%sboost_%s%s' % (prefix, name, suffix))) + libs.append(lib) + return libs + + +if env['PLATFORM'].startswith('win'): + env.Append(CPPDEFINES = ['WIN32', 'NDEBUG', '_CONSOLE', '_WEBSOCKETPP_CPP11_FRIEND_']) + arch_flags = '/arch:SSE2' + opt_flags = '/Ox /Oi /fp:fast' + warn_flags = '/W3 /wd4996 /wd4995 /wd4355' + env['CCFLAGS'] = '%s /EHsc /GR /GS- /MD /nologo %s %s' % (warn_flags, arch_flags, opt_flags) + env['LINKFLAGS'] = '/INCREMENTAL:NO /MANIFEST /NOLOGO /OPT:REF /OPT:ICF /MACHINE:X86' + env.VariantDir("release/", "src/"); -lib_sources = ["base64/base64.cpp","md5/md5.c","messages/data.cpp","network_utilities.cpp","processors/hybi_header.cpp","sha1/sha1.cpp","uri.cpp"] -lib_path = ['/usr/lib','/usr/local/lib','#/release'] +if env['PLATFORM'].startswith('win'): + lib_path = env['BOOST_LIBS'] +else: + lib_path = ['/usr/lib', + '/usr/local/lib', + env['BOOST_LIBS'], + '#/release'] -static_lib=env.StaticLibrary(target = 'release/websocketpp', source = lib_sources, srcdir="release") -shared_lib=env.SharedLibrary(target = 'release/websocketpp', source = lib_sources, srcdir="release",LIBS=['boost_regex'],LIBPATH=lib_path) - -# Echo Server -env.VariantDir("#/release/echo_server","examples/echo_server") -env.Program(target="#/release/echo_server/echo_server",srcdir="#/release/echo_server/",source=["echo_server.cpp"],LIBS=[shared_lib,'boost_system','boost_date_time','boost_regex','boost_thread','pthread'],LIBPATH=lib_path) - -lib_rt = '' +platform_libs = [] if env['PLATFORM'] == 'posix': - lib_rt = 'rt' + platform_libs = ['pthread', 'rt'] +elif env['PLATFORM'].startswith('win'): + # Win/VC++ supports autolinking. nothing to do. + pass -# Echo Server -env.VariantDir("#/release/wsperf","examples/wsperf") -env.Program(target="#/release/wsperf/wsperf",srcdir="#/release/wsperf/",source=["wsperf.cpp","request.cpp","case.cpp","generic.cpp"],LIBS=[shared_lib,'boost_system','boost_date_time','boost_regex','boost_thread','pthread',lib_rt,'boost_random','boost_chrono','boost_program_options'],LIBPATH=lib_path) \ No newline at end of file +#### END OF GLOBAL CONF ######################################################## + +## WebSocket++ library +## +lib_sources = ["base64/base64.cpp", + "md5/md5.c", + "messages/data.cpp", + "network_utilities.cpp", + "processors/hybi_header.cpp", + "sha1/sha1.cpp", + "uri.cpp"] + +static_lib = env.StaticLibrary(target = 'release/websocketpp', + source = lib_sources, + srcdir = "release") +#shared_lib=env.SharedLibrary(target = 'release/websocketpp', source = lib_sources, srcdir="release",LIBS=['boost_regex'],LIBPATH=lib_path) + +wslib = static_lib + +## Echo Server +## +env.VariantDir("#/release/echo_server", "examples/echo_server") +env.Program(target = "#/release/echo_server/echo_server", + srcdir = "#/release/echo_server/", + source = ["echo_server.cpp"], + LIBS = [wslib, platform_libs] + boostlibs(['system', + 'date_time', + 'regex', + 'thread']), + LIBPATH = lib_path) + +## wsperf +## +env.VariantDir("#/release/wsperf", "examples/wsperf") +env.Program(target = "#/release/wsperf/wsperf", + srcdir = "#/release/wsperf/", + source = ["wsperf.cpp", + "request.cpp", + "case.cpp", + "generic.cpp"], + LIBS = [wslib, platform_libs] + boostlibs(['system', + 'date_time', + 'regex', + 'thread', + 'random', + 'chrono', + 'program_options']), + LIBPATH = lib_path)