Skip to content

Commit 3c2a0ef

Browse files
committed
CDRIVER-1160: configure flag for MONGOC_NO_AUTOMATIC_GLOBALS
1 parent 3c1e2b9 commit 3c2a0ef

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ NOTE: OpenSSL is required for authenticating to MongoDB 3.0 and later."
1010
option(ENABLE_SASL "Use Cyrus SASL library for Kerberos." ON)
1111
option(ENABLE_TESTS "Build MongoDB C Driver tests." ON)
1212
option(ENABLE_EXAMPLES "Build MongoDB C Driver examples." ON)
13+
option(ENABLE_AUTOMATIC_INIT_AND_CLEANUP "Enable automatic init and cleanup (GCC only)" ON)
1314

1415
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
1516

@@ -35,6 +36,12 @@ else ()
3536
set (MONGOC_ENABLE_SASL 0)
3637
endif ()
3738

39+
if (ENABLE_AUTOMATIC_INIT_AND_CLEANUP)
40+
set (MONGOC_NO_AUTOMATIC_GLOBALS 0)
41+
else ()
42+
set (MONGOC_NO_AUTOMATIC_GLOBALS 1)
43+
endif ()
44+
3845
set (SOURCE_DIR "${PROJECT_SOURCE_DIR}/")
3946

4047
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
AS_IF([test "$enable_automatic_init_and_cleanup" != "no"], [
2+
AC_SUBST(MONGOC_NO_AUTOMATIC_GLOBALS, 0)
3+
], [
4+
AC_SUBST(MONGOC_NO_AUTOMATIC_GLOBALS, 1)
5+
])
6+

build/autotools/PrintBuildConfiguration.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Build configuration:
3030
Compile with debug symbols (slow) : ${enable_debug_symbols}
3131
Enable GCC build optimization : ${enable_optimizations}
3232
Enable automatic binary hardening : ${enable_hardening}
33+
Enable automatic init and cleanup : ${enable_automatic_init_and_cleanup}
3334
Code coverage support : ${enable_coverage}
3435
Cross Compiling : ${enable_crosscompile}
3536
Fast counters : ${enable_rdtscp}

build/autotools/ReadCommandLineArguments.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ AC_ARG_ENABLE(tracing,
1010
[],[enable_tracing="no"])
1111
AC_MSG_RESULT([$enable_tracing])
1212

13+
AC_MSG_CHECKING([whether to automatic init and cleanup])
14+
AC_ARG_ENABLE(automatic-init-and-cleanup,
15+
AC_HELP_STRING([--enable-automatic-init-and-cleanup], [turn on automatic mongoc_init() and mongoc_cleanup() [default=yes]]),
16+
[],[enable_automatic_init_and_cleanup="yes"])
17+
AC_MSG_RESULT([$enable_automatic_init_and_cleanup])
18+
1319
AC_MSG_CHECKING([whether to enable optimized builds])
1420
AC_ARG_ENABLE(optimizations,
1521
AC_HELP_STRING([--enable-optimizations], [turn on build-time optimizations [default=yes]]),

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ m4_include([build/autotools/Optimizations.m4])
3333
m4_include([build/autotools/Coverage.m4])
3434
m4_include([build/autotools/LDVersionScript.m4])
3535
m4_include([build/autotools/WeakSymbols.m4])
36+
m4_include([build/autotools/AutomaticInitAndCleanup.m4])
3637

3738
# We would put AM_INIT_AUTOMAKE into SetupAutomake.m4, but seems to cause
3839
# autoconf errors.

src/mongoc/mongoc-config.h.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@
6666
#endif
6767

6868

69+
/*
70+
* Disable automatic calls to mongoc_init() and mongoc_cleanup()
71+
* before main() is called, and after exit() (respectively).
72+
*/
73+
#define MONGOC_NO_AUTOMATIC_GLOBALS @MONGOC_NO_AUTOMATIC_GLOBALS@
74+
75+
#if MONGOC_NO_AUTOMATIC_GLOBALS != 1
76+
# undef MONGOC_NO_AUTOMATIC_GLOBALS
77+
#endif
78+
79+
6980
#endif /* MONGOC_CONFIG_H */

0 commit comments

Comments
 (0)