Qt: Fix leak on CaptureFileDialog preview of file with errors
[wireshark.git] / ConfigureChecks.cmake
blob22770da4259fbdcac5d5685f6832723048be9462
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 endif()
93 check_function_exists("getifaddrs"       HAVE_GETIFADDRS)
94 check_function_exists("issetugid"        HAVE_ISSETUGID)
95 check_function_exists("setresgid"        HAVE_SETRESGID)
96 check_function_exists("setresuid"        HAVE_SETRESUID)
97 if (APPLE)
98         cmake_push_check_state()
99         set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY})
100         check_function_exists("CFPropertyListCreateWithStream" HAVE_CFPROPERTYLISTCREATEWITHSTREAM)
101         cmake_pop_check_state()
102 endif()
103 if(UNIX)
104         cmake_push_check_state()
105         list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
106         check_symbol_exists("memmem"        "string.h"   HAVE_MEMMEM)
107         check_symbol_exists("memrchr"       "string.h"   HAVE_MEMRCHR)
108         check_symbol_exists("strerrorname_np" "string.h" HAVE_STRERRORNAME_NP)
109         check_symbol_exists("strptime"      "time.h"     HAVE_STRPTIME)
110         check_symbol_exists("vasprintf"     "stdio.h"    HAVE_VASPRINTF)
111         cmake_pop_check_state()
112 endif()
114 #Struct members
115 include(CheckStructHasMember)
116 check_struct_has_member("struct stat"     st_blksize     sys/stat.h   HAVE_STRUCT_STAT_ST_BLKSIZE)
117 check_struct_has_member("struct stat"     st_birthtime   sys/stat.h   HAVE_STRUCT_STAT_ST_BIRTHTIME)
118 check_struct_has_member("struct stat"     __st_birthtime sys/stat.h   HAVE_STRUCT_STAT___ST_BIRTHTIME)
119 check_struct_has_member("struct tm"       tm_zone        time.h       HAVE_STRUCT_TM_TM_ZONE)
120 check_struct_has_member("struct tm"       tm_gmtoff      time.h       HAVE_STRUCT_TM_TM_GMTOFF)
122 # Types
123 include(CheckTypeSize)
124 check_type_size("ssize_t"       SSIZE_T)
127 # Check if the libc vsnprintf() conforms to C99. If this fails we may
128 # need to fall-back on GLib I/O.
130 # If cross-compiling we can't check so just assume this requirement is met.
132 if(NOT CMAKE_CROSSCOMPILING)
133         check_c_source_runs("
134                 #include <stdio.h>
135                 int main(void)
136                 {
137                         /* Check that snprintf() and vsnprintf() don't return
138                         * -1 if the buffer is too small. C99 says this value
139                         * is the length that would be written not including
140                         * the nul byte. */
141                         char buf[3];
142                         return snprintf(buf, sizeof(buf), \"%s\", \"ABCDEF\") > 0 ? 0 : 1;
143                 }"
144                 HAVE_C99_VSNPRINTF
145         )
146         if (NOT HAVE_C99_VSNPRINTF)
147                 message(FATAL_ERROR
148 "Building Wireshark requires a C99 compliant vsnprintf() and this \
149 target does not meet that requirement. Compiling for ${CMAKE_SYSTEM} \
150 using ${CMAKE_C_COMPILER_ID}. Please report this issue to the Wireshark \
151 developers at wireshark-dev@wireshark.org."
152                 )
153         endif()
154 endif()
157 # *If* we found libnl, check if we can use nl80211 stuff with it.
159 if (NL_FOUND)
160         check_c_source_compiles(
161                 "#include <linux/nl80211.h>
162                 int main(void) {
163                         int x = NL80211_FREQUENCY_ATTR_MAX_TX_POWER;
164                         x |= NL80211_ATTR_SUPPORTED_IFTYPES;
165                         x |= NL80211_ATTR_SUPPORTED_COMMANDS;
166                         x |= NL80211_ATTR_WIPHY_FREQ;
167                         x |= NL80211_CHAN_NO_HT;
168                         (void)x;
169                 }"
170                 HAVE_NL80211
171         )
172         check_c_source_compiles(
173                 "#include <linux/nl80211.h>
174                 int main(void) {
175                         enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
176                 }"
177                 HAVE_NL80211_CMD_SET_CHANNEL
178         )
179         check_c_source_compiles(
180                 "#include <linux/nl80211.h>
181                 int main(void) {
182                         enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
183                 }"
184                 HAVE_NL80211_SPLIT_WIPHY_DUMP
185         )
186         check_c_source_compiles(
187                 "#include <linux/nl80211.h>
188                 int main(void) {
189                         enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
190                 }"
191                 HAVE_NL80211_VHT_CAPABILITY
192         )
193 endif()
196 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
198 # Local variables:
199 # c-basic-offset: 8
200 # tab-width: 8
201 # indent-tabs-mode: t
202 # End:
204 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
205 # :indentSize=8:tabSize=8:noTabs=false: