summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAmir Masoud Abdol <amir.abdol@qt.io>2023-03-01 15:41:14 +0100
committerThiago Macieira <thiago.macieira@intel.com>2023-05-11 17:05:25 -0700
commit68b625901f9eb7c34e3d7aa302e1c0a454d3190b (patch)
tree36faae7f3c3b7d573a82e08390c7f8c03900408e /cmake
parentff9da1db0b0963f967f45ab430ec40a3051b70b4 (diff)
Network: link directly to libresolv instead of dlopen()ing it
There's little need for us to dynamically load it. The reasons why that was necessary aren't in the public history (Qt 4.5 already had it[1]). I remember writing the code in 2007-2008, I just don't remember why. On modern Linux and FreeBSD, there's no libresolv.so any more and those symbols have been rolled up into libc.so. It's still necessary on Darwin systems, so this commit introduces WrapResolv. It also resolves the unity build issues relating to libresolv symbols. [1] https://code.qt.io/cgit/qt/qt.git/tree/src/network/kernel/qhostinfo_unix.cpp?h=v4.5.1 Task-number: QTBUG-109394 Change-Id: Ic5799e4d000b6c9395109e008780643bac52122b Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindWrapResolv.cmake49
1 files changed, 49 insertions, 0 deletions
diff --git a/cmake/FindWrapResolv.cmake b/cmake/FindWrapResolv.cmake
new file mode 100644
index 0000000000..9720c96c00
--- /dev/null
+++ b/cmake/FindWrapResolv.cmake
@@ -0,0 +1,49 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 Intel Corpotation.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# We can't create the same interface imported target multiple times, CMake will complain if we do
+# that. This can happen if the find_package call is done in multiple different subdirectories.
+if(TARGET WrapResolv::WrapResolv)
+ set(WrapResolv_FOUND ON)
+ return()
+endif()
+
+set(WrapResolv_FOUND OFF)
+
+include(CheckCXXSourceCompiles)
+include(CMakePushCheckState)
+
+if(QNX)
+ find_library(LIBRESOLV socket)
+else()
+ find_library(LIBRESOLV resolv)
+endif()
+
+cmake_push_check_state()
+if(LIBRESOLV)
+ list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBRESOLV}")
+endif()
+
+check_cxx_source_compiles("
+#include <netinet/in.h>
+#include <resolv.h>
+
+int main(int, char **)
+{
+ res_init();
+}
+" HAVE_RES_INIT)
+
+cmake_pop_check_state()
+
+if(HAVE_RES_INIT)
+ set(WrapResolv_FOUND ON)
+ add_library(WrapResolv::WrapResolv INTERFACE IMPORTED)
+ if(LIBRESOLV)
+ target_link_libraries(WrapResolv::WrapResolv INTERFACE "${LIBRESOLV}")
+ endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(WrapResolv DEFAULT_MSG WrapResolv_FOUND)