1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckFunctionExists)
4 include(CheckLibraryExists)
6 include(CheckStructHasMember)
7 include(CheckPrototypeDefinition)
10 set(PACKAGE ${PROJECT_NAME})
11 set(VERSION ${PROJECT_VERSION})
12 set(DATADIR ${DATA_INSTALL_DIR})
13 set(LIBDIR ${LIB_INSTALL_DIR})
14 set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
15 set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
17 set(BINARYDIR ${resolv_wrapper_BINARY_DIR})
18 set(SOURCEDIR ${resolv_wrapper_SOURCE_DIR})
20 function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
21 # Remove whitespaces from the argument.
22 # This is needed for CC="ccache gcc" cmake ..
23 string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
27 ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
28 OUTPUT_VARIABLE _COMPILER_VERSION
31 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
32 _COMPILER_VERSION "${_COMPILER_VERSION}")
34 set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
37 if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
38 compiler_dumpversion(GNUCC_VERSION)
39 if (NOT GNUCC_VERSION EQUAL 34)
40 set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden")
41 check_c_source_compiles(
42 "void __attribute__((visibility(\"default\"))) test() {}
43 int main(void){ return 0; }
44 " WITH_VISIBILITY_HIDDEN)
45 unset(CMAKE_REQUIRED_FLAGS)
46 endif (NOT GNUCC_VERSION EQUAL 34)
47 endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
50 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
51 check_include_file(resolv.h HAVE_RESOLV_H)
52 check_include_file(arpa/nameser.h HAVE_ARPA_NAMESER_H)
55 find_library(RESOLV_LIRBRARY resolv)
57 set(HAVE_LIBRESOLV TRUE)
59 # If we have a libresolv, we need to check functions linking the library
60 list(APPEND _REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
62 message(STATUS "libresolv not found on ${CMAKE_SYSTEM_NAME}: Only dns faking will be available")
65 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
66 check_function_exists(res_send HAVE_RES_SEND)
67 check_function_exists(__res_send HAVE___RES_SEND)
68 unset(CMAKE_REQUIRED_LIBRARIES)
70 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
71 check_function_exists(res_init HAVE_RES_INIT)
72 check_function_exists(__res_init HAVE___RES_INIT)
73 unset(CMAKE_REQUIRED_LIBRARIES)
75 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
76 check_function_exists(res_ninit HAVE_RES_NINIT)
77 check_function_exists(__res_ninit HAVE___RES_NINIT)
78 unset(CMAKE_REQUIRED_LIBRARIES)
80 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
81 check_function_exists(res_close HAVE_RES_CLOSE)
82 check_function_exists(__res_close HAVE___RES_CLOSE)
83 unset(CMAKE_REQUIRED_LIBRARIES)
85 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
86 check_function_exists(res_nclose HAVE_RES_NCLOSE)
87 check_function_exists(__res_nclose HAVE___RES_NCLOSE)
88 unset(CMAKE_REQUIRED_LIBRARIES)
90 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
91 check_function_exists(res_query HAVE_RES_QUERY)
92 check_function_exists(__res_query HAVE___RES_QUERY)
93 unset(CMAKE_REQUIRED_LIBRARIES)
95 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
96 check_function_exists(res_nquery HAVE_RES_NQUERY)
97 check_function_exists(__res_nquery HAVE___RES_NQUERY)
98 unset(CMAKE_REQUIRED_LIBRARIES)
100 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
101 check_function_exists(res_search HAVE_RES_SEARCH)
102 check_function_exists(__res_search HAVE___RES_SEARCH)
103 unset(CMAKE_REQUIRED_LIBRARIES)
105 set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
106 check_function_exists(res_nsearch HAVE_RES_NSEARCH)
107 check_function_exists(__res_nsearch HAVE___RES_NSEARCH)
108 unset(CMAKE_REQUIRED_LIBRARIES)
110 check_symbol_exists(ns_name_compress "sys/types.h;arpa/nameser.h" HAVE_NS_NAME_COMPRESS)
114 # libsocket (Solaris)
115 find_library(SOCKET_LIBRARY socket)
117 check_library_exists(${SOCKET_LIBRARY} getaddrinfo "" HAVE_LIBSOCKET)
119 list(APPEND _REQUIRED_LIBRARIES ${SOCKET_LIBRARY})
123 # libnsl/inet_pton (Solaris)
124 find_library(NSL_LIBRARY nsl)
126 check_library_exists(${NSL_LIBRARY} inet_pton "" HAVE_LIBNSL)
128 list(APPEND _REQUIRED_LIBRARIES ${NSL_LIBRARY})
133 check_function_exists(getaddrinfo HAVE_GETADDRINFO)
136 find_library(DLFCN_LIBRARY dl)
138 list(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY})
140 check_function_exists(dlopen HAVE_DLOPEN)
142 message(FATAL_ERROR "FATAL: No dlopen() function detected")
147 check_c_source_compiles("
149 #include <sys/socket.h>
151 #include <netinet/in.h>
155 struct sockaddr_storage sa_store;
156 struct addrinfo *ai = NULL;
157 struct in6_addr in6addr;
158 int idx = if_nametoindex(\"iface1\");
159 int s = socket(AF_INET6, SOCK_STREAM, 0);
160 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
162 const char *es = gai_strerror(ret);
168 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
169 #define IPV6_V6ONLY 26
171 ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
172 (const void *)&val, sizeof(val));
178 check_struct_has_member("struct __res_state" _u._ext.nsaddrs resolv.h HAVE_RESOLV_IPV6_NSADDRS)
180 check_c_source_compiles("
181 void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
185 }" HAVE_ATTRIBUTE_PRINTF_FORMAT)
187 check_c_source_compiles("
188 void test_destructor_attribute(void) __attribute__ ((destructor));
190 void test_destructor_attribute(void)
197 }" HAVE_DESTRUCTOR_ATTRIBUTE)
200 test_big_endian(WORDS_BIGENDIAN)
202 set(RWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "resolv_wrapper required system libraries")