1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckFunctionExists)
4 include(CheckLibraryExists)
6 include(CheckStructHasMember)
7 include(CheckPrototypeDefinition)
10 set(BINARYDIR ${resolv_wrapper_BINARY_DIR})
11 set(SOURCEDIR ${resolv_wrapper_SOURCE_DIR})
13 function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
14 # Remove whitespaces from the argument.
15 # This is needed for CC="ccache gcc" cmake ..
16 string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
20 ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
21 OUTPUT_VARIABLE _COMPILER_VERSION
24 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
25 _COMPILER_VERSION "${_COMPILER_VERSION}")
27 set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
30 if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
31 compiler_dumpversion(GNUCC_VERSION)
32 if (NOT GNUCC_VERSION EQUAL 34)
33 set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden")
34 check_c_source_compiles(
35 "void __attribute__((visibility(\"default\"))) test() {}
36 int main(void){ return 0; }
37 " WITH_VISIBILITY_HIDDEN)
38 unset(CMAKE_REQUIRED_FLAGS)
39 endif (NOT GNUCC_VERSION EQUAL 34)
40 endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
43 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
44 check_include_file(resolv.h HAVE_RESOLV_H)
45 check_include_file(arpa/nameser.h HAVE_ARPA_NAMESER_H)
48 find_library(RESOLV_LIRBRARY resolv)
50 set(HAVE_LIBRESOLV TRUE)
52 # If we have a libresolv, we need to check functions linking the library
53 list(APPEND _REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
55 message(STATUS "libresolv not found on ${CMAKE_SYSTEM_NAME}: Only dns faking will be available")
58 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
59 check_function_exists(res_send HAVE_RES_SEND)
60 check_function_exists(__res_send HAVE___RES_SEND)
61 unset(CMAKE_REQUIRED_LIBRARIES)
63 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
64 check_function_exists(res_init HAVE_RES_INIT)
65 check_function_exists(__res_init HAVE___RES_INIT)
66 unset(CMAKE_REQUIRED_LIBRARIES)
68 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
69 check_function_exists(res_ninit HAVE_RES_NINIT)
70 check_function_exists(__res_ninit HAVE___RES_NINIT)
71 unset(CMAKE_REQUIRED_LIBRARIES)
73 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
74 check_function_exists(res_close HAVE_RES_CLOSE)
75 check_function_exists(__res_close HAVE___RES_CLOSE)
76 unset(CMAKE_REQUIRED_LIBRARIES)
78 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
79 check_function_exists(res_nclose HAVE_RES_NCLOSE)
80 check_function_exists(__res_nclose HAVE___RES_NCLOSE)
81 unset(CMAKE_REQUIRED_LIBRARIES)
83 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
84 check_function_exists(res_query HAVE_RES_QUERY)
85 check_function_exists(__res_query HAVE___RES_QUERY)
86 unset(CMAKE_REQUIRED_LIBRARIES)
88 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
89 check_function_exists(res_nquery HAVE_RES_NQUERY)
90 check_function_exists(__res_nquery HAVE___RES_NQUERY)
91 unset(CMAKE_REQUIRED_LIBRARIES)
93 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
94 check_function_exists(res_search HAVE_RES_SEARCH)
95 check_function_exists(__res_search HAVE___RES_SEARCH)
96 unset(CMAKE_REQUIRED_LIBRARIES)
98 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
99 check_function_exists(res_nsearch HAVE_RES_NSEARCH)
100 check_function_exists(__res_nsearch HAVE___RES_NSEARCH)
101 unset(CMAKE_REQUIRED_LIBRARIES)
103 check_symbol_exists(ns_name_compress "sys/types.h;arpa/nameser.h" HAVE_NS_NAME_COMPRESS)
107 # libsocket (Solaris)
108 find_library(SOCKET_LIBRARY socket)
110 check_library_exists(${SOCKET_LIBRARY} getaddrinfo "" HAVE_LIBSOCKET)
112 list(APPEND _REQUIRED_LIBRARIES ${SOCKET_LIBRARY})
116 # libnsl/inet_pton (Solaris)
117 find_library(NSL_LIBRARY nsl)
119 check_library_exists(${NSL_LIBRARY} inet_pton "" HAVE_LIBNSL)
121 list(APPEND _REQUIRED_LIBRARIES ${NSL_LIBRARY})
126 check_function_exists(getaddrinfo HAVE_GETADDRINFO)
129 find_library(DLFCN_LIBRARY dl)
131 list(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY})
133 check_function_exists(dlopen HAVE_DLOPEN)
135 message(FATAL_ERROR "FATAL: No dlopen() function detected")
140 check_c_source_compiles("
142 #include <sys/socket.h>
144 #include <netinet/in.h>
148 struct sockaddr_storage sa_store;
149 struct addrinfo *ai = NULL;
150 struct in6_addr in6addr;
151 int idx = if_nametoindex(\"iface1\");
152 int s = socket(AF_INET6, SOCK_STREAM, 0);
153 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
155 const char *es = gai_strerror(ret);
161 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
162 #define IPV6_V6ONLY 26
164 ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
165 (const void *)&val, sizeof(val));
171 check_struct_has_member("struct __res_state" _u._ext.nsaddrs resolv.h HAVE_RESOLV_IPV6_NSADDRS)
173 check_c_source_compiles("
174 void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
178 }" HAVE_ATTRIBUTE_PRINTF_FORMAT)
180 check_c_source_compiles("
181 void test_destructor_attribute(void) __attribute__ ((destructor));
183 void test_destructor_attribute(void)
190 }" HAVE_DESTRUCTOR_ATTRIBUTE)
193 test_big_endian(WORDS_BIGENDIAN)
195 set(RWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "resolv_wrapper required system libraries")