|
| 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