Add support for the PTR DNS Resource Record type
[obnox/cwrap/resolv_wrapper.git] / ConfigureChecks.cmake
1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckFunctionExists)
4 include(CheckLibraryExists)
5 include(CheckTypeSize)
6 include(CheckStructHasMember)
7 include(CheckPrototypeDefinition)
8 include(TestBigEndian)
9
10 set(PACKAGE ${APPLICATION_NAME})
11 set(VERSION ${APPLICATION_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})
16
17 set(BINARYDIR ${CMAKE_BINARY_DIR})
18 set(SOURCEDIR ${CMAKE_SOURCE_DIR})
19
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}")
24
25     execute_process(
26         COMMAND
27             ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
28         OUTPUT_VARIABLE _COMPILER_VERSION
29     )
30
31     string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
32            _COMPILER_VERSION "${_COMPILER_VERSION}")
33
34     set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
35 endfunction()
36
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         set(CMAKE_REQUIRED_FLAGS "")
46     endif (NOT GNUCC_VERSION EQUAL 34)
47 endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
48
49 # HEADERS
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)
53
54 # FUNCTIONS
55 set(CMAKE_REQUIRED_LIBRARIES)
56
57 find_library(RESOLV_LIRBRARY resolv)
58
59 if (RESOLV_LIRBRARY)
60     check_library_exists(${RESOLV_LIRBRARY} res_send "" RES_SEND_IN_LIBRESOLV)
61     check_library_exists(${RESOLV_LIRBRARY} __res_send "" __RES_SEND_IN_LIBRESOLV)
62     if (RES_SEND_IN_LIBRESOLV OR __RES_SEND_IN_LIBRESOLV)
63         set(HAVE_LIBRESOLV TRUE)
64         set(CMAKE_REQUIRED_LIBRARIES ${RESOLV_LIRBRARY})
65     endif()
66 endif()
67
68 check_function_exists(res_init HAVE_RES_INIT)
69 check_function_exists(__res_init HAVE___RES_INIT)
70
71 check_function_exists(res_ninit HAVE_RES_NINIT)
72 check_function_exists(__res_ninit HAVE___RES_NINIT)
73 if (RESOLV_LIRBRARY)
74     check_library_exists(${RESOLV_LIRBRARY} res_ninit "" HAVE_RES_NINIT_IN_LIBRESOLV)
75 endif()
76
77 check_function_exists(res_close HAVE_RES_CLOSE)
78 check_function_exists(__res_close HAVE___RES_CLOSE)
79
80 check_function_exists(res_nclose HAVE_RES_NCLOSE)
81 check_function_exists(__res_nclose HAVE___RES_NCLOSE)
82 if (RESOLV_LIRBRARY)
83     check_library_exists(${RESOLV_LIRBRARY} res_nclose "" HAVE_RES_NCLOSE_IN_LIBRESOLV)
84 endif()
85
86 check_function_exists(res_query HAVE_RES_QUERY)
87 check_function_exists(__res_query HAVE___RES_QUERY)
88
89 check_function_exists(res_nquery HAVE_RES_NQUERY)
90 check_function_exists(__res_nquery HAVE___RES_NQUERY)
91
92 check_function_exists(res_search HAVE_RES_SEARCH)
93 check_function_exists(__res_search HAVE___RES_SEARCH)
94
95 check_function_exists(res_nsearch HAVE_RES_NSEARCH)
96 check_function_exists(__res_nsearch HAVE___RES_NSEARCH)
97
98 check_symbol_exists(ns_name_compress "sys/types.h;arpa/nameser.h" HAVE_NS_NAME_COMPRESS)
99
100 if (UNIX)
101     if (NOT LINUX)
102         # libsocket (Solaris)
103         check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET)
104         if (HAVE_LIBSOCKET)
105           set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
106         endif (HAVE_LIBSOCKET)
107
108         # libnsl/inet_pton (Solaris)
109         check_library_exists(nsl inet_pton "" HAVE_LIBNSL)
110         if (HAVE_LIBNSL)
111             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} nsl)
112         endif (HAVE_LIBNSL)
113     endif (NOT LINUX)
114
115     check_function_exists(getaddrinfo HAVE_GETADDRINFO)
116 endif (UNIX)
117
118 check_library_exists(dl dlopen "" HAVE_LIBDL)
119 if (HAVE_LIBDL)
120     find_library(DLFCN_LIBRARY dl)
121     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY})
122 endif (HAVE_LIBDL)
123
124 # IPV6
125 check_c_source_compiles("
126     #include <stdlib.h>
127     #include <sys/socket.h>
128     #include <netdb.h>
129     #include <netinet/in.h>
130     #include <net/if.h>
131
132 int main(void) {
133     struct sockaddr_storage sa_store;
134     struct addrinfo *ai = NULL;
135     struct in6_addr in6addr;
136     int idx = if_nametoindex(\"iface1\");
137     int s = socket(AF_INET6, SOCK_STREAM, 0);
138     int ret = getaddrinfo(NULL, NULL, NULL, &ai);
139     if (ret != 0) {
140         const char *es = gai_strerror(ret);
141     }
142
143     freeaddrinfo(ai);
144     {
145         int val = 1;
146 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
147 #define IPV6_V6ONLY 26
148 #endif
149         ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
150                          (const void *)&val, sizeof(val));
151     }
152
153     return 0;
154 }" HAVE_IPV6)
155
156 check_struct_has_member("struct __res_state" _u._ext.nsaddrs resolv.h HAVE_RESOLV_IPV6_NSADDRS)
157
158 check_c_source_compiles("
159 void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
160
161 int main(void) {
162     return 0;
163 }" HAVE_ATTRIBUTE_PRINTF_FORMAT)
164
165 check_c_source_compiles("
166 void test_destructor_attribute(void) __attribute__ ((destructor));
167
168 void test_destructor_attribute(void)
169 {
170     return;
171 }
172
173 int main(void) {
174     return 0;
175 }" HAVE_DESTRUCTOR_ATTRIBUTE)
176
177 # ENDIAN
178 test_big_endian(WORDS_BIGENDIAN)
179
180 set(RWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "resolv_wrapper required system libraries")