summaryrefslogtreecommitdiff
path: root/src/SConscript.client
blob: 8925163eae4541d24af995a095d60b54332a8ad2 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# -*- mode: python -*-

# This SConscript describes build and install rules for the Mongo C++ driver and associated exmaple
# programs.
import os

Import('env has_option installSetup use_system_version_of_library')

Import('nix linux darwin windows')

buildShared = False
if has_option("sharedclient"):
    buildShared = True

clientEnv = env.Clone()
libEnv = env.Clone()
del env
clientEnv['CPPDEFINES'].remove('MONGO_EXPOSE_MACROS')
libEnv.Append(CPPDEFINES='LIBMONGOCLIENT_BUILDING')

libEnv.Command(['mongo/base/error_codes.h', 'mongo/base/error_codes.cpp',],
               ['mongo/base/generate_error_codes.py', 'mongo/base/error_codes.err'],
               '$PYTHON $SOURCES $TARGETS')

libEnv.Command(['mongo/db/auth/action_type.h', 'mongo/db/auth/action_type.cpp'],
               ['mongo/db/auth/generate_action_types.py', 'mongo/db/auth/action_types.txt'],
               '$PYTHON $SOURCES $TARGETS')

clientSourceBasic = [
    'mongo/base/error_codes.cpp',
    'mongo/base/global_initializer.cpp',
    'mongo/base/global_initializer_registerer.cpp',
    'mongo/base/init.cpp',
    'mongo/base/initializer.cpp',
    'mongo/base/initializer_context.cpp',
    'mongo/base/initializer_dependency_graph.cpp',
    'mongo/base/make_string_vector.cpp',
    'mongo/base/parse_number.cpp',
    'mongo/base/status.cpp',
    'mongo/base/string_data.cpp',
    'mongo/bson/bson_validate.cpp',
    'mongo/bson/oid.cpp',
    'mongo/bson/util/bson_extract.cpp',
    'mongo/buildinfo.cpp',
    'mongo/client/auth_helpers.cpp',
    'mongo/client/clientAndShell.cpp',
    'mongo/client/clientOnly.cpp',
    'mongo/client/connpool.cpp',
    'mongo/client/dbclient.cpp',
    'mongo/client/dbclient_rs.cpp',
    'mongo/client/dbclientcursor.cpp',
    'mongo/client/gridfs.cpp',
    'mongo/client/init.cpp',
    'mongo/client/sasl_client_authenticate.cpp',
    'mongo/client/syncclusterconnection.cpp',
    'mongo/db/jsobj.cpp',
    'mongo/db/json.cpp',
    'mongo/db/lasterror.cpp',
    'mongo/db/dbmessage.cpp',
    'mongo/db/server_options.cpp',
    'mongo/logger/console.cpp',
    'mongo/logger/log_manager.cpp',
    'mongo/logger/log_severity.cpp',
    'mongo/logger/logger.cpp',
    'mongo/logger/logstream_builder.cpp',
    'mongo/logger/message_event_utf8_encoder.cpp',
    'mongo/logger/message_log_domain.cpp',
    'mongo/logger/ramlog.cpp',
    'mongo/logger/rotatable_file_manager.cpp',
    'mongo/logger/rotatable_file_writer.cpp',
    'mongo/pch.cpp',
    'mongo/platform/backtrace.cpp',
    'mongo/platform/posix_fadvise.cpp',
    'mongo/platform/process_id.cpp',
    'mongo/platform/random.cpp',
    'mongo/util/assert_util.cpp',
    'mongo/util/background.cpp',
    'mongo/util/base64.cpp',
    'mongo/util/concurrency/rwlockimpl.cpp',
    'mongo/util/concurrency/spin_lock.cpp',
    'mongo/util/concurrency/synchronization.cpp',
    'mongo/util/concurrency/task.cpp',
    'mongo/util/concurrency/thread_name.cpp',
    'mongo/util/concurrency/thread_pool.cpp',
    'mongo/util/concurrency/mutexdebugger.cpp',
    'mongo/util/debug_util.cpp',
    'mongo/util/stacktrace.cpp',
    'mongo/util/file.cpp',
    'mongo/util/file_allocator.cpp',
    'mongo/util/fail_point.cpp',
    'mongo/util/fail_point_registry.cpp',
    'mongo/util/fail_point_service.cpp',
    'mongo/util/hex.cpp',
    'mongo/util/histogram.cpp',
    'mongo/util/intrusive_counter.cpp',
    'mongo/util/log.cpp',
    'mongo/util/md5.cpp',
    'mongo/util/md5main.cpp',
    'mongo/util/net/httpclient.cpp',
    'mongo/util/net/listen.cpp',
    'mongo/util/net/message.cpp',
    'mongo/util/net/message_port.cpp',
    'mongo/util/net/sock.cpp',
    "mongo/util/net/socket_poll.cpp",
    'mongo/util/net/ssl_manager.cpp',
    'mongo/util/password.cpp',
    'mongo/util/paths.cpp',
    'mongo/util/processinfo.cpp',
    'mongo/util/signal_handlers.cpp',
    'mongo/util/stringutils.cpp',
    'mongo/util/text.cpp',
    'mongo/util/time_support.cpp',
    'mongo/util/timer.cpp',
    'mongo/util/trace.cpp',
    'mongo/util/util.cpp',
    'mongo/util/version.cpp',
    'third_party/murmurhash3/MurmurHash3.cpp',
    ]

