new send control (barely works)
[swift-upb.git] / SConstruct
1 # Written by Victor Grishchenko, Arno Bakker 
2 # see LICENSE.txt for license information
3 #
4 # Requirements:
5 #  - scons: Cross-platform build system    http://www.scons.org/
6 #  - googletest: Google C++ Test Framework http://code.google.com/p/googletest/
7 #       * Install in ..\gtest-1.4.0
8 #  - google-glog: Google Logging Library for C++  http://code.google.com/p/google-glog/
9 #       * Install in ..\glog-0.3.0 
10 #       * I get ..\glog-0.3.0\src\windows\glog/log_severity.h(51) : error C2059: syntax error :
11 #         'constant' while running scons. Apparently the ERROR constant is already defined somewhere.
12 #         #undef ERROR before the def allows include.
13 #
14 #  - OpenSSL: http://www.slproweb.com/products/Win32OpenSSL.html
15 #       * Install non-light Win32 binary in \openssl
16 #       * Using a openssl-0.9.8k tar-ball doesn't work as the includes there
17 #         are symbolic links which get turned into 0 length files by 7Zip. 
18 #
19
20 import os
21 import re
22 import sys
23
24 DEBUG = True
25
26 TestDir='tests'
27
28 target = 'p2tp'
29 source = [ 'bin64.cpp','hashtree.cpp','datagram.cpp','bins.cpp',
30     'transfer.cpp', 'p2tp.cpp', 'sendrecv.cpp', 'ext/send_control.cpp',
31     'compat/hirestimeofday.cpp', 'compat/util.cpp']
32
33 env = Environment()
34 if sys.platform == "win32":
35         # "MSVC works out of the box". Sure.
36         # Make sure scons finds cl.exe, etc.
37         env.Append ( ENV = { 'PATH' : os.environ['PATH'] } )
38
39         # Make sure scons finds std MSVC include files
40         if not 'INCLUDE' in os.environ:
41                 print "p2tp: Please run scons in a Visual Studio Command Prompt"
42                 sys.exit(-1)
43                 
44         include = os.environ['INCLUDE']
45         include += '..\\gtest-1.4.0\\include;'
46         include += '..\\glog-0.3.0\\src\\windows;' # Funky
47         include += '\\openssl\\include;' 
48         
49         env.Append ( ENV = { 'INCLUDE' : include } )
50         
51         # Other compiler flags
52         env.Append(CPPPATH=".")
53         if DEBUG:
54                 env.Append(CXXFLAGS="/Zi /Yd /MTd")
55                 env.Append(LINKFLAGS="/DEBUG")
56
57         # Add simulated pread/write
58         source += ['compat/unixio.cpp']
59  
60         # Set libs to link to
61         libs = ['libglog','ws2_32']
62         if DEBUG:
63                 libs += ['gtestd','libeay32MTd']
64         else:
65                 libs += ['gtest','libeay32']
66                 
67         # Update lib search path
68         libpath = os.environ['LIBPATH']
69         if DEBUG:
70                 libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Debug;'
71                 libpath += '\\build\\glog-0.3.0\\vsprojects\\libglog\\Debug;'
72                 libpath += '\\openssl\\lib\\VC\\static;'
73         else:
74                 libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Release;'
75                 libpath += '\\build\\glog-0.3.0\\vsprojects\\libglog\\Release;'
76                 libpath += '\\openssl\\lib;'
77         # Somehow linker can't find uuid.lib
78         libpath += 'C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Lib;'
79         
80 else:
81         # Enable the user defining external includes
82         if 'CPPPATH' in os.environ:
83             cpppath = os.environ['CPPPATH']
84         else:
85             cpppath = ""
86             print "To use external libs, set CPPPATH environment variable to list of colon-separated include dirs"
87         env.Append(CPPPATH=".:"+cpppath)
88     #env.Append(LINKFLAGS="--static")
89
90         #if DEBUG:
91         #       env.Append(CXXFLAGS="-g")
92
93         # Set libs to link to
94         libs = ['stdc++','gtest','glog','pthread','crypto']
95         if 'LIBPATH' in os.environ:
96             libpath = os.environ['LIBPATH']
97         else:
98             libpath = ""
99             print "To use external libs, set LIBPATH environment variable to list of colon-separated lib dirs"
100
101 env.StaticLibrary (
102     target= target,
103     source = source,
104     LIBS=libs,
105     LIBPATH=libpath )
106
107 Export("env")
108 Export("libs")
109 Export("libpath")
110 Export("DEBUG")
111 SConscript('tests/SConscript')