From a84fa5a76d0400f56545b60f92f56526ed867fa1 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 5 Jun 2023 19:35:47 +0000 Subject: [PATCH 01/13] Remove AUTO for ENABLE_SRV 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. --- CMakeLists.txt | 4 +- build/cmake/CMakeLists.txt | 2 +- build/cmake/FindResSearch.cmake | 73 ------------------- build/cmake/ResSearch.cmake | 53 ++++++++++++++ src/libmongoc/CMakeLists.txt | 27 +++++-- .../build/cmake/libmongoc-1.0-config.cmake.in | 2 +- .../libmongoc-static-1.0-config.cmake.in | 4 +- 7 files changed, 79 insertions(+), 86 deletions(-) delete mode 100644 build/cmake/FindResSearch.cmake create mode 100644 build/cmake/ResSearch.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6846efe8ca9..3a9da60b1e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,9 +73,7 @@ mongo_bool_setting(ENABLE_HTML_DOCS "Build the HTML documentation" DEFAULT VALUE mongo_bool_setting(ENABLE_UNINSTALL "Generate an 'uninstall' script and an 'uninstall' build target") # Optional features that are ENABLED when necessary dependencies are found: -mongo_setting(ENABLE_SRV "Enable support for mongodb+srv URIs." - OPTIONS ON OFF AUTO - DEFAULT VALUE AUTO) +mongo_bool_setting(ENABLE_SRV "Enable support for mongodb+srv URIs.") mongo_setting(ENABLE_SNAPPY "Enable Snappy compression support" OPTIONS ON OFF AUTO DEFAULT VALUE AUTO) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 97875a8c1b5..d9c93e81490 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -2,7 +2,7 @@ add_subdirectory (make_dist) set (build_cmake_MODULES CheckSchedGetCPU.cmake - FindResSearch.cmake + ResSearch.cmake FindSASL2.cmake FindSnappy.cmake FindSphinx.cmake diff --git a/build/cmake/FindResSearch.cmake b/build/cmake/FindResSearch.cmake deleted file mode 100644 index c96550656bd..00000000000 --- a/build/cmake/FindResSearch.cmake +++ /dev/null @@ -1,73 +0,0 @@ -include (CheckSymbolExists) - -if (ENABLE_SRV STREQUAL ON OR ENABLE_SRV STREQUAL AUTO) - if (WIN32) - set (RESOLV_LIBRARIES Dnsapi) - set (MONGOC_HAVE_DNSAPI 1) - set (MONGOC_HAVE_RES_NSEARCH 0) - set (MONGOC_HAVE_RES_NDESTROY 0) - set (MONGOC_HAVE_RES_NCLOSE 0) - set (MONGOC_HAVE_RES_SEARCH 0) - else () - set (MONGOC_HAVE_DNSAPI 0) - # Thread-safe DNS query function for _mongoc_client_get_srv. - # Could be a macro, not a function, so use check_symbol_exists. - check_symbol_exists (res_nsearch resolv.h MONGOC_HAVE_RES_NSEARCH) - if (MONGOC_HAVE_RES_NSEARCH) - set (RESOLV_LIBRARIES resolv) - set (MONGOC_HAVE_RES_SEARCH 0) - - # We have res_nsearch. Call res_ndestroy (BSD/Mac) or res_nclose (Linux)? - check_symbol_exists (res_ndestroy resolv.h MONGOC_HAVE_RES_NDESTROY) - if (MONGOC_HAVE_RES_NDESTROY) - set (MONGOC_HAVE_RES_NCLOSE 0) - else () - set (MONGOC_HAVE_RES_NDESTROY 0) - check_symbol_exists (res_nclose resolv.h MONGOC_HAVE_RES_NCLOSE) - if (NOT MONGOC_HAVE_RES_NCLOSE) - 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) - set (MONGOC_HAVE_RES_NCLOSE 0) - - # Thread-unsafe function. - check_symbol_exists (res_search resolv.h MONGOC_HAVE_RES_SEARCH) - if (MONGOC_HAVE_RES_SEARCH) - set (RESOLV_LIBRARIES resolv) - else () - set (MONGOC_HAVE_RES_SEARCH 0) - endif () - endif () - endif () -else () - # ENABLE_SRV disabled, set default values for defines. - set (MONGOC_HAVE_DNSAPI 0) - set (MONGOC_HAVE_RES_NSEARCH 0) - set (MONGOC_HAVE_RES_NDESTROY 0) - set (MONGOC_HAVE_RES_NCLOSE 0) - set (MONGOC_HAVE_RES_SEARCH 0) -endif () - -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") -endif () diff --git a/build/cmake/ResSearch.cmake b/build/cmake/ResSearch.cmake new file mode 100644 index 00000000000..0542eee5a34 --- /dev/null +++ b/build/cmake/ResSearch.cmake @@ -0,0 +1,53 @@ +include(CheckSymbolExists) + +set(resolve_libs) +set(resolve_is_libc FALSE) + +if(WIN32) + set(resolve_libs Dnsapi) + set(_MONGOC_HAVE_DNSAPI 1) +else() + # Thread-safe DNS query function for _mongoc_client_get_srv. + # Could be a macro, not a function, so use check_symbol_exists. + check_symbol_exists(res_nsearch resolv.h _MONGOC_HAVE_RES_NSEARCH) + check_symbol_exists(res_ndestroy resolv.h _MONGOC_HAVE_RES_NDESTROY) + check_symbol_exists(res_nclose resolv.h _MONGOC_HAVE_RES_NCLOSE) + if(MONGOC_HAVE_RES_NSEARCH) + # We have res_nsearch. Call res_ndestroy (BSD/Mac) or res_nclose (Linux)? + set(resolve_libs resolv) + 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(resolve_is_libc TRUE) + else() + # Thread-unsafe function. + check_symbol_exists(res_search resolv.h _MONGOC_HAVE_RES_SEARCH) + if(_MONGOC_HAVE_RES_SEARCH) + set(resolve_libs resolv) + endif() + endif() +endif() + +_mongo_pick(MONGOC_HAVE_DNSAPI 1 0 _MONGOC_HAVE_DNSAPI) +_mongo_pick(MONGOC_HAVE_RES_NSEARCH 1 0 _MONGOC_HAVE_RES_NSEARCH) +_mongo_pick(MONGOC_HAVE_RES_NDESTROY 1 0 _MONGOC_HAVE_RES_NDESTROY) +_mongo_pick(MONGOC_HAVE_RES_NCLOSE 1 0 _MONGOC_HAVE_RES_NCLOSE) +_mongo_pick(MONGOC_HAVE_RES_SEARCH 1 0 _MONGOC_HAVE_RES_SEARCH) + +if(resolve_libs OR resolve_is_libc) + # Define the resolver interface: + add_library(_mongoc-resolve INTERFACE) + target_link_libraries(_mongoc-resolve INTERFACE ${resolve_libs}) + add_library(mongo::c::detail::resolve ALIAS _mongoc-resolve) + set_property(TARGET _mongoc-resolve PROPERTY EXPORT_NAME c::detail::resolve) + install(TARGETS _mongoc-resolve EXPORT mongoc-targets) +endif() diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index aa59f9e4ab6..de93e1221ec 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -288,7 +288,9 @@ else () set (MONGOC_SOCKET_ARG3 "int") endif () -include (FindResSearch) +# Find name resolution libaries. Also sets definitions used in configure_file(): +include(ResSearch) + include (CheckSchedGetCPU) function (mongoc_get_accept_args ARG2 ARG3) @@ -701,14 +703,27 @@ if (CMAKE_USE_PTHREADS_INIT) endif () set (LIBRARIES - ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${RESOLV_LIBRARIES} + ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} Threads::Threads ${ICU_LIBRARIES} ${LIBMONGOCRYPT_LIBRARY} ) set (STATIC_LIBRARIES - ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SSL_STATIC_LIBRARIES} ${SHM_LIBRARIES} ${RESOLV_LIBRARIES} + ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SSL_STATIC_LIBRARIES} ${SHM_LIBRARIES} ${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ICU_LIBRARIES} ${LIBMONGOCRYPT_LIBRARY} ) +add_library(_mongoc-dependencies INTERFACE) +add_library(mongo::c::dependencies ALIAS _mongoc-dependencies) +install(TARGETS _mongoc-dependencies EXPORT mongoc-targets) +set_property(TARGET _mongoc-dependencies PROPERTY EXPORT_NAME dependencies) + +if(ENABLE_SRV) + # Interface target defined by ResSearch.cmake: + if(NOT TARGET mongo::c::detail::resolve) + message(SEND_ERROR "ENABLE_SRV is “${ENABLE_SRV}”, but we were unable to find a name resolution library") + endif() + target_link_libraries(_mongoc-dependencies INTERFACE mongo::c::detail::resolve) +endif() + if (WIN32) set (LIBRARIES ${LIBRARIES} ws2_32) endif () @@ -733,7 +748,7 @@ endif () add_library (mongoc_shared SHARED ${SOURCES} ${HEADERS} ${HEADERS_FORWARDING}) set_target_properties (mongoc_shared PROPERTIES CMAKE_CXX_VISIBILITY_PRESET hidden) -target_link_libraries (mongoc_shared PRIVATE ${LIBRARIES} PUBLIC ${BSON_LIBRARIES}) +target_link_libraries (mongoc_shared PRIVATE ${LIBRARIES} PUBLIC ${BSON_LIBRARIES} mongo::c::dependencies) target_include_directories (mongoc_shared PRIVATE ${ZLIB_INCLUDE_DIRS}) target_include_directories (mongoc_shared PRIVATE ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES}) if(ENABLE_COVERAGE) @@ -778,7 +793,7 @@ if (MONGOC_ENABLE_STATIC_BUILD) target_compile_options(mongoc_static PRIVATE --coverage) target_link_options(mongoc_static PUBLIC --coverage) endif() - target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} ${BSON_STATIC_LIBRARIES}) + target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} ${BSON_STATIC_LIBRARIES} mongo::c::dependencies) if (NOT WIN32 AND ENABLE_PIC) target_compile_options (mongoc_static PUBLIC -fPIC) message (STATUS "Adding -fPIC to compilation of mongoc_static components") @@ -1178,7 +1193,7 @@ set (libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") foreach ( FLAG - ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${RESOLV_LIBRARIES} + ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${THREAD_LIB} ${ZLIB_LIBRARIES} ${SNAPPY_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${ICU_LIBRARIES} ${LIBMONGOCRYPT_LIBRARY}) diff --git a/src/libmongoc/build/cmake/libmongoc-1.0-config.cmake.in b/src/libmongoc/build/cmake/libmongoc-1.0-config.cmake.in index feeca0259e9..27a0af45f4e 100644 --- a/src/libmongoc/build/cmake/libmongoc-1.0-config.cmake.in +++ b/src/libmongoc/build/cmake/libmongoc-1.0-config.cmake.in @@ -38,7 +38,7 @@ set (MONGOC_LIBRARIES ${MONGOC_LIBRARY} ${BSON_LIBRARIES}) # like "-framework CoreFoundation;-framework Security". set (IS_FRAMEWORK_VAR 0) foreach (LIB - @SASL_LIBRARIES@ @SSL_LIBRARIES@ @SHM_LIBRARIES@ @RESOLV_LIBRARIES@ + @SASL_LIBRARIES@ @SSL_LIBRARIES@ @SHM_LIBRARIES@ @RESOLVE_LIB_NAME@ @SNAPPY_LIBRARIES@ @ICU_LIBRARIES@ @MONGOC_ZSTD_LIBRARIES@ @LIBMONGOCRYPT_LIBRARY@ ) if (LIB STREQUAL "-framework") diff --git a/src/libmongoc/build/cmake/libmongoc-static-1.0-config.cmake.in b/src/libmongoc/build/cmake/libmongoc-static-1.0-config.cmake.in index 6f05b0c18c4..21ea717472c 100644 --- a/src/libmongoc/build/cmake/libmongoc-static-1.0-config.cmake.in +++ b/src/libmongoc/build/cmake/libmongoc-static-1.0-config.cmake.in @@ -42,8 +42,8 @@ set (MONGOC_STATIC_LIBRARIES ${MONGOC_STATIC_LIBRARY} ${ZLIB_STATIC_LIBRARY} ${B # "-framework CoreFoundation -framework Security". Split into a CMake array # like "-framework CoreFoundation;-framework Security". set (IS_FRAMEWORK_VAR 0) -foreach (LIB @SASL_LIBRARIES@ @SSL_LIBRARIES@ @SHM_LIBRARIES@ @ZLIB_LIBRARIES@ - @SNAPPY_LIBRARIES@ @RESOLV_LIBRARIES@ @ICU_LIBRARIES@ @MONGOC_ZSTD_LIBRARIES@ @LIBMONGOCRYPT_LIBRARY@ +foreach (LIB @SASL_LIBRARIES@ @SSL_LIBRARIES@ @SHM_LIBRARIES@ @ZLIB_LIBRARIES@ @RESOLVE_LIB_NAME@ + @SNAPPY_LIBRARIES@ @ICU_LIBRARIES@ @MONGOC_ZSTD_LIBRARIES@ @LIBMONGOCRYPT_LIBRARY@ ) if (LIB STREQUAL "-framework") set (IS_FRAMEWORK_VAR 1) From 6abe0f109f54fc294c1bbcb50332416f9a5c8976 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 5 Jun 2023 20:33:20 +0000 Subject: [PATCH 02/13] Use ENABLE_SRV to toggle SRV support rather than detection macros --- src/libmongoc/CMakeLists.txt | 2 ++ src/libmongoc/src/mongoc/mongoc-client.c | 27 ++++++++++++++------- src/libmongoc/src/mongoc/mongoc-config.h.in | 4 +++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index de93e1221ec..ff1f3964126 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -290,6 +290,8 @@ endif () # Find name resolution libaries. Also sets definitions used in configure_file(): include(ResSearch) +# Definition for mongoc-config.h: +_mongo_pick(MONGOC_ENABLE_SRV 1 0 ENABLE_SRV) include (CheckSchedGetCPU) diff --git a/src/libmongoc/src/mongoc/mongoc-client.c b/src/libmongoc/src/mongoc/mongoc-client.c index 35f972e3d40..d032ddcbca9 100644 --- a/src/libmongoc/src/mongoc/mongoc-client.c +++ b/src/libmongoc/src/mongoc/mongoc-client.c @@ -101,7 +101,11 @@ _mongoc_client_killcursors_command (mongoc_cluster_t *cluster, } while (0) -#ifdef MONGOC_HAVE_DNSAPI +#if MONGOC_ENABLE_SRV == 0 // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ENABLE_SRV disabled + +/* SRV support is disabled */ + +#elif defined(MONGOC_HAVE_DNSAPI) // ↑↑↑ ENABLE_SRV disabled / Win32 Dnsapi ↓↓↓↓ typedef bool (*mongoc_rr_callback_t) (const char *hostname, PDNS_RECORD pdns, @@ -291,7 +295,9 @@ _mongoc_get_rr_dnsapi (const char *hostname, RETURN (dns_success && callback_success); } -#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH)) +#elif ( \ + defined(MONGOC_HAVE_RES_NSEARCH) || \ + defined(MONGOC_HAVE_RES_SEARCH)) // ↑↑↑↑↑↑↑ Win32 Dnsapi / resolv ↓↓↓↓↓↓↓↓ typedef bool (*mongoc_rr_callback_t) (const char *hostname, ns_msg *ns_answer, @@ -569,7 +575,7 @@ _mongoc_get_rr_search (const char *hostname, #endif RETURN (dns_success && callback_success); } -#endif +#endif // ↑↑↑↑↑↑↑↑↑↑↑↑↑ resolv /* *-------------------------------------------------------------------------- @@ -605,17 +611,20 @@ _mongoc_client_get_rr (const char *hostname, { BSON_ASSERT (rr_data); -#ifdef MONGOC_HAVE_DNSAPI - return _mongoc_get_rr_dnsapi (hostname, rr_type, rr_data, error); -#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH)) - return _mongoc_get_rr_search ( - hostname, rr_type, rr_data, initial_buffer_size, error); -#else +#if MONGOC_ENABLE_SRV == 0 + // Disabled bson_set_error (error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_NAME_RESOLUTION, "libresolv unavailable, cannot use mongodb+srv URI"); return false; +#elif defined(MONGOC_HAVE_DNSAPI) + return _mongoc_get_rr_dnsapi (hostname, rr_type, rr_data, error); +#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH)) + return _mongoc_get_rr_search ( + hostname, rr_type, rr_data, initial_buffer_size, error); +#else +#error No SRV library is available, but ENABLE_SRV is true! #endif } diff --git a/src/libmongoc/src/mongoc/mongoc-config.h.in b/src/libmongoc/src/mongoc/mongoc-config.h.in index 29882211c96..1aa1447cc95 100644 --- a/src/libmongoc/src/mongoc/mongoc-config.h.in +++ b/src/libmongoc/src/mongoc/mongoc-config.h.in @@ -226,6 +226,10 @@ # undef MONGOC_HAVE_SOCKLEN #endif +/** + * @brief Defined to 0/1 for whether we were configured with ENABLE_SRV + */ +#define MONGOC_ENABLE_SRV @MONGOC_ENABLE_SRV@ /* * MONGOC_HAVE_DNSAPI is set from configure to determine if we should use the From 18146ac34142d0fac36336928a7a84123c9acbd3 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Mon, 5 Jun 2023 23:35:36 +0000 Subject: [PATCH 03/13] Add distinct feature flag for SRV toggle. --- src/libmongoc/examples/parse_handshake_cfg.py | 3 +- src/libmongoc/src/mongoc/mongoc-config.h.in | 28 +++++++++++-------- .../src/mongoc/mongoc-handshake-private.h | 1 + src/libmongoc/src/mongoc/mongoc-handshake.c | 4 +++ src/libmongoc/tests/test-mongoc-handshake.c | 3 ++ 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/libmongoc/examples/parse_handshake_cfg.py b/src/libmongoc/examples/parse_handshake_cfg.py index 4d70b039db0..e1da7d70ca4 100644 --- a/src/libmongoc/examples/parse_handshake_cfg.py +++ b/src/libmongoc/examples/parse_handshake_cfg.py @@ -37,7 +37,8 @@ "MONGOC_MD_FLAG_TRACE", "MONGOC_MD_FLAG_ENABLE_ICU", "MONGOC_MD_FLAG_ENABLE_CLIENT_SIDE_ENCRYPTION", - "MONGOC_MD_FLAG_ENABLE_MONGODB_AWS_AUTH" + "MONGOC_MD_FLAG_ENABLE_MONGODB_AWS_AUTH", + "MONGOC_MD_FLAG_ENABLE_SRV", ] def main(): diff --git a/src/libmongoc/src/mongoc/mongoc-config.h.in b/src/libmongoc/src/mongoc/mongoc-config.h.in index 1aa1447cc95..ac4413389f8 100644 --- a/src/libmongoc/src/mongoc/mongoc-config.h.in +++ b/src/libmongoc/src/mongoc/mongoc-config.h.in @@ -372,16 +372,6 @@ */ #define MONGOC_TRACE @MONGOC_TRACE@ -enum { - /** - * @brief Compile-time constant determining whether the mongoc library was - * compiled with tracing enabled. - * - * Can be controlled with the 'ENABLE_TRACING" configure-time boolean option - */ - MONGOC_TRACE_ENABLED = MONGOC_TRACE -}; - /* * Set if we have ICU support. */ @@ -391,7 +381,6 @@ enum { # undef MONGOC_ENABLE_ICU #endif - /* * Set if we have Client Side Encryption support. */ @@ -422,6 +411,23 @@ enum { # undef MONGOC_ENABLE_MONGODB_AWS_AUTH #endif +enum { + /** + * @brief Compile-time constant determining whether the mongoc library was + * compiled with tracing enabled. + * + * Can be controlled with the “ENABLE_TRACING” configure-time boolean option + */ + MONGOC_TRACE_ENABLED = MONGOC_TRACE, + /** + * @brief Compile-time constant indicating whether the mongoc library was + * compiled with SRV server discovery support. + * + * Can be controled with the “ENABLE_SRV” configure-time boolean option. + */ + MONGOC_SRV_ENABLED = MONGOC_ENABLE_SRV, +}; + /* clang-format on */ #endif /* MONGOC_CONFIG_H */ diff --git a/src/libmongoc/src/mongoc/mongoc-handshake-private.h b/src/libmongoc/src/mongoc/mongoc-handshake-private.h index 8da55ebc360..70a141d607b 100644 --- a/src/libmongoc/src/mongoc/mongoc-handshake-private.h +++ b/src/libmongoc/src/mongoc/mongoc-handshake-private.h @@ -81,6 +81,7 @@ typedef enum { MONGOC_MD_FLAG_ENABLE_ICU, MONGOC_MD_FLAG_ENABLE_CLIENT_SIDE_ENCRYPTION, MONGOC_MD_FLAG_ENABLE_MONGODB_AWS_AUTH, + MONGOC_MD_FLAG_ENABLE_SRV, /* Add additional config flags here, above LAST_MONGOC_MD_FLAG. */ LAST_MONGOC_MD_FLAG } mongoc_handshake_config_flag_bit_t; diff --git a/src/libmongoc/src/mongoc/mongoc-handshake.c b/src/libmongoc/src/mongoc/mongoc-handshake.c index dd2f2dd51f0..80bff6ad091 100644 --- a/src/libmongoc/src/mongoc/mongoc-handshake.c +++ b/src/libmongoc/src/mongoc/mongoc-handshake.c @@ -196,6 +196,10 @@ _mongoc_handshake_get_config_hex_string (void) _set_bit (bf, byte_count, MONGOC_MD_FLAG_ENABLE_MONGODB_AWS_AUTH); #endif + if (MONGOC_SRV_ENABLED) { + _set_bit (bf, byte_count, MONGOC_MD_FLAG_ENABLE_SRV); + } + bson_string_t *const str = bson_string_new ("0x"); for (uint32_t i = 0u; i < byte_count; i++) { bson_string_append_printf (str, "%02x", bf[i]); diff --git a/src/libmongoc/tests/test-mongoc-handshake.c b/src/libmongoc/tests/test-mongoc-handshake.c index 6fef3e48cb2..2b090be0e1b 100644 --- a/src/libmongoc/tests/test-mongoc-handshake.c +++ b/src/libmongoc/tests/test-mongoc-handshake.c @@ -871,6 +871,9 @@ test_handshake_platform_config (void) BSON_ASSERT (_get_bit (config_str, MONGOC_MD_FLAG_HAVE_SCHED_GETCPU)); #endif + BSON_ASSERT (_get_bit (config_str, MONGOC_MD_FLAG_ENABLE_SRV) == + MONGOC_SRV_ENABLED); + #ifdef MONGOC_ENABLE_SHM_COUNTERS BSON_ASSERT (_get_bit (config_str, MONGOC_MD_FLAG_ENABLE_SHM_COUNTERS)); #endif From ea2ef8a4c0b1ef46fdc31ff919f207d3029b900a Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 6 Jun 2023 06:45:21 +0000 Subject: [PATCH 04/13] 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. --- build/cmake/ResSearch.cmake | 19 ++- src/libmongoc/CMakeLists.txt | 158 ++++++++++++++----- src/libmongoc/src/CMakeLists.txt | 3 +- src/libmongoc/src/libmongoc-1.0.pc.in | 11 -- src/libmongoc/src/libmongoc-static-1.0.pc.in | 11 -- src/libmongoc/src/libmongoc.pc.in | 63 ++++++++ 6 files changed, 192 insertions(+), 73 deletions(-) delete mode 100644 src/libmongoc/src/libmongoc-1.0.pc.in delete mode 100644 src/libmongoc/src/libmongoc-static-1.0.pc.in create mode 100644 src/libmongoc/src/libmongoc.pc.in diff --git a/build/cmake/ResSearch.cmake b/build/cmake/ResSearch.cmake index 0542eee5a34..f0632ee3a99 100644 --- a/build/cmake/ResSearch.cmake +++ b/build/cmake/ResSearch.cmake @@ -1,10 +1,12 @@ include(CheckSymbolExists) -set(resolve_libs) +# The name of the library that performs name resolution, suitable for giving to the "-l" link flag +set(RESOLVE_LIB_NAME) +# If TRUE, then the C runtime provides the name resolution that we need set(resolve_is_libc FALSE) if(WIN32) - set(resolve_libs Dnsapi) + set(RESOLVE_LIB_NAME Dnsapi) set(_MONGOC_HAVE_DNSAPI 1) else() # Thread-safe DNS query function for _mongoc_client_get_srv. @@ -14,7 +16,7 @@ else() check_symbol_exists(res_nclose resolv.h _MONGOC_HAVE_RES_NCLOSE) if(MONGOC_HAVE_RES_NSEARCH) # We have res_nsearch. Call res_ndestroy (BSD/Mac) or res_nclose (Linux)? - set(resolve_libs resolv) + set(RESOLVE_LIB_NAME resolv) elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") # On FreeBSD, the following line does not properly detect res_search, # which is included in libc on FreeBSD: @@ -32,7 +34,7 @@ else() # Thread-unsafe function. check_symbol_exists(res_search resolv.h _MONGOC_HAVE_RES_SEARCH) if(_MONGOC_HAVE_RES_SEARCH) - set(resolve_libs resolv) + set(RESOLVE_LIB_NAME resolv) endif() endif() endif() @@ -43,11 +45,12 @@ _mongo_pick(MONGOC_HAVE_RES_NDESTROY 1 0 _MONGOC_HAVE_RES_NDESTROY) _mongo_pick(MONGOC_HAVE_RES_NCLOSE 1 0 _MONGOC_HAVE_RES_NCLOSE) _mongo_pick(MONGOC_HAVE_RES_SEARCH 1 0 _MONGOC_HAVE_RES_SEARCH) -if(resolve_libs OR resolve_is_libc) +if(RESOLVE_LIB_NAME OR resolve_is_libc) # Define the resolver interface: add_library(_mongoc-resolve INTERFACE) - target_link_libraries(_mongoc-resolve INTERFACE ${resolve_libs}) - add_library(mongo::c::detail::resolve ALIAS _mongoc-resolve) - set_property(TARGET _mongoc-resolve PROPERTY EXPORT_NAME c::detail::resolve) + add_library(mongo::detail::c_resolve ALIAS _mongoc-resolve) + set_target_properties(_mongoc-resolve PROPERTIES + INTERFACE_LINK_LIBRARIES "${RESOLVE_LIB_NAME}" + EXPORT_NAME detail::c_resolve) install(TARGETS _mongoc-resolve EXPORT mongoc-targets) endif() diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index ff1f3964126..a849056438b 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -720,10 +720,10 @@ set_property(TARGET _mongoc-dependencies PROPERTY EXPORT_NAME dependencies) if(ENABLE_SRV) # Interface target defined by ResSearch.cmake: - if(NOT TARGET mongo::c::detail::resolve) + if(NOT TARGET mongo::detail::c_resolve) message(SEND_ERROR "ENABLE_SRV is “${ENABLE_SRV}”, but we were unable to find a name resolution library") endif() - target_link_libraries(_mongoc-dependencies INTERFACE mongo::c::detail::resolve) + target_link_libraries(_mongoc-dependencies INTERFACE mongo::detail::c_resolve) endif() if (WIN32) @@ -786,8 +786,12 @@ target_include_directories ( $ ) -set_target_properties (mongoc_shared PROPERTIES VERSION 0.0.0 SOVERSION 0) -set_target_properties (mongoc_shared PROPERTIES OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-${MONGOC_API_VERSION}") +set_target_properties (mongoc_shared PROPERTIES + OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-${MONGOC_API_VERSION}" + VERSION 0.0.0 + SOVERSION 0 + pc_REQUIRES "libbson-1.0" + ) if (MONGOC_ENABLE_STATIC_BUILD) add_library (mongoc_static STATIC ${SOURCES} ${HEADERS} ${HEADERS_FORWARDING}) @@ -800,6 +804,10 @@ if (MONGOC_ENABLE_STATIC_BUILD) target_compile_options (mongoc_static PUBLIC -fPIC) message (STATUS "Adding -fPIC to compilation of mongoc_static components") endif () + if(ENABLE_SRV AND RESOLVE_LIB_NAME) + # The static library needs to link to the resolver in pkg-config: + set_property(TARGET mongoc_static APPEND PROPERTY pc_LIBS "-l${RESOLVE_LIB_NAME}") + endif() target_include_directories (mongoc_static PRIVATE ${ZLIB_INCLUDE_DIRS}) target_include_directories (mongoc_static PRIVATE ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES}) if (MONGOC_ENABLE_MONGODB_AWS_AUTH) @@ -827,8 +835,11 @@ if (MONGOC_ENABLE_STATIC_BUILD) $ $ ) - set_target_properties (mongoc_static PROPERTIES VERSION 0.0.0) - set_target_properties (mongoc_static PROPERTIES OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-static-${MONGOC_API_VERSION}") + set_target_properties (mongoc_static PROPERTIES + VERSION 0.0.0 + OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-static-${MONGOC_API_VERSION}" + pc_REQUIRES "libbson-static-1.0" + ) endif () if (ENABLE_APPLE_FRAMEWORK) @@ -1193,44 +1204,109 @@ set (VERSION "${MONGOC_VERSION}") set (prefix "${CMAKE_INSTALL_PREFIX}") set (libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") -foreach ( - FLAG - ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} - ${THREAD_LIB} ${ZLIB_LIBRARIES} ${SNAPPY_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${ICU_LIBRARIES} +# Collect link items for the static library to be inserted into the pkg-config +if(TARGET mongoc_static) + set(link_options + ${SASL_LIBRARIES} ${SSL_LIBRARIES} ${SHM_LIBRARIES} ${THREAD_LIB} ${ZLIB_LIBRARIES} + ${SNAPPY_LIBRARIES} ${MONGOC_ZSTD_LIBRARIES} ${ICU_LIBRARIES} ${LIBMONGOCRYPT_LIBRARY}) + # Replace all absolute paths with search-dir link-file options: + list(TRANSFORM link_options + REPLACE "^(.+)/lib([^/]+)\\.[a-z]+$" + "-L\\1;-l\\2" + REGEX "^/") + # Prepend "-l" to all bare names: + list(TRANSFORM link_options PREPEND "-l" REGEX "^[^-]") + list(REMOVE_DUPLICATES link_options) + message(DEBUG "Computed static library link options: ${link_options}") + set_property(TARGET mongoc_static APPEND PROPERTY pc_LIBS ${link_options}) +endif() - if (IS_ABSOLUTE "${FLAG}") - get_filename_component (FLAG_DIR "${FLAG}" DIRECTORY) - get_filename_component (FLAG_FILE "${FLAG}" NAME_WE) - STRING (REGEX REPLACE "^lib" "" FLAG_FILE "${FLAG_FILE}") - set (MONGOC_LIBRARIES "${MONGOC_LIBRARIES} -L${FLAG_DIR} -l${FLAG_FILE}") - elseif (FLAG MATCHES "^-.*") - # Flag starts with dash, add it as-is. - set (MONGOC_LIBRARIES "${MONGOC_LIBRARIES} ${FLAG}") - else () - # Flag doesn't start with dash, add it with a dash. - set (MONGOC_LIBRARIES "${MONGOC_LIBRARIES} -l${FLAG}") - endif () -endforeach () +# More pkg-config properties: +set_target_properties(${TARGETS_TO_INSTALL} PROPERTIES + pc_NAME "libmongoc" + pc_DESCRIPTION "The libmongoc MongoDB client library." + pc_VERSION "${VERSION}") +# Relative include-path will be given the install prefix: +set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pc_INCLUDE_DIRECTORIES "${MONGOC_HEADER_INSTALL_DIR}") + +#[[ +Utility for configuring a file and then evaluating generator expressions on it. +The content of the file has a tiny templating DSL for writing generator +expressions. Expansion takes place as follows: + 1. Delete any content starting at hash-tilde "#~" until the next newline + 2. Search for any lines of the form "%define foo bar". For each instance, + replace "foo" with "bar" in the remainder of the file. The "% foo bar" + line is deleted. + 3. If a tilde "~" appears adjacent to any of "$,<:>@", delete the tilde and + all adjacent whitespace. + 4. Run string(CONFIGURE ... @ONLY) on the result to replace variable + references. Special replacements @space@, @newline, and @empty@ are also + available for adjusting whitespace after ~ trimming. + 5. Run file(GENERATE). +]] +function(_mongoc_configure_and_generate_file input output) + set(CMAKE_MESSAGE_CONTEXT _mongoc_configure_and_generate_file) + # If given a relative input path, make it relative to the current source dir: + get_filename_component(abs_in "${input}" ABSOLUTE) + file(READ "${input}" content) + # Some convenience values for @expansion@ in the file: + set(space " ") + set(newline "\n") + set(empty "") + # Delete "#~" comments: + string(REGEX REPLACE "#~[^\n]*" "" content "${content}") + # Replace our simple "%define " macros: + while(content MATCHES "(.*)\n *%define *([a-zA-Z_\\$<>:-]+) *([^\n]*)\n(.*)") + set(before "${CMAKE_MATCH_1}") + set(after "${CMAKE_MATCH_4}") + set(def "${CMAKE_MATCH_2}") + set(val "${CMAKE_MATCH_3}") + message(TRACE "Replace “${def}” with “${val}”") + # Only perform the replacment on the remainder of the file following that + # line: + string(REPLACE "${def}" "${val}" after "${after}") + # Splice the results: + set(content "${before}\n${after}") + endwhile() + # Whitespace trimming. right-trim when tilde is to the right of special chars: + string(REGEX REPLACE "([,><:@])~[ \n\t]*" "\\1" content "${content}") + # Same thing, but on the left-hand side: + string(REGEX REPLACE "[ \n\t]*~([^ \t\n])" "\\1" content "${content}") + # Replace @varables@: + string(CONFIGURE "${content}" content @ONLY) + # If given a relative output path, make it relative to the current binary dir: + if(NOT IS_ABSOLUTE "${output}") + get_filename_component(output "${CMAKE_CURRENT_BINARY_DIR}/${output}" ABSOLUTE) + endif() + message(DEBUG "Configure+generate file [${input}] -> [${output}]") + message(TRACE "Content:\n${content}") + # Generate it: + file(GENERATE OUTPUT "${output}" CONTENT "${content}" ${ARGN}) +endfunction() + +# Generate pkg-config for mongoc_shared +if(TARGET mongoc_shared) + set(GENERATE_TARGET mongoc_shared) + _mongoc_configure_and_generate_file( + src/libmongoc.pc.in + src/libmongoc-1.0.pc) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-1.0.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() + +# Now one for mongoc_static: +if(TARGET mongoc_static) + set(GENERATE_TARGET mongoc_static) + _mongoc_configure_and_generate_file( + src/libmongoc.pc.in + src/libmongoc-static-1.0.pc) + if(MONGOC_ENABLE_STATIC_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-static-1.0.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + endif() +endif() -configure_file ( - ${CMAKE_CURRENT_SOURCE_DIR}/src/libmongoc-1.0.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-1.0.pc -@ONLY) -install ( - FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-1.0.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig -) -if (MONGOC_ENABLE_STATIC_INSTALL) - configure_file ( - ${CMAKE_CURRENT_SOURCE_DIR}/src/libmongoc-static-1.0.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-static-1.0.pc - @ONLY) - install ( - FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmongoc-static-1.0.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig - ) -endif () # Deprecated alias for libmongoc-1.0.pc, see CDRIVER-2086. if (MONGOC_ENABLE_SSL) configure_file ( diff --git a/src/libmongoc/src/CMakeLists.txt b/src/libmongoc/src/CMakeLists.txt index 9fcc323a444..fabfeac41a4 100644 --- a/src/libmongoc/src/CMakeLists.txt +++ b/src/libmongoc/src/CMakeLists.txt @@ -2,9 +2,8 @@ add_subdirectory (mongoc) set_local_dist (src_libmongoc_src_DIST_local CMakeLists.txt - libmongoc-1.0.pc.in + libmongoc.pc.in libmongoc-ssl-1.0.pc.in - libmongoc-static-1.0.pc.in mongoc-config.cmake ) diff --git a/src/libmongoc/src/libmongoc-1.0.pc.in b/src/libmongoc/src/libmongoc-1.0.pc.in deleted file mode 100644 index 1b489d86ce7..00000000000 --- a/src/libmongoc/src/libmongoc-1.0.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=${prefix} -libdir=@libdir@ -includedir=${exec_prefix}/include - -Name: libmongoc -Description: The libmongoc MongoDB client library. -Version: @VERSION@ -Requires: libbson-1.0 -Libs: -L${libdir} -lmongoc-1.0 -Cflags: -I${includedir}/libmongoc-@MONGOC_API_VERSION@ diff --git a/src/libmongoc/src/libmongoc-static-1.0.pc.in b/src/libmongoc/src/libmongoc-static-1.0.pc.in deleted file mode 100644 index d59ee64478e..00000000000 --- a/src/libmongoc/src/libmongoc-static-1.0.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=${prefix} -libdir=@libdir@ -includedir=${exec_prefix}/include - -Name: libmongoc -Description: The libmongoc MongoDB client library. -Version: @VERSION@ -Requires: libbson-static-1.0 -Libs: -L${libdir} -lmongoc-static-1.0 @MONGOC_LIBRARIES@ -Cflags: -I${includedir}/libmongoc-@MONGOC_API_VERSION@ -DMONGOC_STATIC diff --git a/src/libmongoc/src/libmongoc.pc.in b/src/libmongoc/src/libmongoc.pc.in new file mode 100644 index 00000000000..ba84e8e3182 --- /dev/null +++ b/src/libmongoc/src/libmongoc.pc.in @@ -0,0 +1,63 @@ +prefix=@prefix@ +exec_prefix=${prefix} +libdir=@libdir@ +includedir=${exec_prefix}/include + +Name: $ +Description: $ +Version: $ + +%define $ +#~ Conditional: Only expand a first "\nRequires: " if Requires is non-empty: +%define has_requires $<> +~$ +#~ The rest: +~$ + +~@newline@~ + +#~ Link options: +Libs: -L${libdir} -l$ ~@space@~ + #~ Join each "Libs" item with spaces. This could be more robust, but it suites our purposes: + %define libs_prop $ + #~ Remove duplicate items, which will usually be redundant link paths: + %define libs $ + $~ + + #~ Add link options. Don't remove duplicates, because they may be important + %define link_opts $ + $<$<>:@space@$> + +~@newline@~ + +#~ Compile-flags: +%define cflags_prop $ +Cflags: $ ~@space@~ + + #~ Options: + %define opts_prop $ + %define opts $ + $~ + + #~ Preprocessor definitions: + %define defs_prop $ + %define defs $ + $<$<>: -D>~ + $~ + + #~ Inclusions: + %define inc_prop $ + %define incs $ + #~ Absolute path includes are kept absolute: + %define abs_includes $ + $<$<>: -I>~ + $~ + #~ Relative includes are made relative to ${prefix} + %define relative_includes $ + $<$<>: -I${prefix}/>~ + $ From 2c376508db918a6212a16aa1fff83d45af5b9728 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 13 Jun 2023 21:17:12 +0000 Subject: [PATCH 05/13] Tweak method of detecting name resolution --- build/cmake/ResSearch.cmake | 55 +++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/build/cmake/ResSearch.cmake b/build/cmake/ResSearch.cmake index f0632ee3a99..b26dc0fe7a3 100644 --- a/build/cmake/ResSearch.cmake +++ b/build/cmake/ResSearch.cmake @@ -1,4 +1,7 @@ include(CheckSymbolExists) +include(CMakePushCheckState) + +cmake_push_check_state(RESET) # The name of the library that performs name resolution, suitable for giving to the "-l" link flag set(RESOLVE_LIB_NAME) @@ -9,41 +12,37 @@ if(WIN32) set(RESOLVE_LIB_NAME Dnsapi) set(_MONGOC_HAVE_DNSAPI 1) else() - # Thread-safe DNS query function for _mongoc_client_get_srv. - # Could be a macro, not a function, so use check_symbol_exists. - check_symbol_exists(res_nsearch resolv.h _MONGOC_HAVE_RES_NSEARCH) - check_symbol_exists(res_ndestroy resolv.h _MONGOC_HAVE_RES_NDESTROY) - check_symbol_exists(res_nclose resolv.h _MONGOC_HAVE_RES_NCLOSE) - if(MONGOC_HAVE_RES_NSEARCH) - # We have res_nsearch. Call res_ndestroy (BSD/Mac) or res_nclose (Linux)? - set(RESOLVE_LIB_NAME resolv) - 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) + # Try to find the search functions for various configurations. + # Headers required by minimum on the strictest system: (Tested on FreeBSD 13) + set(resolve_headers netinet/in.h sys/types.h arpa/nameser.h resolv.h) + check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_NOLINK) + check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_NOLINK) + check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_NOLINK) + check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_NOLINK) + # Can we use name resolution with just libc? + if((_MONGOC_HAVE_RES_NSEARCH_NOLINK OR _MONGOC_HAVE_RES_SEARCH_NOLINK) + AND (_MONGOC_HAVE_RES_NDESTROY_NOLINK OR _MONGOC_HAVE_RES_NCLOSE_NOLINK)) set(resolve_is_libc TRUE) + message(VERBOSE "Name resolution is provided by the C runtime") else() - # Thread-unsafe function. - check_symbol_exists(res_search resolv.h _MONGOC_HAVE_RES_SEARCH) - if(_MONGOC_HAVE_RES_SEARCH) + # Cannot find it without any links. Try linking in the "resolv" library: + set(CMAKE_REQUIRES_LIBRARIES resolv) + check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_RESOLV) + check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_RESOLV) + check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_RESOLV) + check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_RESOLV) + if((_MONGOC_HAVE_RES_NSEARCH_RESOLV OR _MONGOC_HAVE_RES_SEARCH_RESOLV) + AND (_MONGOC_HAVE_RES_NDESTROY_RESOLV OR _MONGOC_HAVE_RES_NCLOSE_RESOLV)) set(RESOLVE_LIB_NAME resolv) endif() endif() endif() _mongo_pick(MONGOC_HAVE_DNSAPI 1 0 _MONGOC_HAVE_DNSAPI) -_mongo_pick(MONGOC_HAVE_RES_NSEARCH 1 0 _MONGOC_HAVE_RES_NSEARCH) -_mongo_pick(MONGOC_HAVE_RES_NDESTROY 1 0 _MONGOC_HAVE_RES_NDESTROY) -_mongo_pick(MONGOC_HAVE_RES_NCLOSE 1 0 _MONGOC_HAVE_RES_NCLOSE) -_mongo_pick(MONGOC_HAVE_RES_SEARCH 1 0 _MONGOC_HAVE_RES_SEARCH) +_mongo_pick(MONGOC_HAVE_RES_NSEARCH 1 0 [[_MONGOC_HAVE_RES_NSEARCH_NOLINK OR _MONGOC_HAVE_RES_NSEARCH_RESOLV]]) +_mongo_pick(MONGOC_HAVE_RES_SEARCH 1 0 [[_MONGOC_HAVE_RES_SEARCH_NOLINK OR _MONGOC_HAVE_RES_SEARCH_RESOLV]]) +_mongo_pick(MONGOC_HAVE_RES_NDESTROY 1 0 [[_MONGOC_HAVE_RES_NDESTROY_NOLINK OR _MONGOC_HAVE_RES_NDESTROY_RESOLV]]) +_mongo_pick(MONGOC_HAVE_RES_NCLOSE 1 0 [[_MONGOC_HAVE_RES_NCLOSE_NOLINK OR _MONGOC_HAVE_RES_NCLOSE_RESOLV]]) if(RESOLVE_LIB_NAME OR resolve_is_libc) # Define the resolver interface: @@ -54,3 +53,5 @@ if(RESOLVE_LIB_NAME OR resolve_is_libc) EXPORT_NAME detail::c_resolve) install(TARGETS _mongoc-resolve EXPORT mongoc-targets) endif() + +cmake_pop_check_state() From 9e42bfc041f18338bdefb707a6dc29e52e1567b9 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 13 Jun 2023 21:18:04 +0000 Subject: [PATCH 06/13] Rename intermediate interface libs --- src/libmongoc/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index a849056438b..3dec8e56a8a 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -714,9 +714,9 @@ set (STATIC_LIBRARIES ) add_library(_mongoc-dependencies INTERFACE) -add_library(mongo::c::dependencies ALIAS _mongoc-dependencies) +add_library(mongo::detail::c_dependencies ALIAS _mongoc-dependencies) install(TARGETS _mongoc-dependencies EXPORT mongoc-targets) -set_property(TARGET _mongoc-dependencies PROPERTY EXPORT_NAME dependencies) +set_property(TARGET _mongoc-dependencies PROPERTY EXPORT_NAME detail::c_dependencies) if(ENABLE_SRV) # Interface target defined by ResSearch.cmake: @@ -750,7 +750,7 @@ endif () add_library (mongoc_shared SHARED ${SOURCES} ${HEADERS} ${HEADERS_FORWARDING}) set_target_properties (mongoc_shared PROPERTIES CMAKE_CXX_VISIBILITY_PRESET hidden) -target_link_libraries (mongoc_shared PRIVATE ${LIBRARIES} PUBLIC ${BSON_LIBRARIES} mongo::c::dependencies) +target_link_libraries (mongoc_shared PRIVATE ${LIBRARIES} PUBLIC ${BSON_LIBRARIES} mongo::detail::c_dependencies) target_include_directories (mongoc_shared PRIVATE ${ZLIB_INCLUDE_DIRS}) target_include_directories (mongoc_shared PRIVATE ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES}) if(ENABLE_COVERAGE) @@ -799,7 +799,7 @@ if (MONGOC_ENABLE_STATIC_BUILD) target_compile_options(mongoc_static PRIVATE --coverage) target_link_options(mongoc_static PUBLIC --coverage) endif() - target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} ${BSON_STATIC_LIBRARIES} mongo::c::dependencies) + target_link_libraries (mongoc_static PUBLIC ${STATIC_LIBRARIES} ${BSON_STATIC_LIBRARIES} mongo::detail::c_dependencies) if (NOT WIN32 AND ENABLE_PIC) target_compile_options (mongoc_static PUBLIC -fPIC) message (STATUS "Adding -fPIC to compilation of mongoc_static components") From 5ea027bdb42bbfa9ca441bd913241c5065608147 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 13 Jun 2023 21:30:36 +0000 Subject: [PATCH 07/13] Swap resolv search order for with/without a link --- build/cmake/ResSearch.cmake | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/build/cmake/ResSearch.cmake b/build/cmake/ResSearch.cmake index b26dc0fe7a3..e19eb1042a9 100644 --- a/build/cmake/ResSearch.cmake +++ b/build/cmake/ResSearch.cmake @@ -15,25 +15,25 @@ else() # Try to find the search functions for various configurations. # Headers required by minimum on the strictest system: (Tested on FreeBSD 13) set(resolve_headers netinet/in.h sys/types.h arpa/nameser.h resolv.h) - check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_NOLINK) - check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_NOLINK) - check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_NOLINK) - check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_NOLINK) - # Can we use name resolution with just libc? - if((_MONGOC_HAVE_RES_NSEARCH_NOLINK OR _MONGOC_HAVE_RES_SEARCH_NOLINK) - AND (_MONGOC_HAVE_RES_NDESTROY_NOLINK OR _MONGOC_HAVE_RES_NCLOSE_NOLINK)) - set(resolve_is_libc TRUE) - message(VERBOSE "Name resolution is provided by the C runtime") + set(CMAKE_REQUIRES_LIBRARIES resolv) + check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_RESOLV) + check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_RESOLV) + check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_RESOLV) + check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_RESOLV) + if((_MONGOC_HAVE_RES_NSEARCH_RESOLV OR _MONGOC_HAVE_RES_SEARCH_RESOLV) + AND (_MONGOC_HAVE_RES_NDESTROY_RESOLV OR _MONGOC_HAVE_RES_NCLOSE_RESOLV)) + set(RESOLVE_LIB_NAME resolv) else() - # Cannot find it without any links. Try linking in the "resolv" library: - set(CMAKE_REQUIRES_LIBRARIES resolv) - check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_RESOLV) - check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_RESOLV) - check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_RESOLV) - check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_RESOLV) - if((_MONGOC_HAVE_RES_NSEARCH_RESOLV OR _MONGOC_HAVE_RES_SEARCH_RESOLV) - AND (_MONGOC_HAVE_RES_NDESTROY_RESOLV OR _MONGOC_HAVE_RES_NCLOSE_RESOLV)) - set(RESOLVE_LIB_NAME resolv) + # Can we use name resolution with just libc? + unset(CMAKE_REQUIRES_LIBRARIES) + check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_NOLINK) + check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_NOLINK) + check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_NOLINK) + check_symbol_exists(res_nclose "${resolve_headers}" _MONGOC_HAVE_RES_NCLOSE_NOLINK) + if((_MONGOC_HAVE_RES_NSEARCH_NOLINK OR _MONGOC_HAVE_RES_SEARCH_NOLINK) + AND (_MONGOC_HAVE_RES_NDESTROY_NOLINK OR _MONGOC_HAVE_RES_NCLOSE_NOLINK)) + set(resolve_is_libc TRUE) + message(VERBOSE "Name resolution is provided by the C runtime") endif() endif() endif() From db385dc5a0754db338c8fea3230a034fef6a22fc Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 13 Jun 2023 21:42:58 +0000 Subject: [PATCH 08/13] Sppeling --- build/cmake/ResSearch.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/cmake/ResSearch.cmake b/build/cmake/ResSearch.cmake index e19eb1042a9..d82466cd5b3 100644 --- a/build/cmake/ResSearch.cmake +++ b/build/cmake/ResSearch.cmake @@ -15,7 +15,7 @@ else() # Try to find the search functions for various configurations. # Headers required by minimum on the strictest system: (Tested on FreeBSD 13) set(resolve_headers netinet/in.h sys/types.h arpa/nameser.h resolv.h) - set(CMAKE_REQUIRES_LIBRARIES resolv) + set(CMAKE_REQUIRED_LIBRARIES resolv) check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_RESOLV) check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_RESOLV) check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_RESOLV) @@ -25,7 +25,7 @@ else() set(RESOLVE_LIB_NAME resolv) else() # Can we use name resolution with just libc? - unset(CMAKE_REQUIRES_LIBRARIES) + unset(CMAKE_REQUIRED_LIBRARIES) check_symbol_exists(res_nsearch "${resolve_headers}" _MONGOC_HAVE_RES_NSEARCH_NOLINK) check_symbol_exists(res_search "${resolve_headers}" _MONGOC_HAVE_RES_SEARCH_NOLINK) check_symbol_exists(res_ndestroy "${resolve_headers}" _MONGOC_HAVE_RES_NDESTROY_NOLINK) From db2d4031dbb6dec247c0b68d874ce539a414628b Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 15 Jun 2023 13:10:15 -0600 Subject: [PATCH 09/13] Spelling and tpyos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roberto C. Sánchez --- src/libmongoc/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 3dec8e56a8a..361525b8e4d 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -1236,12 +1236,12 @@ The content of the file has a tiny templating DSL for writing generator expressions. Expansion takes place as follows: 1. Delete any content starting at hash-tilde "#~" until the next newline 2. Search for any lines of the form "%define foo bar". For each instance, - replace "foo" with "bar" in the remainder of the file. The "% foo bar" + replace "foo" with "bar" in the remainder of the file. The "%define foo bar" line is deleted. 3. If a tilde "~" appears adjacent to any of "$,<:>@", delete the tilde and all adjacent whitespace. 4. Run string(CONFIGURE ... @ONLY) on the result to replace variable - references. Special replacements @space@, @newline, and @empty@ are also + references. Special replacements @space@, @newline@, and @empty@ are also available for adjusting whitespace after ~ trimming. 5. Run file(GENERATE). ]] @@ -1263,7 +1263,7 @@ function(_mongoc_configure_and_generate_file input output) set(def "${CMAKE_MATCH_2}") set(val "${CMAKE_MATCH_3}") message(TRACE "Replace “${def}” with “${val}”") - # Only perform the replacment on the remainder of the file following that + # Only perform the replacement on the remainder of the file following that # line: string(REPLACE "${def}" "${val}" after "${after}") # Splice the results: @@ -1273,7 +1273,7 @@ function(_mongoc_configure_and_generate_file input output) string(REGEX REPLACE "([,><:@])~[ \n\t]*" "\\1" content "${content}") # Same thing, but on the left-hand side: string(REGEX REPLACE "[ \n\t]*~([^ \t\n])" "\\1" content "${content}") - # Replace @varables@: + # Replace @variables@: string(CONFIGURE "${content}" content @ONLY) # If given a relative output path, make it relative to the current binary dir: if(NOT IS_ABSOLUTE "${output}") From bb3d49d9d64c227d7f7143ec578a8d51dd8d8863 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 15 Jun 2023 13:10:53 -0600 Subject: [PATCH 10/13] Another one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roberto C. Sánchez --- src/libmongoc/src/libmongoc.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmongoc/src/libmongoc.pc.in b/src/libmongoc/src/libmongoc.pc.in index ba84e8e3182..fbb570d0c00 100644 --- a/src/libmongoc/src/libmongoc.pc.in +++ b/src/libmongoc/src/libmongoc.pc.in @@ -23,7 +23,7 @@ Version: $ #~ Link options: Libs: -L${libdir} -l$ ~@space@~ - #~ Join each "Libs" item with spaces. This could be more robust, but it suites our purposes: + #~ Join each "Libs" item with spaces. This could be more robust, but it suits our purposes: %define libs_prop $ #~ Remove duplicate items, which will usually be redundant link paths: %define libs $ From 416e5f9a9c3b150323b5f1507b9b98795442f424 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 15 Jun 2023 15:07:10 -0600 Subject: [PATCH 11/13] PR cleanup and feedback --- CMakeLists.txt | 2 +- src/libmongoc/CMakeLists.txt | 21 +++++++++++---------- src/libmongoc/src/libmongoc.pc.in | 14 +++++++------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a9da60b1e1..cc1f69fc9ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,9 +71,9 @@ mongo_bool_setting(ENABLE_EXAMPLES "Build MongoDB C Driver examples") mongo_bool_setting(ENABLE_MAN_PAGES "Build the manual pages" DEFAULT VALUE OFF) mongo_bool_setting(ENABLE_HTML_DOCS "Build the HTML documentation" DEFAULT VALUE OFF) mongo_bool_setting(ENABLE_UNINSTALL "Generate an 'uninstall' script and an 'uninstall' build target") +mongo_bool_setting(ENABLE_SRV "Enable support for mongodb+srv URIs.") # Optional features that are ENABLED when necessary dependencies are found: -mongo_bool_setting(ENABLE_SRV "Enable support for mongodb+srv URIs.") mongo_setting(ENABLE_SNAPPY "Enable Snappy compression support" OPTIONS ON OFF AUTO DEFAULT VALUE AUTO) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 361525b8e4d..c8d0c89a1a5 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -29,6 +29,9 @@ set (MONGOC_ENABLE_COMPRESSION_SNAPPY 0) set (MONGOC_ENABLE_COMPRESSION_ZLIB 0) set (MONGOC_ENABLE_COMPRESSION_ZSTD 0) +# Definition for mongoc-config.h: +_mongo_pick(MONGOC_ENABLE_SRV 1 0 ENABLE_SRV) + set (MONGOC_OUTPUT_BASENAME "mongoc" CACHE STRING "Output mongoc library base name") if (NOT ENABLE_ZLIB MATCHES "SYSTEM|AUTO|BUNDLED|OFF") @@ -290,8 +293,6 @@ endif () # Find name resolution libaries. Also sets definitions used in configure_file(): include(ResSearch) -# Definition for mongoc-config.h: -_mongo_pick(MONGOC_ENABLE_SRV 1 0 ENABLE_SRV) include (CheckSchedGetCPU) @@ -790,7 +791,7 @@ set_target_properties (mongoc_shared PROPERTIES OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-${MONGOC_API_VERSION}" VERSION 0.0.0 SOVERSION 0 - pc_REQUIRES "libbson-1.0" + pkg_config_REQUIRES "libbson-1.0" ) if (MONGOC_ENABLE_STATIC_BUILD) @@ -806,7 +807,7 @@ if (MONGOC_ENABLE_STATIC_BUILD) endif () if(ENABLE_SRV AND RESOLVE_LIB_NAME) # The static library needs to link to the resolver in pkg-config: - set_property(TARGET mongoc_static APPEND PROPERTY pc_LIBS "-l${RESOLVE_LIB_NAME}") + set_property(TARGET mongoc_static APPEND PROPERTY pkg_config_LIBS "-l${RESOLVE_LIB_NAME}") endif() target_include_directories (mongoc_static PRIVATE ${ZLIB_INCLUDE_DIRS}) target_include_directories (mongoc_static PRIVATE ${LIBMONGOCRYPT_INCLUDE_DIRECTORIES}) @@ -838,7 +839,7 @@ if (MONGOC_ENABLE_STATIC_BUILD) set_target_properties (mongoc_static PROPERTIES VERSION 0.0.0 OUTPUT_NAME "${MONGOC_OUTPUT_BASENAME}-static-${MONGOC_API_VERSION}" - pc_REQUIRES "libbson-static-1.0" + pkg_config_REQUIRES "libbson-static-1.0" ) endif () @@ -1219,16 +1220,16 @@ if(TARGET mongoc_static) list(TRANSFORM link_options PREPEND "-l" REGEX "^[^-]") list(REMOVE_DUPLICATES link_options) message(DEBUG "Computed static library link options: ${link_options}") - set_property(TARGET mongoc_static APPEND PROPERTY pc_LIBS ${link_options}) + set_property(TARGET mongoc_static APPEND PROPERTY pkg_config_LIBS ${link_options}) endif() # More pkg-config properties: set_target_properties(${TARGETS_TO_INSTALL} PROPERTIES - pc_NAME "libmongoc" - pc_DESCRIPTION "The libmongoc MongoDB client library." - pc_VERSION "${VERSION}") + pkg_config_NAME "libmongoc" + pkg_config_DESCRIPTION "The libmongoc MongoDB client library." + pkg_config_VERSION "${VERSION}") # Relative include-path will be given the install prefix: -set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pc_INCLUDE_DIRECTORIES "${MONGOC_HEADER_INSTALL_DIR}") +set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${MONGOC_HEADER_INSTALL_DIR}") #[[ Utility for configuring a file and then evaluating generator expressions on it. diff --git a/src/libmongoc/src/libmongoc.pc.in b/src/libmongoc/src/libmongoc.pc.in index fbb570d0c00..72ecb2bb345 100644 --- a/src/libmongoc/src/libmongoc.pc.in +++ b/src/libmongoc/src/libmongoc.pc.in @@ -3,16 +3,16 @@ exec_prefix=${prefix} libdir=@libdir@ includedir=${exec_prefix}/include -Name: $ -Description: $ -Version: $ +Name: $ +Description: $ +Version: $ %define $ +%define requires_prop $ #~ Conditional: Only expand a first "\nRequires: " if Requires is non-empty: %define has_requires $<> ~$ @@ -24,7 +24,7 @@ Version: $ #~ Link options: Libs: -L${libdir} -l$ ~@space@~ #~ Join each "Libs" item with spaces. This could be more robust, but it suits our purposes: - %define libs_prop $ + %define libs_prop $ #~ Remove duplicate items, which will usually be redundant link paths: %define libs $ $~ @@ -36,7 +36,7 @@ Libs: -L${libdir} -l$ ~@space@~ ~@newline@~ #~ Compile-flags: -%define cflags_prop $ +%define cflags_prop $ Cflags: $ ~@space@~ #~ Options: @@ -51,7 +51,7 @@ Cflags: $ ~@space@~ $~ #~ Inclusions: - %define inc_prop $ + %define inc_prop $ %define incs $ #~ Absolute path includes are kept absolute: %define abs_includes $ From 52b881e66b881ca3a51640f7a02cb67a9ea1ffe8 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Thu, 15 Jun 2023 18:36:04 -0600 Subject: [PATCH 12/13] Regex tweak --- src/libmongoc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index c8d0c89a1a5..24119c3697d 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -1258,7 +1258,7 @@ function(_mongoc_configure_and_generate_file input output) # Delete "#~" comments: string(REGEX REPLACE "#~[^\n]*" "" content "${content}") # Replace our simple "%define " macros: - while(content MATCHES "(.*)\n *%define *([a-zA-Z_\\$<>:-]+) *([^\n]*)\n(.*)") + while(content MATCHES "(.*)\n *%define +([a-zA-Z_\\$<>:-]+) *([^\n]*)\n(.*)") set(before "${CMAKE_MATCH_1}") set(after "${CMAKE_MATCH_4}") set(def "${CMAKE_MATCH_2}") From d997d8281d516d6abbcebaf8ac7a67d6f36a9859 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 20 Jun 2023 14:41:13 -0600 Subject: [PATCH 13/13] Tweak .pc generation --- src/libmongoc/CMakeLists.txt | 2 +- src/libmongoc/src/libmongoc.pc.in | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 24119c3697d..698f1d827a1 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -1213,7 +1213,7 @@ if(TARGET mongoc_static) ${LIBMONGOCRYPT_LIBRARY}) # Replace all absolute paths with search-dir link-file options: list(TRANSFORM link_options - REPLACE "^(.+)/lib([^/]+)\\.[a-z]+$" + REPLACE "^(.+)/lib([^/\\.]+)\\..+$" "-L\\1;-l\\2" REGEX "^/") # Prepend "-l" to all bare names: diff --git a/src/libmongoc/src/libmongoc.pc.in b/src/libmongoc/src/libmongoc.pc.in index 72ecb2bb345..d4db5b61b76 100644 --- a/src/libmongoc/src/libmongoc.pc.in +++ b/src/libmongoc/src/libmongoc.pc.in @@ -1,7 +1,6 @@ prefix=@prefix@ exec_prefix=${prefix} libdir=@libdir@ -includedir=${exec_prefix}/include Name: $ Description: $