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