Allow extra plugins to be missing e.g. because they are in another branch
[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 check_include_file("arpa/inet.h"         HAVE_ARPA_INET_H)
15 check_include_file("fcntl.h"             HAVE_FCNTL_H)
16 check_include_file("getopt.h"            HAVE_GETOPT_H)
17 check_include_file("grp.h"               HAVE_GRP_H)
18 check_include_file("ifaddrs.h"           HAVE_IFADDRS_H)
19 check_include_file("netinet/in.h"        HAVE_NETINET_IN_H)
20 check_include_file("netdb.h"             HAVE_NETDB_H)
21 check_include_file("pwd.h"               HAVE_PWD_H)
22 check_include_file("sys/ioctl.h"         HAVE_SYS_IOCTL_H)
23 check_include_file("sys/select.h"        HAVE_SYS_SELECT_H)
24 check_include_file("sys/socket.h"        HAVE_SYS_SOCKET_H)
25 check_include_file("sys/sockio.h"        HAVE_SYS_SOCKIO_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)
30
31 #
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.
35 #
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()
59
60 #Functions
61 include(CheckFunctionExists)
62 include(CheckSymbolExists)
63
64 #
65 # Platform-specific functions used in platform-specific code.
66 # We check for them only on the platform on which we use them.
67 #
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()
82
83 #
84 # Use check_symbol_exists just in case math.h does something magic
85 # and there's not actually a function named floorl()
86 #
87 cmake_push_check_state()
88 set(CMAKE_REQUIRED_INCLUDES ${M_INCLUDE_DIRS})
89 set(CMAKE_REQUIRED_LIBRARIES ${M_LIBRARIES})
90 check_symbol_exists("floorl" "math.h"    HAVE_FLOORL)
91 cmake_pop_check_state()
92
93 check_function_exists("getopt_long"      HAVE_GETOPT_LONG)
94 if(HAVE_GETOPT_LONG)
95         #
96         # The OS has getopt_long(), so it might have optreset.
97         # Do we have it?
98         #
99         if(HAVE_GETOPT_H)
100                 check_symbol_exists("optreset" "getopt.h" HAVE_OPTRESET)
101         else()
102                 check_symbol_exists("optreset"           HAVE_OPTRESET)
103         endif()
104 else()
105         #
106         # The OS doesn't have getopt_long(), so we're using the GNU libc
107         # version that we have in wsutil.  It doesn't have optreset, so we
108         # don't need to check for it.
109         #
110         # However, it uses alloca(), so we may need to include alloca.h;
111         # check for it.
112         #
113         check_include_file("alloca.h"    HAVE_ALLOCA_H)
114 endif()
115 check_function_exists("getifaddrs"       HAVE_GETIFADDRS)
116 check_function_exists("issetugid"        HAVE_ISSETUGID)
117 check_function_exists("mkstemps"         HAVE_MKSTEMPS)
118 check_function_exists("setresgid"        HAVE_SETRESGID)
119 check_function_exists("setresuid"        HAVE_SETRESUID)
120 check_function_exists("strptime"         HAVE_STRPTIME)
121 if (APPLE)
122         cmake_push_check_state()
123         set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY})
124         check_function_exists("CFPropertyListCreateWithStream" HAVE_CFPROPERTYLISTCREATEWITHSTREAM)
125         cmake_pop_check_state()
126 endif()
127
128 #Struct members
129 include(CheckStructHasMember)
130 check_struct_has_member("struct sockaddr" sa_len         sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
131 check_struct_has_member("struct stat"     st_flags       sys/stat.h   HAVE_STRUCT_STAT_ST_FLAGS)
132 check_struct_has_member("struct stat"     st_birthtime   sys/stat.h   HAVE_STRUCT_STAT_ST_BIRTHTIME)
133 check_struct_has_member("struct stat"     __st_birthtime sys/stat.h   HAVE_STRUCT_STAT___ST_BIRTHTIME)
134 check_struct_has_member("struct tm"       tm_zone        time.h       HAVE_STRUCT_TM_TM_ZONE)
135
136 #Symbols but NOT enums or types
137 check_symbol_exists(tzname "time.h" HAVE_TZNAME)
138
139 # Check for stuff that isn't testable via the tests above
140
141 #
142 # *If* we found libnl, check if we can use nl80211 stuff with it.
143 #
144 if (NL_FOUND)
145         check_c_source_compiles(
146                 "#include <linux/nl80211.h>
147                 int main(void) {
148                         int x = NL80211_FREQUENCY_ATTR_MAX_TX_POWER;
149                         x |= NL80211_ATTR_SUPPORTED_IFTYPES;
150                         x |= NL80211_ATTR_SUPPORTED_COMMANDS;
151                         x |= NL80211_ATTR_WIPHY_FREQ;
152                         x |= NL80211_CHAN_NO_HT;
153                         (void)x;
154                 }"
155                 HAVE_NL80211
156         )
157         check_c_source_compiles(
158                 "#include <linux/nl80211.h>
159                 int main(void) {
160                         enum nl80211_commands x = NL80211_CMD_SET_CHANNEL;
161                 }"
162                 HAVE_NL80211_CMD_SET_CHANNEL
163         )
164         check_c_source_compiles(
165                 "#include <linux/nl80211.h>
166                 int main(void) {
167                         enum nl80211_protocol_features x = NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP;
168                 }"
169                 HAVE_NL80211_SPLIT_WIPHY_DUMP
170         )
171         check_c_source_compiles(
172                 "#include <linux/nl80211.h>
173                 int main(void) {
174                         enum nl80211_attrs x = NL80211_ATTR_VHT_CAPABILITY;
175                 }"
176                 HAVE_NL80211_VHT_CAPABILITY
177         )
178 endif()
179
180 #
181 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
182 #
183 # Local variables:
184 # c-basic-offset: 8
185 # tab-width: 8
186 # indent-tabs-mode: t
187 # End:
188 #
189 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
190 # :indentSize=8:tabSize=8:noTabs=false:
191 #