Skip to content

Fix build for FreeBSD #1243

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 7 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ endif ()
add_definitions (-D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE)
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE)

# Enable non-standard features on FreeBSD with __BSD_VISIBLE=1
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions (-D__BSD_VISIBLE=1)
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1)
endif ()

# https://opensource.apple.com/source/Libc/Libc-1439.40.11/gen/compat.5.auto.html
# Non-POSIX extensions are required by `_SC_NPROCESSORS_ONLN`.
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
Expand Down
19 changes: 17 additions & 2 deletions build/cmake/FindResSearch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ if (ENABLE_SRV STREQUAL ON OR ENABLE_SRV STREQUAL AUTO)
set (MONGOC_HAVE_RES_NCLOSE 0)
endif ()
endif ()
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
# On FreeBSD, the following line does not properly detect res_search,
# which is included in libc on FreeBSD:
# check_symbol_exists (res_search resolv.h MONGOC_HAVE_RES_SEARCH)
#
# Attempting to link with libresolv on FreeBSD will fail with this error:
# ld: error: unable to find library -lresolv
#
# Since res_search has existed since 4.3 BSD (which is the predecessor
# of FreeBSD), it is safe to assume that this function will exist in
# libc on FreeBSD.
set (MONGOC_HAVE_RES_SEARCH 1)
set (MONGOC_HAVE_RES_NSEARCH 0)
set (MONGOC_HAVE_RES_NDESTROY 0)
set (MONGOC_HAVE_RES_NCLOSE 0)
else ()
set (MONGOC_HAVE_RES_NSEARCH 0)
set (MONGOC_HAVE_RES_NDESTROY 0)
Expand All @@ -48,10 +63,10 @@ else ()
set (MONGOC_HAVE_RES_NSEARCH 0)
set (MONGOC_HAVE_RES_NDESTROY 0)
set (MONGOC_HAVE_RES_NCLOSE 0)
set (MONGOC_HAVE_RES_SEARCH 0)
set (MONGOC_HAVE_RES_SEARCH 0)
endif ()

if (ENABLE_SRV STREQUAL ON AND NOT RESOLV_LIBRARIES)
if (ENABLE_SRV STREQUAL ON AND NOT RESOLV_LIBRARIES AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
message (
FATAL_ERROR
"Cannot find libresolv or dnsapi. Try setting ENABLE_SRV=OFF")
Expand Down
4 changes: 2 additions & 2 deletions src/libbson/tests/test-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -2113,8 +2113,8 @@ test_bson_json_double (void)
BSON_ASSERT (BSON_ITER_HOLDS_DOUBLE (&iter));
ASSERT_CMPDOUBLE (bson_iter_double (&iter), ==, 0.0);

/* check that "x" is -0.0. signbit not available on Solaris or VS 2010 */
#if !defined(__sun) && (!defined(_MSC_VER) || (_MSC_VER >= 1800))
/* check that "x" is -0.0. signbit not available on Solaris, FreeBSD, or VS 2010 */
#if !defined(__sun) && !defined(__FreeBSD__) && (!defined(_MSC_VER) || (_MSC_VER >= 1800))
BSON_ASSERT (signbit (bson_iter_double (&iter)));
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/


#include <bson/bson.h>
#include "mongoc-config.h"
#ifdef MONGOC_HAVE_DNSAPI
Expand All @@ -25,6 +24,7 @@
#else
#if defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH)
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/nameser.h>
#include <resolv.h>
Expand Down
1 change: 1 addition & 0 deletions src/libmongoc/src/mongoc/mongoc-counters-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sys/sysinfo.h>
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
defined(__OpenBSD__)
#include <sched.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/param.h>
Expand Down