- Result of svn merge -x --ignore-eol-style -r 424:458 https://ttuki.vtt.fi/svn/p2p...
[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', 'transfer.cpp', 'compat/hirestimeofday.cpp', 'compat/util.cpp']
30
31 env = Environment()
32 if sys.platform == "win32":
33         # "MSVC works out of the box". Sure.
34         # Make sure scons finds cl.exe, etc.
35         env.Append ( ENV = { 'PATH' : os.environ['PATH'] } )
36
37         # Make sure scons finds std MSVC include files
38         if not 'INCLUDE' in os.environ:
39                 print "p2tp: Please run scons in a Visual Studio Command Prompt"
40                 sys.exit(-1)
41                 
42         include = os.environ['INCLUDE']
43         include += '..\\gtest-1.4.0\\include;'
44         include += '..\\glog-0.3.0\\src\\windows;' # Funky
45         include += '\\openssl\\include;' 
46         
47         env.Append ( ENV = { 'INCLUDE' : include } )
48         
49         # Other compiler flags
50         env.Append(CPPPATH=".")
51         if DEBUG:
52                 env.Append(CXXFLAGS="/Zi /Yd /MTd")
53                 env.Append(LINKFLAGS="/DEBUG")
54
55         # Add simulated pread/write
56         source += ['compat/unixio.cpp']
57  
58         # Set libs to link to
59         libs = ['libglog','ws2_32']
60         if DEBUG:
61                 libs += ['gtestd','libeay32MTd']
62         else:
63                 libs += ['gtest','libeay32']
64                 
65         # Update lib search path
66         libpath = os.environ['LIBPATH']
67         if DEBUG:
68                 libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Debug;'
69                 libpath += '\\build\\glog-0.3.0\\vsprojects\\libglog\\Debug;'
70                 libpath += '\\openssl\\lib\\VC\\static;'
71         else:
72                 libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Release;'
73                 libpath += '\\build\\glog-0.3.0\\vsprojects\\libglog\\Release;'
74                 libpath += '\\openssl\\lib;'
75         # Somehow linker can't find uuid.lib
76         libpath += 'C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Lib;'
77         
78 else:
79         # Enable the user defining external includes
80         if 'CPPPATH' in os.environ:
81             cpppath = os.environ['CPPPATH']
82         else:
83             cpppath = ""
84             print "To use external libs, set CPPPATH environment variable to list of colon-separated include dirs"
85         env.Append(CPPPATH=".:"+cpppath)
86         env.Append(LINKFLAGS="--static")
87
88         #if DEBUG:
89         #       env.Append(CXXFLAGS="-g")
90
91         # Set libs to link to
92         libs = ['stdc++','gtest','glog','pthread','crypto']
93         if 'LIBPATH' in os.environ:
94             libpath = os.environ['LIBPATH']
95         else:
96             libpath = ""
97             print "To use external libs, set LIBPATH environment variable to list of colon-separated lib dirs"
98
99 env.StaticLibrary (
100     target= target,
101     source = source,
102     LIBS=libs,
103     LIBPATH=libpath )
104
105 Export("env")
106 Export("libs")
107 Export("libpath")
108 Export("DEBUG")
109 SConscript('tests/SConscript')