1 # ConfigureChecks.cmake
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
7 # SPDX-License-Identifier: GPL-2.0-or-later
10 include(CMakePushCheckState)
12 #check system for includes
13 include(CheckIncludeFile)
14 include(CheckIncludeFiles)
15 check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
16 check_include_file("grp.h" HAVE_GRP_H)
18 # This may require <sys/types.h> to be included
20 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
21 check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
22 check_include_file("netdb.h" HAVE_NETDB_H)
23 check_include_file("pwd.h" HAVE_PWD_H)
24 check_include_file("sys/select.h" HAVE_SYS_SELECT_H)
25 check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
26 check_include_file("sys/time.h" HAVE_SYS_TIME_H)
27 check_include_file("sys/utsname.h" HAVE_SYS_UTSNAME_H)
28 check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
29 check_include_file("unistd.h" HAVE_UNISTD_H)
32 # On Linux, check for some additional headers, which we need as a
33 # workaround for a bonding driver bug and for libpcap's current lack
34 # of its own workaround for that bug.
36 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
38 # Those header files require <sys/socket.h>.
40 check_c_source_compiles(
41 "#include <sys/socket.h>
42 #include <linux/sockios.h>
49 check_c_source_compiles(
50 "#include <sys/socket.h>
51 #include <linux/if_bonding.h>
56 HAVE_LINUX_IF_BONDING_H
61 include(CheckFunctionExists)
62 include(CheckSymbolExists)
65 # Platform-specific functions used in platform-specific code.
66 # We check for them only on the platform on which we use them.
68 if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
72 cmake_push_check_state()
73 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
74 check_function_exists("dlget" HAVE_DLGET)
75 cmake_pop_check_state()
76 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
80 check_function_exists("getexecname" HAVE_GETEXECNAME)
83 check_symbol_exists("clock_gettime" "time.h" HAVE_CLOCK_GETTIME)
84 # Some platforms (macOS pre 10.15) are non-conformant with C11 and lack timespec_get()
85 check_symbol_exists("timespec_get" "time.h" HAVE_TIMESPEC_GET)
87 check_symbol_exists("localtime_r" "time.h" HAVE_LOCALTIME_R)
88 check_symbol_exists("gmtime_r" "time.h" HAVE_GMTIME_R)
89 check_symbol_exists("timegm" "time.h" HAVE_TIMEGM)
90 check_symbol_exists("tzset" "time.h" HAVE_TZSET)
91 check_symbol_exists("tzname" "time.h" HAVE_TZNAME)
92 check_symbol_exists("getline" "stdio.h" HAVE_GETLINE)
94 check_function_exists("getifaddrs" HAVE_GETIFADDRS)
95 check_function_exists("issetugid" HAVE_ISSETUGID)
96 check_function_exists("setresgid" HAVE_SETRESGID)
97 check_function_exists("setresuid" HAVE_SETRESUID)
99 cmake_push_check_state()
100 set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY})
101 check_function_exists("CFPropertyListCreateWithStream" HAVE_CFPROPERTYLISTCREATEWITHSTREAM)
102 cmake_pop_check_state()
105 cmake_push_check_state()
106 list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
107 check_symbol_exists("memmem" "string.h" HAVE_MEMMEM)
108 check_symbol_exists("memrchr" "string.h" HAVE_MEMRCHR)
109 check_symbol_exists("strerrorname_np" "string.h" HAVE_STRERRORNAME_NP)
110 check_symbol_exists("strptime" "time.h" HAVE_STRPTIME)
111 check_symbol_exists("vasprintf" "stdio.h" HAVE_VASPRINTF)
112 cmake_pop_check_state()
116 include(CheckStructHasMember)
117 check_struct_has_member("struct stat" st_blksize sys/stat.h HAVE_STRUCT_STAT_ST_BLKSIZE)
118 check_struct_has_member("struct stat" st_birthtime sys/stat.h HAVE_STRUCT_STAT_ST_BIRTHTIME)
119 check_struct_has_member("struct stat" __st_birthtime sys/stat.h HAVE_STRUCT_STAT___ST_BIRTHTIME)
120 check_struct_has_member("struct tm" tm_zone time.h HAVE_STRUCT_TM_TM_ZONE)
121 check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF)
124 include(CheckTypeSize)
125 check_type_size("ssize_t" SSIZE_T)
128 # Check if the libc vsnprintf() conforms to C99. If this fails we may
129 # need to fall-back on GLib I/O.
131 # If cross-compiling we can't check so just assume this requirement is met.
133 if(NOT CMAKE_CROSSCOMPILING)
134 check_c_source_runs("
137 #pragma GCC diagnostic push
138 #pragma GCC diagnostic ignored \"-Wall\"
141 /* Check that snprintf() and vsnprintf() don't return
142 * -1 if the buffer is too small. C99 says this value
143 * is the length that would be written not including
146 return snprintf(buf, sizeof(buf), \"%s\", \"ABCDEF\") > 0 ? 0 : 1;
148 #pragma GCC diagnostic pop"
151 if (NOT HAVE_C99_VSNPRINTF)
153 "Building Wireshark requires a C99 compliant vsnprintf() and this \
154 target does not meet that requirement. Compiling for ${CMAKE_SYSTEM} \
155 using ${CMAKE_C_COMPILER_ID}. Please report this issue to the Wireshark \
156 developers at wireshark-dev@wireshark.org."
162 # *If* we found libnl, check if we can use nl80211 stuff with it.
165 check_c_source_compiles(
166 "#include <linux/nl80211.h>
168 int x = NL80211_FREQUENCY_ATTR_MAX_TX_POWER;
169 x |= NL80211_ATTR_SUPPORTED_IFTYPES;
170 x |= NL80211_ATTR_SUPPORTED_COMMANDS;
171 x |= NL80211_ATTR_WIPHY_FREQ;
172 x |= NL80211_CHAN_NO_HT;
177 check_c_source_compiles(
178 "#include <linux/nl80211.h>
180 enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
182 HAVE_NL80211_CMD_SET_CHANNEL
184 check_c_source_compiles(
185 "#include <linux/nl80211.h>
187 enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
189 HAVE_NL80211_SPLIT_WIPHY_DUMP
191 check_c_source_compiles(
192 "#include <linux/nl80211.h>
194 enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
196 HAVE_NL80211_VHT_CAPABILITY
201 # Editor modelines - https://www.wireshark.org/tools/modelines.html
206 # indent-tabs-mode: t
209 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
210 # :indentSize=8:tabSize=8:noTabs=false: