CMake: Skip some header checks on Windows.
[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 # SPDX-License-Identifier: GPL-2.0-or-later
8 #
9
10 include(CMakePushCheckState)
11
12 if(WIN32)
13         # Prepopulate some values. Compilation checks on Windows can be slow.
14         set(HAVE_FCNTL_H TRUE)
15         set(HAVE_SYS_STAT_H TRUE)
16         set(HAVE_FLOORL TRUE)
17         set(HAVE_LRINT TRUE)
18 endif(WIN32)
19
20 #check system for includes
21 include(CheckIncludeFile)
22 check_include_file("arpa/inet.h"         HAVE_ARPA_INET_H)
23 check_include_file("fcntl.h"             HAVE_FCNTL_H)
24 check_include_file("getopt.h"            HAVE_GETOPT_H)
25 check_include_file("grp.h"               HAVE_GRP_H)
26 check_include_file("ifaddrs.h"           HAVE_IFADDRS_H)
27 check_include_file("netinet/in.h"        HAVE_NETINET_IN_H)
28 check_include_file("netdb.h"             HAVE_NETDB_H)
29 check_include_file("pwd.h"               HAVE_PWD_H)
30 check_include_file("sys/ioctl.h"         HAVE_SYS_IOCTL_H)
31 check_include_file("sys/select.h"        HAVE_SYS_SELECT_H)
32 check_include_file("sys/socket.h"        HAVE_SYS_SOCKET_H)
33 check_include_file("sys/sockio.h"        HAVE_SYS_SOCKIO_H)
34 check_include_file("sys/stat.h"          HAVE_SYS_STAT_H)
35 check_include_file("sys/time.h"          HAVE_SYS_TIME_H)
36 check_include_file("sys/types.h"         HAVE_SYS_TYPES_H)
37 check_include_file("sys/utsname.h"       HAVE_SYS_UTSNAME_H)
38 check_include_file("sys/wait.h"          HAVE_SYS_WAIT_H)
39 check_include_file("unistd.h"            HAVE_UNISTD_H)
40
41 #
42 # On Linux, check for some additional headers, which we need as a
43 # workaround for a bonding driver bug and for libpcap's current lack
44 # of its own workaround for that bug.
45 #
46 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
47         #
48         # Those header files require <sys/socket.h>.
49         #
50         check_c_source_compiles(
51                 "#include <sys/socket.h>
52                 #include <linux/sockios.h>
53                 int main(void)
54                 {
55                         return 0;
56                 }"
57                 HAVE_LINUX_SOCKIOS_H
58         )
59         check_c_source_compiles(
60                 "#include <sys/socket.h>
61                 #include <linux/if_bonding.h>
62                 int main(void)
63                 {
64                         return 0;
65                 }"
66                 HAVE_LINUX_IF_BONDING_H
67         )
68 endif()
69
70 #Functions
71 include(CheckFunctionExists)
72 include(CheckSymbolExists)
73
74 cmake_push_check_state()
75 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
76 check_function_exists("dladdr"           HAVE_DLADDR)
77 cmake_pop_check_state()
78
79 #
80 # Use check_symbol_exists just in case math.h does something magic
81 # and there's not actually a function named floorl()
82 #
83 cmake_push_check_state()
84 set(CMAKE_REQUIRED_INCLUDES ${M_INCLUDE_DIRS})
85 set(CMAKE_REQUIRED_LIBRARIES ${M_LIBRARIES})
86 check_symbol_exists("floorl" "math.h"    HAVE_FLOORL)
87 check_symbol_exists("lrint"  "math.h"    HAVE_LRINT) # GTK+ only
88 cmake_pop_check_state()
89
90 check_function_exists("getopt_long"      HAVE_GETOPT_LONG)
91 if(HAVE_GETOPT_LONG)
92         if(HAVE_GETOPT_H)
93                 check_symbol_exists("optreset" "getopt.h" HAVE_OPTRESET)
94         else()
95                 check_symbol_exists("optreset"           HAVE_OPTRESET)
96         endif()
97 endif()
98 check_function_exists("getifaddrs"       HAVE_GETIFADDRS)
99 check_function_exists("issetugid"        HAVE_ISSETUGID)
100 check_function_exists("mkstemps"         HAVE_MKSTEMPS)
101 check_function_exists("popcount"         HAVE_POPCOUNT)
102 check_function_exists("setresgid"        HAVE_SETRESGID)
103 check_function_exists("setresuid"        HAVE_SETRESUID)
104 check_function_exists("strptime"         HAVE_STRPTIME)
105 if (APPLE)
106         cmake_push_check_state()
107         set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY})
108         check_function_exists("CFPropertyListCreateWithStream" HAVE_CFPROPERTYLISTCREATEWITHSTREAM)
109         cmake_pop_check_state()
110 endif()
111
112 #Struct members
113 include(CheckStructHasMember)
114 check_struct_has_member("struct sockaddr" sa_len         sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
115 check_struct_has_member("struct stat"     st_flags       sys/stat.h   HAVE_STRUCT_STAT_ST_FLAGS)
116 check_struct_has_member("struct stat"     st_birthtime   sys/stat.h   HAVE_STRUCT_STAT_ST_BIRTHTIME)
117 check_struct_has_member("struct stat"     __st_birthtime sys/stat.h   HAVE_STRUCT_STAT___ST_BIRTHTIME)
118 check_struct_has_member("struct tm"       tm_zone        time.h       HAVE_STRUCT_TM_TM_ZONE)
119
120 #Symbols but NOT enums or types
121 check_symbol_exists(tzname "time.h" HAVE_TZNAME)
122
123 # Check for stuff that isn't testable via the tests above
124
125 #
126 # *If* we found libnl, check if we can use nl80211 stuff with it.
127 #
128 if (NL_FOUND)
129         check_c_source_compiles(
130                 "#include <linux/nl80211.h>
131                 int main() {
132                         int x = NL80211_FREQUENCY_ATTR_MAX_TX_POWER;
133                         x |= NL80211_ATTR_SUPPORTED_IFTYPES;
134                         x |= NL80211_ATTR_SUPPORTED_COMMANDS;
135                         x |= NL80211_ATTR_WIPHY_FREQ;
136                         x |= NL80211_CHAN_NO_HT;
137                         (void)x;
138                 }"
139                 HAVE_NL80211
140         )
141         check_c_source_compiles(
142                 "#include <linux/nl80211.h>
143                 int main() {
144                         enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
145                 }"
146                 HAVE_NL80211_CMD_SET_CHANNEL
147         )
148         check_c_source_compiles(
149                 "#include <linux/nl80211.h>
150                 int main() {
151                         enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
152                 }"
153                 HAVE_NL80211_SPLIT_WIPHY_DUMP
154         )
155         check_c_source_compiles(
156                 "#include <linux/nl80211.h>
157                 int main() {
158                         enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
159                 }"
160                 HAVE_NL80211_VHT_CAPABILITY
161         )
162 endif()
163
164 #
165 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
166 #
167 # Local variables:
168 # c-basic-offset: 8
169 # tab-width: 8
170 # indent-tabs-mode: t
171 # End:
172 #
173 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
174 # :indentSize=8:tabSize=8:noTabs=false:
175 #