@@ -14,12 +14,14 @@ include (MongoC-Warnings)
14
14
15
15
set (BSON_OUTPUT_BASENAME "bson" CACHE STRING "Output bson library base name" )
16
16
17
+ include (CheckCSourceCompiles)
17
18
include (CheckFunctionExists)
18
19
include (CheckIncludeFile)
20
+ include (CheckIncludeFiles)
19
21
include (CheckStructHasMember)
20
22
include (CheckSymbolExists)
21
- include (TestBigEndian)
22
23
include (InstallRequiredSystemLibraries)
24
+ include (TestBigEndian)
23
25
24
26
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR} /build /cmake)
25
27
@@ -83,8 +85,6 @@ else ()
83
85
set (BSON_OS 1)
84
86
endif ()
85
87
86
- include (CheckIncludeFiles)
87
-
88
88
CHECK_INCLUDE_FILE (strings .h BSON_HAVE_STRINGS_H)
89
89
if (NOT BSON_HAVE_STRINGS_H)
90
90
set (BSON_HAVE_STRINGS_H 0)
@@ -119,6 +119,38 @@ else ()
119
119
set (BSON_BYTE_ORDER 1234)
120
120
endif ()
121
121
122
+ # 1. Normally, `defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600` should be enough
123
+ # to detect if an XSI-compliant `strerror_r` is available.
124
+ # 2. However, GNU provides an incompatible `strerror_r` as an extension,
125
+ # requiring an additional test for `!defined(_GNU_SOURCE)`.
126
+ # 3. However, musl does not support the GNU extension even when `_GNU_SOURCE` is
127
+ # defined, preventing `!defined(_GNU_SOURCE)` from being a portable
128
+ # XSI-compliance test.
129
+ # 4. However, musl does not provide a feature test macro to detect compilation
130
+ # with musl, and workarounds that use internal glibc feature test macros such
131
+ # as `defined(__USE_GNU)` are explicitly forbidden by glibc documentation.
132
+ # 5. Therefore, give up on using feature test macros: use `CheckCSourceCompiles`
133
+ # to test if the current `strerror_r` is XSI-compliant if present.
134
+ if (NOT WIN32 )
135
+ CHECK_C_SOURCE_COMPILES(
136
+ [[
137
+ #include <string.h>
138
+ int test(int errnum, char *buf, size_t buflen) {
139
+ return strerror_r (errnum, buf, buflen);
140
+ }
141
+ int main(void) {}
142
+ ]]
143
+ BSON_HAVE_XSI_STRERROR_R
144
+ FAIL_REGEX "int-conversion"
145
+ )
146
+ endif ()
147
+
148
+ if (BSON_HAVE_XSI_STRERROR_R)
149
+ set (BSON_HAVE_XSI_STRERROR_R 1)
150
+ else ()
151
+ set (BSON_HAVE_XSI_STRERROR_R 0)
152
+ endif ()
153
+
122
154
configure_file (
123
155
"${PROJECT_SOURCE_DIR} /src/bson/bson-config.h.in"
124
156
"${PROJECT_BINARY_DIR} /src/bson/bson-config.h"
0 commit comments