]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: add support for `CURL_USE_LIBUV` option
authorViktor Szakats <commit@vsz.me>
Mon, 5 Aug 2024 16:44:37 +0000 (18:44 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 6 Aug 2024 00:40:16 +0000 (02:40 +0200)
Also use an `#undef` hack for CMake Unity builds to avoid the previously
included `memdebug.h` header messing up the declarations pulled in by
`uv.h`:
```
In file included from ~/curl/bld/src/CMakeFiles/curl.dir/Unity/unity_0_c.c:88:
In file included from ~/curl/src/tool_operate.c:54:
In file included from /usr/local/Cellar/libuv/1.48.0/include/uv.h:71:
In file included from /usr/local/Cellar/libuv/1.48.0/include/uv/unix.h:34:
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/netdb.h:269:7: error: expected parameter declarator
void            freeaddrinfo(struct addrinfo *);
                ^
~/curl/lib/memdebug.h:167:31: note: expanded from macro 'freeaddrinfo'
  curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
                              ^
```

Follow-up to 38d334e3e17f16107921299a6d7b6654f6ec553b #14298
Closes #14399

CMakeLists.txt
lib/curl_config.h.cmake
src/tool_operate.c

index 0058b52570059f1c02c7d340fb7515c011e92662..75317c917b76b3ef171ab17882f8c990a5b16e8a 100644 (file)
@@ -1083,6 +1083,23 @@ if(CURL_USE_GSSAPI)
   endif()
 endif()
 
+# libuv
+option(CURL_USE_LIBUV "Use libuv for event-based tests" OFF)
+if(CURL_USE_LIBUV)
+  if(NOT ENABLE_DEBUG)
+    message(FATAL_ERROR "Using libuv without debug support enabled is useless")
+  endif()
+  find_package(PkgConfig QUIET)
+  pkg_check_modules(LIBUV "libuv")
+  if(LIBUV_FOUND)
+    list(APPEND CURL_LIBS ${LIBUV_LINK_LIBRARIES})
+    list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libuv")
+    include_directories(${LIBUV_INCLUDE_DIRS})
+    set(USE_LIBUV ON)
+    set(HAVE_UV_H ON)
+  endif()
+endif()
+
 option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
 if(USE_LIBRTMP)
   cmake_push_check_state()
index 666a7bae4662c23fef219eea9a93d891368bd659..bff17bc493aba54f4359e8bc33bbe8e5bb7a38ab 100644 (file)
@@ -722,6 +722,12 @@ ${SIZEOF_TIME_T_CODE}
 /* if GSASL is in use */
 #cmakedefine USE_GSASL 1
 
+/* if libuv is in use */
+#cmakedefine USE_LIBUV 1
+
+/* Define to 1 if you have the <uv.h> header file. */
+#cmakedefine HAVE_UV_H 1
+
 /* Define to 1 if you do not want the OpenSSL configuration to be loaded
    automatically */
 #cmakedefine CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG 1
index 48cc6db63361258b34b84ecd2ebe6ae72479d3a2..c3bd3f37431f9923da60ad9f4e7602ea13fd1f4f 100644 (file)
 #endif
 
 #ifdef HAVE_UV_H
+/* Hack for Unity mode */
+#ifdef HEADER_CURL_MEMDEBUG_H
+#undef HEADER_CURL_MEMDEBUG_H
+#undef freeaddrinfo
+#undef getaddrinfo
+#endif
 /* this is for libuv-enabled debug builds only */
 #include <uv.h>
 #endif