clientSourceSasl = ['mongo/client/sasl_client_authenticate_impl.cpp',
                    'mongo/client/sasl_client_session.cpp']

clientSourceProcessInfo = [
    'mongo/util/processinfo_darwin.cpp',
    'mongo/util/processinfo_freebsd.cpp',
    'mongo/util/processinfo_linux2.cpp',
    'mongo/util/processinfo_none.cpp',
    'mongo/util/processinfo_sunos5.cpp',
    'mongo/util/processinfo_win32.cpp'
]

clientSourceAll = clientSourceBasic + clientSourceSasl + clientSourceProcessInfo

usingSasl = libEnv['MONGO_BUILD_SASL_CLIENT']

clientSource = list(clientSourceBasic)
if usingSasl:
    clientSource += clientSourceSasl

processInfoPlatformFile = libEnv.File( "mongo/util/processinfo_${PYSYSPLATFORM}.cpp" )
# NOTE: See comment about similar code in src/mongo/SConscript
if not os.path.exists( str( processInfoPlatformFile ) ):
    processInfoPlatformFile = libEnv.File( "mongo/util/processinfo_none.cpp" )
clientSource += [processInfoPlatformFile]

exampleSourceMap = [
        ('authTest', 'mongo/client/examples/authTest.cpp'),
        ('clientTest', 'mongo/client/examples/clientTest.cpp'),
        ('firstExample', 'mongo/client/examples/first.cpp'),
        ('httpClientTest', 'mongo/client/examples/httpClientTest.cpp'),
        ('rsExample', 'mongo/client/examples/rs.cpp'),
        ('secondExample', 'mongo/client/examples/second.cpp'),
        ('tutorial', 'mongo/client/examples/tutorial.cpp'),
        ('whereExample', 'mongo/client/examples/whereExample.cpp'),
        ('bsondemo', 'mongo/bson/bsondemo/bsondemo.cpp'),
        ]

clientHeaderDirectories = [
    "base/",
    "bson/",
    "bson/util/",
    "client/",
    "db/",
    "db/auth/",
    "db/stats/",
    "db/repl/",
    "db/ops/",
    "logger/",
    "platform/",
    "s/",
    "scripting/",
    "shell/",
    "util/",
    "util/concurrency/",
    "util/mongoutils/",
    "util/options_parser/",
    "util/net/",
    ""
    ]

clientHeaders = []
for path in clientHeaderDirectories:
    clientHeaders.extend(Glob('mongo/%s/*.h' % path))
    clientHeaders.extend(Glob('mongo/%s/*.hpp' % path))

# This relies on static and shared objects being the same, since we will link these object
# files twice: once into a .a, and another time into a .so
clientObjects = [libEnv.Object(source) for source in clientSource]

mongoClientLibs = []
mongoClientLibDeps = ['$BUILD_DIR/third_party/shim_boost']
mongoClientSysLibDeps = []

if usingSasl:
    mongoClientSysLibDeps += ["sasl2"]

mongoClientInstalls = []
mongoClientPrefixInstalls = []

staticLibEnv = libEnv.Clone()
staticLibEnv.AppendUnique(
    LIBDEPS=mongoClientLibDeps,
    SYSLIBDEPS=mongoClientSysLibDeps)

if windows:
    # On Windows, we need to have the static library target and the
    # import library target have different names, so that they aren't
    # ambiguous to scons.  Boost names the static library libxxxx.lib and
    # the import library xxxx.lib, so we shall follow their lead.
    staticLibName = 'libmongoclient'
else:
    staticLibName = 'mongoclient'

mongoClientStaticLib = staticLibEnv.StaticLibrary(
    staticLibName, clientObjects),
mongoClientInstalls.append(staticLibEnv.Install('#/', mongoClientStaticLib))

if installSetup.libraries:
    mongoClientPrefixInstalls.append(libEnv.Install("$INSTALL_DIR/lib", mongoClientStaticLib))

mongoClientSharedLib = None

if buildShared:

    # TODO: When we are ready to set a SONAME for mongoclient, set SHLIBVERSION=x.y.z in this
    # environment to enable SCons versioned shared library support, and then change the two
    # 'Install' calls in this block to 'InstallVersionedLibrary'. SHLIBVERSION and
    # InstallVersionedLibrary support is only stable in SCons > 2.3.0, so if you add support
    # here, be sure to add an EnsuredSconsVersion here as well.
    sharedLibEnv = libEnv.Clone()
    sharedLibEnv.AppendUnique(LIBS=mongoClientSysLibDeps)

    # On windows, we always want to attach the shim, since independently of whether we are
    # using the system or the vendored boost, the DLL must have complete symbols. For unix like
    # systems, attach the shim only if we are using the external libraries so that we pick up
    # what configure found for us. Otherwise, produce a dynamic object in which the boost
    # symbols are undefined, ensuring that we pass any necessary OS flags to produce such a
    # library.
    if windows or use_system_version_of_library("boost"):
        sharedLibEnv.AppendUnique(LIBDEPS=mongoClientLibDeps)
        if linux:
            sharedLibEnv.AppendUnique(SHLINKFLAGS=["-Wl,--as-needed", "-Wl,-zdefs"])
    elif darwin:
        sharedLibEnv.AppendUnique(SHLINKFLAGS=["-Wl,-undefined,dynamic_lookup"])

    # On non-windows systems, we want to match the behavior of DLLs
    # and not export all symbols from the dynamic shared library unless 
    # they have been explicitly been marked.
    if not windows:
        sharedLibEnv.AppendUnique(CCFLAGS="-fvisibility=hidden")
        sharedLibEnv.AppendUnique(SHLINKFLAGS="-fvisibility=hidden")

    mongoClientSharedLib = sharedLibEnv.SharedLibrary('mongoclient', clientObjects)

    mongoClientSharedLibInstall = sharedLibEnv.Install(
        '#/sharedclient', mongoClientSharedLib)

    if darwin:
        # Set up the copy of the client library in #/sharedclient so that things that link
        # against it record the local directory as the install_name.
        sharedLibEnv.AddPostAction(
            mongoClientSharedLibInstall,
            "install_name_tool -id @executable_path/%s %s" % (
                mongoClientSharedLibInstall[0].name,
                mongoClientSharedLibInstall[0]
            ))
    mongoClientInstalls.append(mongoClientSharedLibInstall)

    if installSetup.libraries:
        mongoClientSharedLibPrefixInstall = sharedLibEnv.Install(
            '$INSTALL_DIR/lib', mongoClientSharedLib)
        if darwin:
            sharedLibEnv.AddPostAction(
                mongoClientSharedLibPrefixInstall,
                "install_name_tool -id %s %s" % (
                    mongoClientSharedLibPrefixInstall[0],
                    mongoClientSharedLibPrefixInstall[0]
                ))
        mongoClientPrefixInstalls.append(mongoClientSharedLibPrefixInstall)

libEnv.Alias('mongoclient', mongoClientInstalls)

