Skip to content

Commit

Permalink
CXX-119 Offer STATIC_LIBMONGOCLIENT to inhibit visibility macro appli…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
acmorrow committed Mar 5, 2014
1 parent 0a797c7 commit 05be083
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/SConscript.client
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ if installSetup.headers or installSetup.libraries:
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])
staticClientEnv.AppendUnique(CPPDEFINES=['STATIC_LIBMONGOCLIENT'])

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

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

# Pretend that these files are shared object suffixed so they don't conflict with the objects
# for the static library.
sharedClientEnv['OBJSUFFIX'] = sharedClientEnv['OBJSUFFIX'] + 's'

# 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
Expand All @@ -412,13 +416,14 @@ if buildShared:
RPATH=[sharedClientEnv.Literal("\\$$ORIGIN")])

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

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

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

# NOTE: There must be a mongod listening on 127.0.0.1:27999 (the traditional mongodb smoke test
# port) for the smokeClient target to run. In the server repo that is no problem, the smoke.py
Expand Down
6 changes: 6 additions & 0 deletions src/mongo/bson/bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
#error bson.h is for C++ driver consumer use only
#endif

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

#include "mongo/client/redef_macros.h"

Expand Down
6 changes: 6 additions & 0 deletions src/mongo/client/dbclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
#error dbclient.h is for C++ driver consumer use only
#endif

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

#include "mongo/client/redef_macros.h"

Expand Down

0 comments on commit 05be083

Please sign in to comment.