qt5base-lts/cmake/FindWrapResolv.cmake
Samuli Piippo 4a46ba1209 network: fix link issue with older libc
Amend 68b625901f and fix link issue with
slightly less modern libc/libresolv where not all functions have been
moved over to libc.

ld: src/network/CMakeFiles/Network.dir/kernel/qdnslookup_unix.cpp.o: in function `QDnsLookupRunnable::query(QDnsLookupReply*)':
qdnslookup_unix.cpp:(.text+0x183): undefined reference to `__res_nquery'
ld: qdnslookup_unix.cpp:(.text+0x437): undefined reference to `__dn_expand'
ld: qdnslookup_unix.cpp:(.text+0x621): undefined reference to `__dn_expand'
ld: qdnslookup_unix.cpp:(.text+0x8ff): undefined reference to `__res_nquery'
ld: qdnslookup_unix.cpp:(.text+0xbd7): undefined reference to `__dn_expand'
ld: qdnslookup_unix.cpp:(.text+0xd7f): undefined reference to `__dn_expand'
ld: qdnslookup_unix.cpp:(.text+0xf4f): undefined reference to `__dn_expand'
ld: qdnslookup_unix.cpp:(.text+0x10fa): undefined reference to `__dn_expand'
ld: qdnslookup_unix.cpp:(.text+0x131c): undefined reference to `__dn_expand'
collect2: error: ld returned 1 exit status

Change-Id: If81b292222c78d828b9fef61f30a62f1d584c183
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-26 06:46:30 -07:00

54 lines
1.4 KiB
CMake

# 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 **argv)
{
res_state statep;
int n = res_nmkquery(statep, 0, argv[1], 0, 0, NULL, 0, NULL, NULL, 0);
n = res_nsend(statep, NULL, 0, NULL, 0);
n = dn_expand(NULL, NULL, NULL, NULL, 0);
return n;
}
" HAVE_LIBRESOLV_FUNCTIONS)
cmake_pop_check_state()
if(HAVE_LIBRESOLV_FUNCTIONS)
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)