Squelch warnings.
[metze/wireshark/wip.git] / ConfigureChecks.cmake
1 # ConfigureChecks.cmake
2 #
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 include(CMakePushCheckState)
23
24 #check system for includes
25 include(CheckIncludeFile)
26 check_include_file("arpa/inet.h"         HAVE_ARPA_INET_H)
27 check_include_file("arpa/nameser.h"      HAVE_ARPA_NAMESER_H)
28 check_include_file("dlfcn.h"             HAVE_DLFCN_H)
29 check_include_file("fcntl.h"             HAVE_FCNTL_H)
30 check_include_file("getopt.h"            HAVE_GETOPT_H)
31 check_include_file("grp.h"               HAVE_GRP_H)
32 check_include_file("ifaddrs.h"           HAVE_IFADDRS_H)
33 check_include_file("inttypes.h"          HAVE_INTTYPES_H)
34 check_include_file("netinet/in.h"        HAVE_NETINET_IN_H)
35 check_include_file("netdb.h"             HAVE_NETDB_H)
36 # We need to set the path to Wpdpack in order to find Ntddndis.h
37 #cmake_push_check_state()
38 #set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
39 #check_include_file("Ntddndis.h"          HAVE_NTDDNDIS_H)
40 #cmake_pop_check_state()
41 check_include_file("portaudio.h"         HAVE_PORTAUDIO_H)
42 check_include_file("pwd.h"               HAVE_PWD_H)
43 check_include_file("stdint.h"            HAVE_STDINT_H)
44 check_include_file("sys/ioctl.h"         HAVE_SYS_IOCTL_H)
45 check_include_file("sys/param.h"         HAVE_SYS_PARAM_H)
46 check_include_file("sys/socket.h"        HAVE_SYS_SOCKET_H)
47 check_include_file("sys/sockio.h"        HAVE_SYS_SOCKIO_H)
48 check_include_file("sys/stat.h"          HAVE_SYS_STAT_H)
49 check_include_file("sys/time.h"          HAVE_SYS_TIME_H)
50 check_include_file("sys/types.h"         HAVE_SYS_TYPES_H)
51 check_include_file("sys/utsname.h"       HAVE_SYS_UTSNAME_H)
52 check_include_file("sys/wait.h"          HAVE_SYS_WAIT_H)
53 check_include_file("unistd.h"            HAVE_UNISTD_H)
54 check_include_file("windows.h"           HAVE_WINDOWS_H)
55 check_include_file("winsock2.h"          HAVE_WINSOCK2_H)
56
57 #
58 # On Linux, check for some additional headers, which we need as a
59 # workaround for a bonding driver bug and for libpcap's current lack
60 # of its own workaround for that bug.
61 #
62 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
63         #
64         # Those header files require <sys/socket.h>.
65         #
66         check_c_source_compiles(
67                 "#include <sys/socket.h>
68                 #include <linux/sockios.h>
69                 int main(void)
70                 {
71                         return 0;
72                 }"
73                 HAVE_LINUX_SOCKIOS_H
74         )
75         check_c_source_compiles(
76                 "#include <sys/socket.h>
77                 #include <linux/if_bonding.h>
78                 int main(void)
79                 {
80                         return 0;
81                 }"
82                 HAVE_LINUX_IF_BONDING_H
83         )
84 endif()
85
86 #Functions
87 include(CheckFunctionExists)
88 include(CheckSymbolExists)
89 check_function_exists("chown"            HAVE_CHOWN)
90
91 cmake_push_check_state()
92 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
93 check_function_exists("dladdr"           HAVE_DLADDR)
94 cmake_pop_check_state()
95
96 #
97 # Use check_symbol_exists just in case math.h does something magic
98 # and there's not actually a function named floorl()
99 #
100 cmake_push_check_state()
101 set(CMAKE_REQUIRED_INCLUDES ${M_INCLUDE_DIRS})
102 set(CMAKE_REQUIRED_LIBRARIES ${M_LIBRARIES})
103 check_symbol_exists("floorl" "math.h"    HAVE_FLOORL)
104 check_symbol_exists("lrint"  "math.h"    HAVE_LRINT)
105 cmake_pop_check_state()
106
107 check_function_exists("getopt_long"      HAVE_GETOPT_LONG)
108 if(HAVE_GETOPT_LONG)
109         if(HAVE_GETOPT_H)
110                 check_symbol_exists("optreset" "getopt.h" HAVE_OPTRESET)
111         else()
112                 check_symbol_exists("optreset"           HAVE_OPTRESET)
113         endif()
114 endif()
115 check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER)
116 check_function_exists("getifaddrs"       HAVE_GETIFADDRS)
117 check_function_exists("inet_aton"        HAVE_INET_ATON)
118 check_function_exists("inet_ntop"        HAVE_INET_NTOP)
119 check_function_exists("inet_pton"        HAVE_INET_PTON)
120 check_function_exists("issetugid"        HAVE_ISSETUGID)
121 check_function_exists("mkdtemp"          HAVE_MKDTEMP)
122 check_function_exists("mkstemps"         HAVE_MKSTEMPS)
123 check_function_exists("popcount"         HAVE_POPCOUNT)
124 check_function_exists("setresgid"        HAVE_SETRESGID)
125 check_function_exists("setresuid"        HAVE_SETRESUID)
126 check_function_exists("strptime"         HAVE_STRPTIME)
127 check_function_exists("sysconf"          HAVE_SYSCONF)
128 if (APPLE)
129         cmake_push_check_state()
130         set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY})
131         check_function_exists("CFPropertyListCreateWithStream" HAVE_CFPROPERTYLISTCREATEWITHSTREAM)
132         cmake_pop_check_state()
133 endif()
134
135 #Struct members
136 include(CheckStructHasMember)
137 check_struct_has_member("struct sockaddr" sa_len         sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
138 check_struct_has_member("struct stat"     st_flags       sys/stat.h   HAVE_STRUCT_STAT_ST_FLAGS)
139 check_struct_has_member("struct stat"     st_birthtime   sys/stat.h   HAVE_STRUCT_STAT_ST_BIRTHTIME)
140 check_struct_has_member("struct stat"     __st_birthtime sys/stat.h   HAVE_STRUCT_STAT___ST_BIRTHTIME)
141 check_struct_has_member("struct tm"       tm_zone        time.h       HAVE_STRUCT_TM_TM_ZONE)
142
143 #Symbols but NOT enums or types
144 check_symbol_exists(tzname "time.h" HAVE_TZNAME)
145
146 # Check for stuff that isn't testable via the tests above
147
148 #
149 # *If* we found libnl, check if we can use nl80211 stuff with it.
150 #
151 if (NL_FOUND)
152         check_c_source_compiles(
153                 "#include <linux/nl80211.h>
154                 int main() {
155                         int x = NL80211_FREQUENCY_ATTR_MAX_TX_POWER;
156                         x |= NL80211_ATTR_SUPPORTED_IFTYPES;
157                         x |= NL80211_ATTR_SUPPORTED_COMMANDS;
158                         x |= NL80211_ATTR_WIPHY_FREQ;
159                         x |= NL80211_CHAN_NO_HT;
160                         (void)x;
161                 }"
162                 HAVE_NL80211
163         )
164         check_c_source_compiles(
165                 "#include <linux/nl80211.h>
166                 int main() {
167                         enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
168                 }"
169                 HAVE_NL80211_CMD_SET_CHANNEL
170         )
171         check_c_source_compiles(
172                 "#include <linux/nl80211.h>
173                 int main() {
174                         enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
175                 }"
176                 HAVE_NL80211_SPLIT_WIPHY_DUMP
177         )
178         check_c_source_compiles(
179                 "#include <linux/nl80211.h>
180                 int main() {
181                         enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
182                 }"
183                 HAVE_NL80211_VHT_CAPABILITY
184         )
185 endif()
186
187 #
188 # Check whether GLib's printf supports thousands grouping. (This might
189 # be different from the system's printf since GLib can optionally use
190 # its own printf implementation.)
191 #
192 if (CMAKE_CROSSCOMPILING OR WIN32)
193         #
194         # Play it safe when cross-compiling.
195         #
196         # XXX - compiling and trying to run the test below appears
197         # to loop infinitely on Windows, and the locale is wrong in
198         # any case, so we don't do this on Window for now.
199         #
200         set(HAVE_GLIB_PRINTF_GROUPING FALSE)
201 else()
202         cmake_push_check_state()
203         set(CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS})
204         set(CMAKE_REQUIRED_LIBRARIES ${GLIB2_LIBRARIES})
205         check_c_source_runs(
206                 "#include <glib.h>
207                 #include <locale.h>
208                 #include <stdio.h>
209                 #include <string.h>
210
211                 int
212                 main ()
213                 {
214                   gchar *str;
215                   setlocale(LC_ALL, \"en_US.UTF-8\");
216                   str = g_strdup_printf(\"%'u\", 123456);
217                   return (strcmp (str, \"123,456\") != 0);
218                 }" HAVE_GLIB_PRINTF_GROUPING)
219         cmake_pop_check_state()
220 endif()
221
222 #
223 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
224 #
225 # Local variables:
226 # c-basic-offset: 8
227 # tab-width: 8
228 # indent-tabs-mode: t
229 # End:
230 #
231 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
232 # :indentSize=8:tabSize=8:noTabs=false:
233 #