debug flag
[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 #  - OpenSSL: http://www.slproweb.com/products/Win32OpenSSL.html
9 #       * Install non-light Win32 binary in \openssl
10 #       * Using a openssl-0.9.8k tar-ball doesn't work as the includes there
11 #         are symbolic links which get turned into 0 length files by 7Zip. 
12 #
13
14 import os
15 import re
16 import sys
17
18 DEBUG = True
19
20 TestDir='tests'
21
22 target = 'p2tp'
23 source = [ 'bin64.cpp','sha1.cpp','hashtree.cpp','datagram.cpp','bins.cpp',
24     'transfer.cpp', 'p2tp.cpp', 'sendrecv.cpp', 'ext/send_control.cpp',
25     'compat/hirestimeofday.cpp', 'compat.cpp', 'compat/util.cpp']
26
27 env = Environment()
28 if sys.platform == "win32":
29         # "MSVC works out of the box". Sure.
30         # Make sure scons finds cl.exe, etc.
31         env.Append ( ENV = { 'PATH' : os.environ['PATH'] } )
32
33         # Make sure scons finds std MSVC include files
34         if not 'INCLUDE' in os.environ:
35                 print "p2tp: Please run scons in a Visual Studio Command Prompt"
36                 sys.exit(-1)
37                 
38         include = os.environ['INCLUDE']
39         include += '..\\gtest-1.4.0\\include;'
40         include += '\\openssl\\include;' 
41         
42         env.Append ( ENV = { 'INCLUDE' : include } )
43         
44         # Other compiler flags
45         env.Append(CPPPATH=".")
46         if DEBUG:
47                 env.Append(CXXFLAGS="/Zi /Yd /MTd")
48                 env.Append(LINKFLAGS="/DEBUG")
49
50         # Add simulated pread/write
51         source += ['compat/unixio.cpp']
52  
53         # Set libs to link to
54         libs = ['ws2_32']
55         if DEBUG:
56                 libs += ['gtestd','libeay32MTd']
57         else:
58                 libs += ['gtest','libeay32']
59                 
60         # Update lib search path
61         libpath = os.environ['LIBPATH']
62         if DEBUG:
63                 libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Debug;'
64                 libpath += '\\openssl\\lib\\VC\\static;'
65         else:
66                 libpath += '\\build\\gtest-1.4.0\\msvc\\gtest\\Release;'
67                 libpath += '\\openssl\\lib;'
68         # Somehow linker can't find uuid.lib
69         libpath += 'C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Lib;'
70         
71 else:
72         # Enable the user defining external includes
73         if 'CPPPATH' in os.environ:
74             cpppath = os.environ['CPPPATH']
75         else:
76             cpppath = ""
77             print "To use external libs, set CPPPATH environment variable to list of colon-separated include dirs"
78         env.Append(CPPPATH=".:"+cpppath)
79     #env.Append(LINKFLAGS="--static")
80
81         #if DEBUG:
82         #       env.Append(CXXFLAGS="-g")
83
84         # Set libs to link to
85         libs = ['stdc++','pthread']
86         if 'LIBPATH' in os.environ:
87             libpath = os.environ['LIBPATH']
88         else:
89             libpath = ""
90             print "To use external libs, set LIBPATH environment variable to list of colon-separated lib dirs"
91
92 if DEBUG:
93         env.Append(CXXFLAGS="-DDEBUG")
94
95 env.StaticLibrary (
96     target= target,
97     source = source,
98     LIBS=libs,
99     LIBPATH=libpath )
100
101 Export("env")
102 Export("libs")
103 Export("libpath")
104 Export("DEBUG")
105 SConscript('tests/SConscript')
106 SConscript('exec/SConscript')