Revert "sq h2"
[wireshark-sm.git] / ConfigureChecks.cmake
blob01ba00955d2aa33d452b7216425468d79bef7792
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")
37         #
38         # Those header files require <sys/socket.h>.
39         #
40         check_c_source_compiles(
41                 "#include <sys/socket.h>
42                 #include <linux/sockios.h>
43                 int main(void)
44                 {
45                         return 0;
46                 }"
47                 HAVE_LINUX_SOCKIOS_H
48         )
49         check_c_source_compiles(
50                 "#include <sys/socket.h>
51                 #include <linux/if_bonding.h>
52                 int main(void)
53                 {
54                         return 0;
55                 }"
56                 HAVE_LINUX_IF_BONDING_H
57         )
58 endif()
60 #Functions
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")
69         #
70         # HP-UX
71         #
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.]*")
77         #
78         # Solaris
79         #
80         check_function_exists("getexecname"     HAVE_GETEXECNAME)
81 endif()
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)
86 if(NOT MSVC)
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)
93 endif()
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)
98 if (APPLE)
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()
103 endif()
104 if(UNIX)
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()
113 endif()
115 #Struct members
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)
123 # Types
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("
135                 #include <stdio.h>
137                 #pragma GCC diagnostic push
138                 #pragma GCC diagnostic ignored \"-Wall\"
139                 int main(void)
140                 {
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
144                         * the nul byte. */
145                         char buf[3];
146                         return snprintf(buf, sizeof(buf), \"%s\", \"ABCDEF\") > 0 ? 0 : 1;
147                 }
148                 #pragma GCC diagnostic pop"
149                 HAVE_C99_VSNPRINTF
150         )
151         if (NOT HAVE_C99_VSNPRINTF)
152                 message(FATAL_ERROR
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."
157                 )
158         endif()
159 endif()
162 # *If* we found libnl, check if we can use nl80211 stuff with it.
164 if (NL_FOUND)
165         check_c_source_compiles(
166                 "#include <linux/nl80211.h>
167                 int main(void) {
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;
173                         (void)x;
174                 }"
175                 HAVE_NL80211
176         )
177         check_c_source_compiles(
178                 "#include <linux/nl80211.h>
179                 int main(void) {
180                         enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
181                 }"
182                 HAVE_NL80211_CMD_SET_CHANNEL
183         )
184         check_c_source_compiles(
185                 "#include <linux/nl80211.h>
186                 int main(void) {
187                         enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
188                 }"
189                 HAVE_NL80211_SPLIT_WIPHY_DUMP
190         )
191         check_c_source_compiles(
192                 "#include <linux/nl80211.h>
193                 int main(void) {
194                         enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
195                 }"
196                 HAVE_NL80211_VHT_CAPABILITY
197         )
198 endif()
201 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
203 # Local variables:
204 # c-basic-offset: 8
205 # tab-width: 8
206 # indent-tabs-mode: t
207 # End:
209 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
210 # :indentSize=8:tabSize=8:noTabs=false: