Skip to content

Commit 05be083

Browse files
committed
CXX-119 Offer STATIC_LIBMONGOCLIENT to inhibit visibility macro application
1 parent 0a797c7 commit 05be083

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/SConscript.client

+11-6
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ if installSetup.headers or installSetup.libraries:
378378
include_bsonh_test,
379379
])
380380

381-
# Compile the example files to .o so that we can link them twice: once statically, once shared.
382-
exampleObjMap = [(target, clientEnv.Object(source)) for (target, source) in exampleSourceMap]
383-
384381
staticClientEnv = clientEnv.Clone()
385382
staticClientEnv.PrependUnique(LIBDEPS=[mongoClientStaticLib])
383+
staticClientEnv.AppendUnique(CPPDEFINES=['STATIC_LIBMONGOCLIENT'])
386384

387385
# Build each statically linked client program
388-
staticClientPrograms = [staticClientEnv.Program(target, obj) for (target, obj) in exampleObjMap]
386+
staticClientPrograms = [
387+
staticClientEnv.Program(target, source) for (target, source) in exampleSourceMap
388+
]
389389

390390
# Install them to the root, and append the install targets to the list of client tests
391391
clientTests = staticClientEnv.Install("#/", staticClientPrograms)
@@ -402,6 +402,10 @@ if buildShared:
402402
LIBDEPS=mongoClientLibDeps,
403403
)
404404

405+
# Pretend that these files are shared object suffixed so they don't conflict with the objects
406+
# for the static library.
407+
sharedClientEnv['OBJSUFFIX'] = sharedClientEnv['OBJSUFFIX'] + 's'
408+
405409
# Deal with the different lookup models between regular UNIX and Darwin. For regular unix,
406410
# we set $ORIGIN to pull the copy we run against from the current directory
407411
# (#/sharedclient). On Darwin, the staged copy of the mongoclient dylib in #sharedclient
@@ -412,13 +416,14 @@ if buildShared:
412416
RPATH=[sharedClientEnv.Literal("\\$$ORIGIN")])
413417

414418
sharedClientPrograms = [
415-
sharedClientEnv.Program("sharedclient/" + target, obj) for (target, obj) in exampleObjMap]
419+
sharedClientEnv.Program(
420+
"sharedclient/" + target, source) for (target, source) in exampleSourceMap]
416421
libEnv.Depends(sharedClientPrograms, mongoClientInstalls)
417422

418423
sharedClientProgramInstalls = sharedClientEnv.Install("#/sharedclient", sharedClientPrograms)
419424
clientTests.extend(sharedClientProgramInstalls)
420425

421-
clientEnv.Alias('clientTests', clientTests, [])
426+
clientEnv.Alias('clientTests', clientTests)
422427

423428
# NOTE: There must be a mongod listening on 127.0.0.1:27999 (the traditional mongodb smoke test
424429
# port) for the smokeClient target to run. In the server repo that is no problem, the smoke.py

src/mongo/bson/bson.h

+6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@
3838
#error bson.h is for C++ driver consumer use only
3939
#endif
4040

41+
// Consumers of the MongoDB C++ client library must define STATIC_LIBMONGOCLIENT when including
42+
// this header if they intend to link against the static version of the library. This is best
43+
// handled by adding STATIC_LIBMONGOCLIENT to the list of definitions passed on each compile
44+
// invocation.
45+
#ifndef STATIC_LIBMONGOCLIENT
4146
#define LIBMONGOCLIENT_CONSUMER
47+
#endif
4248

4349
#include "mongo/client/redef_macros.h"
4450

src/mongo/client/dbclient.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
#error dbclient.h is for C++ driver consumer use only
2626
#endif
2727

28+
// Consumers of the MongoDB C++ client library must define STATIC_LIBMONGOCLIENT when including
29+
// this header if they intend to link against the static version of the library. This is best
30+
// handled by adding STATIC_LIBMONGOCLIENT to the list of definitions passed on each compile
31+
// invocation.
32+
#ifndef STATIC_LIBMONGOCLIENT
2833
#define LIBMONGOCLIENT_CONSUMER
34+
#endif
2935

3036
#include "mongo/client/redef_macros.h"
3137

0 commit comments

Comments
 (0)