summaryrefslogtreecommitdiff
path: root/distsrc/client/SConstruct
blob: 4979c9244e6096f746ead6e2b329835082cff2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# scons file for MongoDB c++ client library and examples

import os

# options 
AddOption( "--extrapath",
           dest="extrapath",
           type="string",
           nargs=1,
           action="store",
           help="comma separated list of add'l paths  (--extrapath /opt/foo/,/foo) static linking" )

AddOption( "--prefix",
           dest="prefix",
           type="string",
           nargs=1,
           action="store",
           default="/usr/local",
           help="installation root" )


env = Environment( MSVS_ARCH=None )

def addExtraLibs( s ):
    for x in s.split(","):
        if os.path.exists( x ):
            env.Append( CPPPATH=[ x + "/include" ] )
            env.Append( LIBPATH=[ x + "/lib" ] )
            env.Append( LIBPATH=[ x + "/lib64" ] )

if GetOption( "extrapath" ) is not None:
    addExtraLibs( GetOption( "extrapath" ) )

env.Append( CPPPATH=[ "mongo/" ] )

env.Append( CPPDEFINES=[ "_SCONS" , "MONGO_EXPOSE_MACROS" ] )

nix = False
linux = False

if "darwin" == os.sys.platform:
    addExtraLibs( "/opt/local/" )
    nix = True
elif "linux2" == os.sys.platform or "linux3" == os.sys.platform:
    nix = True
    linux = True

if nix:
    env.Append( CPPFLAGS=" -O3" )
    env.Append( LIBS=["pthread"] )
if linux:
    env.Append( LINKFLAGS=" -Wl,--as-needed -Wl,-zdefs " )

boostLibs = [ "thread" , "filesystem" , "system", "thread" ]
conf = Configure(env)
for lib in boostLibs:
    if not conf.CheckLib("boost_%s-mt" % lib):
        conf.CheckLib("boost_%s" % lib)

dirs = [ "" , "bson/" , "bson/util/" , 
         "client/"  , "s/" , "shell/" , 
         "db/" , 
         "scripting/" , 
         "util/" , "util/concurrency/" , "util/mongoutils/" , "util/net/" ]

allClientFiles = []
for x in dirs:
    allClientFiles += Glob( "mongo/" + x + "*.cpp" )
allClientFiles += Glob( "mongo/util/*.c" )

libs = []
libs += env.SharedLibrary( "mongoclient" , allClientFiles )
sharedClientLibName = str(libs[-1])
libs += env.Library( "mongoclient" , allClientFiles )

# install

prefix = GetOption( "prefix" )

for x in libs:
    env.Install( prefix + "/lib/" , str(x) )

for x in dirs:
    x = "mongo/" + x
    env.Install( prefix + "/include/" + x , Glob( x + "*.h" ) )

env.Alias( "install" , prefix )


# example setup

clientTests = []
clientEnv = env.Clone();
clientEnv.Prepend( LIBS=["libmongoclient.a", sharedClientLibName])
clientEnv.Prepend( LIBPATH=["."] )

# examples

clientTests += [ clientEnv.Program( "firstExample" , [ "client/examples/first.cpp" ] ) ]
clientTests += [ clientEnv.Program( "secondExample" , [ "client/examples/second.cpp" ] ) ]
clientTests += [ clientEnv.Program( "whereExample" , [ "client/examples/whereExample.cpp" ] ) ]
clientTests += [ clientEnv.Program( "authTest" , [ "client/examples/authTest.cpp" ] ) ]
clientTests += [ clientEnv.Program( "httpClientTest" , [ "client/examples/httpClientTest.cpp" ] ) ]
clientTests += [ clientEnv.Program( "clientTest" , [ "client/examples/clientTest.cpp" ] ) ]
clientEnv.Alias("clientTests", clientTests, [])