Skip to content

Commit 0dc1a4e

Browse files
CDRIVER-4637 Remove ENABLE_SRV=AUTO, clean up SRV URI support (#1301)
Remove AUTO for ENABLE_SRV, refactor .pc generation This AUTO wasn't doing anything, and behaved very similar to plain ON. Now we define an interface library that provides the resolving library. Some cleanup to the ResSearch lookup module. * Use ENABLE_SRV to toggle SRV support rather than detection macros * Add distinct feature flag for SRV toggle. * Refactor pkg-config generation to use target properties This change uses target properties to fill in the slots in the generated pkg-config files. Previously this was unstructured strings and flag juggling. * Tweak method of detecting name resolution Co-authored-by: Roberto C. Sánchez <[email protected]>
1 parent ffb3d34 commit 0dc1a4e

17 files changed

+312
-169
lines changed

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ mongo_bool_setting(ENABLE_EXAMPLES "Build MongoDB C Driver examples")
7171
mongo_bool_setting(ENABLE_MAN_PAGES "Build the manual pages" DEFAULT VALUE OFF)
7272
mongo_bool_setting(ENABLE_HTML_DOCS "Build the HTML documentation" DEFAULT VALUE OFF)
7373
mongo_bool_setting(ENABLE_UNINSTALL "Generate an 'uninstall' script and an 'uninstall' build target")
74+
mongo_bool_setting(ENABLE_SRV "Enable support for mongodb+srv URIs.")
7475

7576
# Optional features that are ENABLED when necessary dependencies are found:
76-
mongo_setting(ENABLE_SRV "Enable support for mongodb+srv URIs."
77-
OPTIONS ON OFF AUTO
78-
DEFAULT VALUE AUTO)
7977
mongo_setting(ENABLE_SNAPPY "Enable Snappy compression support"
8078
OPTIONS ON OFF AUTO
8179
DEFAULT VALUE AUTO)

build/cmake/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ add_subdirectory (make_dist)
22

33
set (build_cmake_MODULES
44
CheckSchedGetCPU.cmake
5-
FindResSearch.cmake
5+
ResSearch.cmake
66
FindSASL2.cmake
77
FindSnappy.cmake
88
FindSphinx.cmake

build/cmake/FindResSearch.cmake

Lines changed: 0 additions & 73 deletions
This file was deleted.

build/cmake/ResSearch.cmake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
include(CheckSymbolExists)
2+
include(CMakePushCheckState)
3+
4+
cmake_push_check_state(RESET)
5+
6+
# The name of the library that performs name resolution, suitable for giving to the "-l" link flag
7+
set(RESOLVE_LIB_NAME)
8+
# If TRUE, then the C runtime provides the name resolution that we need
9+
set(resolve_is_libc FALSE)
10+
11+
if(WIN32)
12+
set(RESOLVE_LIB_NAME Dnsapi)
13+
set(_MONGOC_HAVE_DNSAPI 1)
14+
else()
15+
# Try to find the search functions for various configurations.
16+
# Headers required by minimum on the strictest system: (Tested on FreeBSD 13)
17+
set(resolve_headers netinet/in.h sys/types.h arpa/nameser.h resolv.h)
18+
set(CMAKE_REQUIRED_LIBRARIES resolv)
19+
check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_RESOLV)
20+
check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_RESOLV)
21+
check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_RESOLV)
22+
check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_RESOLV)
23+
if((_MONGOC_HAVE_RES_NSEARCH_RESOLV OR _MONGOC_HAVE_RES_SEARCH_RESOLV)
24+
AND (_MONGOC_HAVE_RES_NDESTROY_RESOLV OR _MONGOC_HAVE_RES_NCLOSE_RESOLV))
25+
set(RESOLVE_LIB_NAME resolv)
26+
else()
27+
# Can we use name resolution with just libc?
28+
unset(CMAKE_REQUIRED_LIBRARIES)
29+
check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_NOLINK)
30+
check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_NOLINK)
31+
check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_NOLINK)
32+
check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_NOLINK)
33+
if((_MONGOC_HAVE_RES_NSEARCH_NOLINK OR _MONGOC_HAVE_RES_SEARCH_NOLINK)
34+
AND (_MONGOC_HAVE_RES_NDESTROY_NOLINK OR _MONGOC_HAVE_RES_NCLOSE_NOLINK))
35+
set(resolve_is_libc TRUE)
36+
message(VERBOSE "Name resolution is provided by the C runtime")
37+
endif()
38+
endif()
39+
endif()
40+
41+
_mongo_pick(MONGOC_HAVE_DNSAPI 1 0 _MONGOC_HAVE_DNSAPI)
42+
_mongo_pick(MONGOC_HAVE_RES_NSEARCH 1 0 [[_MONGOC_HAVE_RES_NSEARCH_NOLINK OR _MONGOC_HAVE_RES_NSEARCH_RESOLV]])
43+
_mongo_pick(MONGOC_HAVE_RES_SEARCH 1 0 [[_MONGOC_HAVE_RES_SEARCH_NOLINK OR _MONGOC_HAVE_RES_SEARCH_RESOLV]])
44+
_mongo_pick(MONGOC_HAVE_RES_NDESTROY 1 0 [[_MONGOC_HAVE_RES_NDESTROY_NOLINK OR _MONGOC_HAVE_RES_NDESTROY_RESOLV]])
45+
_mongo_pick(MONGOC_HAVE_RES_NCLOSE 1 0 [[_MONGOC_HAVE_RES_NCLOSE_NOLINK OR _MONGOC_HAVE_RES_NCLOSE_RESOLV]])
46+
47+
if(RESOLVE_LIB_NAME OR resolve_is_libc)
48+
# Define the resolver interface:
49+
add_library(_mongoc-resolve INTERFACE)
50+
add_library(mongo::detail::c_resolve ALIAS _mongoc-resolve)
51+
set_target_properties(_mongoc-resolve PROPERTIES
52+
INTERFACE_LINK_LIBRARIES "${RESOLVE_LIB_NAME}"
53+
EXPORT_NAME detail::c_resolve)
54+
install(TARGETS _mongoc-resolve EXPORT mongoc-targets)
55+
endif()
56+
57+
cmake_pop_check_state()

0 commit comments

Comments
 (0)