if installSetup.headers:
    for x in clientHeaderDirectories:
        inst = libEnv.Install("$INSTALL_DIR/include/mongo/" + x,
                              [Glob('mongo/%s*.h' % x), Glob('mongo/%s*.hpp' % x)])
        libEnv.AddPostAction(inst, Chmod('$TARGET', 0644))
        mongoClientPrefixInstalls.append(inst)

if installSetup.headers or installSetup.libraries:
    installAlias = libEnv.Alias('install-mongoclient', mongoClientPrefixInstalls)

    # Build some simple mainlines that include the dbclient.h and bson.h headers
    # with things set up to include from the installation directory.

    # Remove anything that says $BUILD_DIR from the CPPPATH, except for things in third party,
    # so we have a source for boost, etc if we aren't getting them from the system.
    limit_cpppath=[p for p in libEnv['CPPPATH']
                   if not ('$BUILD_DIR' in p and not 'third_party' in p)]

    # Create an environment where include files and libraries come from the installation directory.
    installationTestEnv = libEnv.Clone(
        CPPPATH=["$INSTALL_DIR/include"] + limit_cpppath,
        LIBPATH=["$INSTALL_DIR/lib"],
        CPPDEFINES=[],
    )

    include_dbclienth_test_file = 'mongo/client/include_dbclienth_test.cpp'
    libEnv.Depends(include_dbclienth_test_file, installAlias)
    include_dbclienth_test = installationTestEnv.Object(
        target='include_dbclienth_test',
        source=[include_dbclienth_test_file])
    libEnv.AlwaysBuild(include_dbclienth_test)
    libEnv.NoCache(include_dbclienth_test)

    include_bsonh_test_file = 'mongo/client/include_bsonh_test.cpp'
    libEnv.Depends(include_bsonh_test_file, installAlias)
    include_bsonh_test = installationTestEnv.Object(
        target='include_bsonh_test',
        source=[include_bsonh_test_file])
    libEnv.AlwaysBuild(include_bsonh_test)
    libEnv.NoCache(include_bsonh_test)

    libEnv.Alias('check-install-mongoclient', [
        include_dbclienth_test,
        include_bsonh_test,
    ])

# Compile the example files to .o so that we can link them twice: once statically, once shared.
exampleObjMap = [(target, clientEnv.Object(source)) for (target, source) in exampleSourceMap]

staticClientEnv = clientEnv.Clone()
staticClientEnv.PrependUnique(LIBDEPS=[mongoClientStaticLib])

# Build each statically linked client program
staticClientPrograms = [staticClientEnv.Program(target, obj) for (target, obj) in exampleObjMap]

# Install them to the root, and append the install targets to the list of client tests
clientTests = staticClientEnv.Install("#/", staticClientPrograms)

# Do the same for the shared library case, if we are doing that.
if buildShared:
    sharedClientEnv = clientEnv.Clone()

    # Arrange for the tests to link against the mongoclient in the #/sharedclient directory,
    # and against boost explicitly rather than picking up the symbols through mongoclient.
    sharedClientEnv.PrependUnique(
        LIBS=['mongoclient'],
        LIBPATH=["#/sharedclient"],
        LIBDEPS=mongoClientLibDeps,
    )

    # Deal with the different lookup models between regular UNIX and Darwin. For regular unix,
    # we set $ORIGIN to pull the copy we run against from the current directory
    # (#/sharedclient). On Darwin, the staged copy of the mongoclient dylib in #sharedclient
    # has @executable path set as its install_name, so we pick up the same behavior that way.
    if nix and not darwin:
        sharedClientEnv.PrependUnique(
            LINKFLAGS="-Wl,-z,origin",
            RPATH=[sharedClientEnv.Literal("\\$$ORIGIN")])

    sharedClientPrograms = [
        sharedClientEnv.Program("sharedclient/" + target, obj) for (target, obj) in exampleObjMap]
    libEnv.Depends(sharedClientPrograms, mongoClientInstalls)

    sharedClientProgramInstalls = sharedClientEnv.Install("#/sharedclient", sharedClientPrograms)
    clientTests.append(sharedClientProgramInstalls)

clientEnv.Alias('clientTests', clientTests, [])