Skip to content

Commit 9d2d8b1

Browse files
authored
CDRIVER-4249 Apply _DEFAULT_SOURCE to all subdirectories (#920)
* Remove deprecated feature test macro _BSD_SOURCE * Reduce language extensions to those specified by _DEFAULT_SOURCE * Apply _DEFAULT_SOURCE to all subdirectories * Remove explicit feature test macros from Evergreen tasks * Address missing inclusion of unistd.h during zlib bundle compilation
1 parent e7e1500 commit 9d2d8b1

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

.evergreen/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ tasks:
10231023
shell: bash
10241024
script: |-
10251025
set -o errexit
1026-
export CFLAGS="-std=c11 -D_XOPEN_SOURCE=600"
1026+
export CFLAGS="-std=c11"
10271027
export DEBUG="ON"
10281028
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
10291029
- func: upload build
@@ -1041,7 +1041,7 @@ tasks:
10411041
shell: bash
10421042
script: |-
10431043
set -o errexit
1044-
export CFLAGS="-std=c99 -D_XOPEN_SOURCE=600"
1044+
export CFLAGS="-std=c99"
10451045
export DEBUG="ON"
10461046
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
10471047
- func: upload build
@@ -1059,7 +1059,7 @@ tasks:
10591059
shell: bash
10601060
script: |-
10611061
set -o errexit
1062-
export CFLAGS="-std=c89 -D_POSIX_C_SOURCE=200112L -pedantic"
1062+
export CFLAGS="-std=c89 -pedantic"
10631063
export DEBUG="ON"
10641064
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
10651065
- func: upload build

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ set (CMAKE_MACOSX_RPATH ON)
235235
# silence a CMake 3.11 warning that the old behavior is deprecated.
236236
cmake_policy (SET CMP0042 NEW)
237237

238+
# https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
239+
# Enable features from POSIX.1-2008 as well as certain BSD and SVID features.
240+
add_definitions (-D_DEFAULT_SOURCE)
241+
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_DEFAULT_SOURCE)
242+
238243
add_subdirectory (src/common)
239244

240245
if (NOT USING_SYSTEM_BSON)
@@ -253,10 +258,6 @@ if (MSVC)
253258
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
254259
endif ()
255260

256-
add_definitions (-D_GNU_SOURCE)
257-
add_definitions (-D_BSD_SOURCE)
258-
add_definitions (-D_DEFAULT_SOURCE)
259-
260261
if (ENABLE_MONGOC)
261262

262263
if (ENABLE_TESTS AND NOT MONGOC_ENABLE_STATIC_BUILD)

build/evergreen_config_lib/tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ def __init__(self, task_name, suffix_commands, orchestration=True, **kwargs):
191191
CompileTask('debug-compile-lto-thin', CFLAGS='-flto=thin'),
192192
SpecialTask('debug-compile-c11',
193193
tags=['debug-compile', 'c11', 'stdflags'],
194-
CFLAGS='-std=c11 -D_XOPEN_SOURCE=600'),
194+
CFLAGS='-std=c11'),
195195
SpecialTask('debug-compile-c99',
196196
tags=['debug-compile', 'c99', 'stdflags'],
197-
CFLAGS='-std=c99 -D_XOPEN_SOURCE=600'),
197+
CFLAGS='-std=c99'),
198198
SpecialTask('debug-compile-c89',
199199
tags=['debug-compile', 'c89', 'stdflags'],
200-
CFLAGS='-std=c89 -D_POSIX_C_SOURCE=200112L -pedantic'),
200+
CFLAGS='-std=c89 -pedantic'),
201201
SpecialTask('debug-compile-valgrind',
202202
tags=['debug-compile', 'valgrind'],
203203
SASL='OFF',

src/libbson/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ set (BSON_API_VERSION 1.0)
3535
set (CPACK_PACKAGE_VERSION_MAJOR ${BSON_MAJOR_VERSION})
3636
set (CPACK_PACKAGE_VERSION_MINOR ${BSON_MINOR_VERSION})
3737

38-
# Enable X/Open 7.0 / POSIX 2008
39-
if (NOT WIN32)
40-
add_compile_options(-D_XOPEN_SOURCE=700)
41-
# Add to CMAKE_REQUIRED_DEFINITIONS to apply to CHECK_SYMBOL_EXISTS.
42-
set (CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_XOPEN_SOURCE=700")
43-
endif ()
44-
# Enable macOS extensions for strlcpy and arc4random.
45-
if (APPLE)
46-
add_compile_options(-D_DARWIN_C_SOURCE=1)
47-
# Add to CMAKE_REQUIRED_DEFINITIONS to apply to CHECK_SYMBOL_EXISTS.
48-
set (CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_DARWIN_C_SOURCE=1")
49-
endif ()
50-
5138
include (CPack)
5239
TEST_BIG_ENDIAN (BSON_BIG_ENDIAN)
5340

src/libmongoc/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ if (NOT ENABLE_ZLIB STREQUAL "OFF")
9999
include (CheckIncludeFiles)
100100
check_include_files ("unistd.h" HAVE_UNISTD_H)
101101
check_include_files ("stdarg.h" HAVE_STDARG_H)
102+
if (HAVE_UNISTD_H)
103+
add_definitions (-DHAVE_UNISTD_H)
104+
endif ()
105+
if (HAVE_STDARG_H)
106+
add_definitions (-DHAVE_STDARG_H)
107+
endif ()
102108
set (MONGOC_ENABLE_COMPRESSION 1)
103109
set (MONGOC_ENABLE_COMPRESSION_ZLIB 1)
104110
else ()

0 commit comments

Comments
 (0)