decrypt
[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 #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("fcntl.h"                HAVE_FCNTL_H)
17 check_include_file("getopt.h"               HAVE_GETOPT_H)
18 check_include_file("grp.h"                  HAVE_GRP_H)
19 #
20 # This may require <sys/types.h> to be included
21 #
22 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
23 check_include_file("netinet/in.h"           HAVE_NETINET_IN_H)
24 check_include_file("netdb.h"                HAVE_NETDB_H)
25 check_include_file("pwd.h"                  HAVE_PWD_H)
26 check_include_file("sys/ioctl.h"            HAVE_SYS_IOCTL_H)
27 check_include_file("sys/select.h"           HAVE_SYS_SELECT_H)
28 check_include_file("sys/socket.h"           HAVE_SYS_SOCKET_H)
29 check_include_file("sys/sockio.h"           HAVE_SYS_SOCKIO_H)
30 check_include_file("sys/time.h"             HAVE_SYS_TIME_H)
31 check_include_file("sys/utsname.h"          HAVE_SYS_UTSNAME_H)
32 check_include_file("sys/wait.h"             HAVE_SYS_WAIT_H)
33 check_include_file("unistd.h"               HAVE_UNISTD_H)
34
35 #
36 # On Linux, check for some additional headers, which we need as a
37 # workaround for a bonding driver bug and for libpcap's current lack
38 # of its own workaround for that bug.
39 #
40 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
41         #
42         # Those header files require <sys/socket.h>.
43         #
44         check_c_source_compiles(
45                 "#include <sys/socket.h>
46                 #include <linux/sockios.h>
47                 int main(void)
48                 {
49                         return 0;
50                 }"
51                 HAVE_LINUX_SOCKIOS_H
52         )
53         check_c_source_compiles(
54                 "#include <sys/socket.h>
55                 #include <linux/if_bonding.h>
56                 int main(void)
57                 {
58                         return 0;
59                 }"
60                 HAVE_LINUX_IF_BONDING_H
61         )
62 endif()
63
64 #Functions
65 include(CheckFunctionExists)
66 include(CheckSymbolExists)
67
68 #
69 # Platform-specific functions used in platform-specific code.
70 # We check for them only on the platform on which we use them.
71 #
72 if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
73         #
74         # HP-UX
75         #
76         cmake_push_check_state()
77         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
78         check_function_exists("dlget"           HAVE_DLGET)
79         cmake_pop_check_state()
80 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
81         #
82         # Solaris
83         #
84         check_function_exists("getexecname"     HAVE_GETEXECNAME)
85 endif()
86
87 #
88 # Use check_symbol_exists just in case math.h does something magic
89 # and there's not actually a function named floorl()
90 #
91 cmake_push_check_state()
92 set(CMAKE_REQUIRED_INCLUDES ${M_INCLUDE_DIRS})
93 set(CMAKE_REQUIRED_LIBRARIES ${M_LIBRARIES})
94 check_symbol_exists("floorl" "math.h"    HAVE_FLOORL)
95 cmake_pop_check_state()
96
97 check_function_exists("getopt_long"      HAVE_GETOPT_LONG)
98 if(HAVE_GETOPT_LONG)
99         #
100         # The OS has getopt_long(), so it might have optreset.
101         # Do we have it?
102         #
103         if(HAVE_GETOPT_H)
104                 check_symbol_exists("optreset" "getopt.h" HAVE_OPTRESET)
105         else()
106                 check_symbol_exists("optreset"           HAVE_OPTRESET)
107         endif()
108 else()
109         #
110         # The OS doesn't have getopt_long(), so we're using the GNU libc
111         # version that we have in wsutil.  It doesn't have optreset, so we
112         # don't need to check for it.
113         #
114         # However, it uses alloca(), so we may need to include alloca.h;
115         # check for it.
116         #
117         check_include_file("alloca.h"    HAVE_ALLOCA_H)
118 endif()
119 check_function_exists("getifaddrs"       HAVE_GETIFADDRS)
120 check_function_exists("issetugid"        HAVE_ISSETUGID)
121 check_function_exists("mkstemps"         HAVE_MKSTEMPS)
122 check_function_exists("setresgid"        HAVE_SETRESGID)
123 check_function_exists("setresuid"        HAVE_SETRESUID)
124 check_function_exists("strptime"         HAVE_STRPTIME)
125 if (APPLE)
126         cmake_push_check_state()
127         set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY})
128         check_function_exists("CFPropertyListCreateWithStream" HAVE_CFPROPERTYLISTCREATEWITHSTREAM)
129         cmake_pop_check_state()
130 endif()
131
132 #Struct members
133 include(CheckStructHasMember)
134 check_struct_has_member("struct sockaddr" sa_len         sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
135 check_struct_has_member("struct stat"     st_flags       sys/stat.h   HAVE_STRUCT_STAT_ST_FLAGS)
136 check_struct_has_member("struct stat"     st_birthtime   sys/stat.h   HAVE_STRUCT_STAT_ST_BIRTHTIME)
137 check_struct_has_member("struct stat"     __st_birthtime sys/stat.h   HAVE_STRUCT_STAT___ST_BIRTHTIME)
138 check_struct_has_member("struct tm"       tm_zone        time.h       HAVE_STRUCT_TM_TM_ZONE)
139
140 #Symbols but NOT enums or types
141 check_symbol_exists(tzname "time.h" HAVE_TZNAME)
142
143 # Check for stuff that isn't testable via the tests above
144
145 #
146 # *If* we found libnl, check if we can use nl80211 stuff with it.
147 #
148 if (NL_FOUND)
149         check_c_source_compiles(
150                 "#include <linux/nl80211.h>
151                 int main(void) {
152                         int x = NL80211_FREQUENCY_ATTR_MAX_TX_POWER;
153                         x |= NL80211_ATTR_SUPPORTED_IFTYPES;
154                         x |= NL80211_ATTR_SUPPORTED_COMMANDS;
155                         x |= NL80211_ATTR_WIPHY_FREQ;
156                         x |= NL80211_CHAN_NO_HT;
157                         (void)x;
158                 }"
159                 HAVE_NL80211
160         )
161         check_c_source_compiles(
162                 "#include <linux/nl80211.h>
163                 int main(void) {
164                         enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
165                 }"
166                 HAVE_NL80211_CMD_SET_CHANNEL
167         )
168         check_c_source_compiles(
169                 "#include <linux/nl80211.h>
170                 int main(void) {
171                         enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
172                 }"
173                 HAVE_NL80211_SPLIT_WIPHY_DUMP
174         )
175         check_c_source_compiles(
176                 "#include <linux/nl80211.h>
177                 int main(void) {
178                         enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
179                 }"
180                 HAVE_NL80211_VHT_CAPABILITY
181         )
182 endif()
183
184 #
185 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
186 #
187 # Local variables:
188 # c-basic-offset: 8
189 # tab-width: 8
190 # indent-tabs-mode: t
191 # End:
192 #
193 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
194 # :indentSize=8:tabSize=8:noTabs=false:
195 #