Skip to content

CDRIVER-4249 Apply _DEFAULT_SOURCE to all subdirectories #920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 5, 2022
6 changes: 3 additions & 3 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ tasks:
shell: bash
script: |-
set -o errexit
export CFLAGS="-std=c11 -D_XOPEN_SOURCE=600"
export CFLAGS="-std=c11"
export DEBUG="ON"
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
- func: upload build
Expand All @@ -1041,7 +1041,7 @@ tasks:
shell: bash
script: |-
set -o errexit
export CFLAGS="-std=c99 -D_XOPEN_SOURCE=600"
export CFLAGS="-std=c99"
export DEBUG="ON"
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
- func: upload build
Expand All @@ -1059,7 +1059,7 @@ tasks:
shell: bash
script: |-
set -o errexit
export CFLAGS="-std=c89 -D_POSIX_C_SOURCE=200112L -pedantic"
export CFLAGS="-std=c89 -pedantic"
export DEBUG="ON"
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
- func: upload build
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ set (CMAKE_MACOSX_RPATH ON)
# silence a CMake 3.11 warning that the old behavior is deprecated.
cmake_policy (SET CMP0042 NEW)

# https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
# Enable features from POSIX.1-2008 as well as certain BSD and SVID features.
add_definitions (-D_DEFAULT_SOURCE)
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_DEFAULT_SOURCE)

add_subdirectory (src/common)

if (NOT USING_SYSTEM_BSON)
Expand All @@ -253,10 +258,6 @@ if (MSVC)
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
endif ()

add_definitions (-D_GNU_SOURCE)
add_definitions (-D_BSD_SOURCE)
add_definitions (-D_DEFAULT_SOURCE)

if (ENABLE_MONGOC)

if (ENABLE_TESTS AND NOT MONGOC_ENABLE_STATIC_BUILD)
Expand Down
6 changes: 3 additions & 3 deletions build/evergreen_config_lib/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ def __init__(self, task_name, suffix_commands, orchestration=True, **kwargs):
CompileTask('debug-compile-lto-thin', CFLAGS='-flto=thin'),
SpecialTask('debug-compile-c11',
tags=['debug-compile', 'c11', 'stdflags'],
CFLAGS='-std=c11 -D_XOPEN_SOURCE=600'),
CFLAGS='-std=c11'),
SpecialTask('debug-compile-c99',
tags=['debug-compile', 'c99', 'stdflags'],
CFLAGS='-std=c99 -D_XOPEN_SOURCE=600'),
CFLAGS='-std=c99'),
SpecialTask('debug-compile-c89',
tags=['debug-compile', 'c89', 'stdflags'],
CFLAGS='-std=c89 -D_POSIX_C_SOURCE=200112L -pedantic'),
CFLAGS='-std=c89 -pedantic'),
SpecialTask('debug-compile-valgrind',
tags=['debug-compile', 'valgrind'],
SASL='OFF',
Expand Down
13 changes: 0 additions & 13 deletions src/libbson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ set (BSON_API_VERSION 1.0)
set (CPACK_PACKAGE_VERSION_MAJOR ${BSON_MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${BSON_MINOR_VERSION})

# Enable X/Open 7.0 / POSIX 2008
if (NOT WIN32)
add_compile_options(-D_XOPEN_SOURCE=700)
# Add to CMAKE_REQUIRED_DEFINITIONS to apply to CHECK_SYMBOL_EXISTS.
set (CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_XOPEN_SOURCE=700")
endif ()
# Enable macOS extensions for strlcpy and arc4random.
if (APPLE)
add_compile_options(-D_DARWIN_C_SOURCE=1)
# Add to CMAKE_REQUIRED_DEFINITIONS to apply to CHECK_SYMBOL_EXISTS.
set (CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_DARWIN_C_SOURCE=1")
endif ()

include (CPack)
TEST_BIG_ENDIAN (BSON_BIG_ENDIAN)

Expand Down
6 changes: 6 additions & 0 deletions src/libmongoc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ if (NOT ENABLE_ZLIB STREQUAL "OFF")
include (CheckIncludeFiles)
check_include_files ("unistd.h" HAVE_UNISTD_H)
check_include_files ("stdarg.h" HAVE_STDARG_H)
if (HAVE_UNISTD_H)
add_definitions (-DHAVE_UNISTD_H)
endif ()
if (HAVE_STDARG_H)
add_definitions (-DHAVE_STDARG_H)
endif ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offhand, PHP was already defining HAVE_UNISTD_H for bundled zlib. It was trivial to make the change for HAVE_STDARG_H, although I didn't notice any build failure omitting it on Ubuntu 20.04.

LGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Lack of) <stdarg.h> was not causing issues, as far as I could observe. HAVE_STDARG_H was just added to compliment the addition of HAVE_UNISTD_H for consistency. The (lack of) <unistd.h> was the relevant issue being addressed.

set (MONGOC_ENABLE_COMPRESSION 1)
set (MONGOC_ENABLE_COMPRESSION_ZLIB 1)
else ()
Expand Down