wmem: allow wmem_destroy_list to ignore a NULL list.
[metze/wireshark/wip.git] / wsutil / CMakeLists.txt
1 # CMakeLists.txt
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(UseABICheck)
11
12 add_definitions(-DPLUGIN_DIR=\"${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_LIBDIR}\")
13 add_definitions(-DEXTCAP_DIR=\"${CMAKE_INSTALL_PREFIX}/${EXTCAP_INSTALL_LIBDIR}\")
14 add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}\")
15
16 set(WSUTIL_PUBLIC_HEADERS
17         adler32.h
18         base32.h
19         bits_count_ones.h
20         bits_ctz.h
21         bitswap.h
22         buffer.h
23         color.h
24         copyright_info.h
25         cpu_info.h
26         crash_info.h
27         crc6.h
28         crc7.h
29         crc8.h
30         crc10.h
31         crc11.h
32         crc16.h
33         crc16-plain.h
34         crc32.h
35         curve25519.h
36         eax.h
37         filesystem.h
38         frequency-utils.h
39         g711.h
40         inet_addr.h
41         inet_ipv4.h
42         inet_ipv6.h
43         interface.h
44         jsmn.h
45         json_dumper.h
46         mpeg-audio.h
47         netlink.h
48         nstime.h
49         os_version_info.h
50         pint.h
51         plugins.h
52         pow2.h
53         privileges.h
54         processes.h
55         report_message.h
56         sign_ext.h
57         sober128.h
58         socket.h
59         str_util.h
60         strnatcmp.h
61         strtoi.h
62         tempfile.h
63         time_util.h
64         type_util.h
65         unicode-utils.h
66         utf8_entities.h
67         ws_cpuid.h
68         ws_mempbrk.h
69         ws_mempbrk_int.h
70         ws_pipe.h
71         ws_printf.h
72         wsjson.h
73         xtea.h
74 )
75
76 set(WSUTIL_COMMON_FILES
77         adler32.c
78         base32.c
79         bitswap.c
80         buffer.c
81         copyright_info.c
82         crash_info.c
83         crc10.c
84         crc16.c
85         crc16-plain.c
86         crc32.c
87         crc6.c
88         crc7.c
89         crc8.c
90         crc11.c
91         curve25519.c
92         dot11decrypt_wep.c
93         eax.c
94         filesystem.c
95         frequency-utils.c
96         g711.c
97         inet_addr.c
98         interface.c
99         jsmn.c
100         json_dumper.c
101         mpeg-audio.c
102         nstime.c
103         cpu_info.c
104         os_version_info.c
105         privileges.c
106         rsa.c
107         sober128.c
108         strnatcmp.c
109         str_util.c
110         strtoi.c
111         report_message.c
112         tempfile.c
113         time_util.c
114         type_util.c
115         unicode-utils.c
116         ws_mempbrk.c
117         ws_pipe.c
118         wsgcrypt.c
119         wsjson.c
120         xtea.c
121 )
122
123 if(ENABLE_PLUGINS)
124         list(APPEND WSUTIL_COMMON_FILES
125                 plugins.c
126         )
127 endif()
128
129 set(WSUTIL_FILES ${WSUTIL_COMMON_FILES})
130 if(WIN32)
131         list(APPEND WSUTIL_FILES
132                 file_util.c
133                 win32-utils.c
134         )
135 endif(WIN32)
136
137
138 if(HAVE_MACOS_FRAMEWORKS)
139         list(APPEND WSUTIL_FILES cfutils.c)
140 endif()
141
142 #
143 # XXX - we're assuming MSVC doesn't require a flag to enable SSE 4.2
144 # support, and that, if the compiler supports a flag for SSE 4.2
145 # support, the intrinsics are supported iff we can include the
146 # <nmmintrin.h> flag.
147 #
148 # We only check for the GCC-style -msse4.2 flag and the Sun C
149 # -xarch=sse4_2 flag.
150 #
151 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
152         set(COMPILER_CAN_HANDLE_SSE4_2 TRUE)
153         set(SSE4_2_FLAG "")
154 else()
155         message(STATUS "Checking for c-compiler flag: -msse4.2")
156         check_c_compiler_flag(-msse4.2 COMPILER_CAN_HANDLE_SSE4_2)
157         if(COMPILER_CAN_HANDLE_SSE4_2)
158                 set(SSE4_2_FLAG "-msse4.2")
159         else()
160                 message(STATUS "Checking for c-compiler flag: -xarch=sse4_2")
161                 check_c_compiler_flag(-xarch=sse4_2 COMPILER_CAN_HANDLE_SSE4_2)
162                 if(COMPILER_CAN_HANDLE_SSE4_2)
163                         set(SSE4_2_FLAG "-xarch=sse4_2")
164                 endif()
165         endif()
166 endif()
167 if(COMPILER_CAN_HANDLE_SSE4_2)
168         #
169         # Make sure we have the necessary headers for the SSE4.2 intrinsics
170         # and that we can use them.
171         #
172         # First, check whether we have emmintrin.h and can use it
173         # *without* the SSE 4.2 flag.
174         #
175         check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
176
177         #
178         # OK, if that works, see whether we have nmmintrin.h and
179         # can use it *with* the SSE 4.2 flag.
180         #
181         if(EMMINTRIN_H_WORKS)
182                 #
183                 # Does this add the SSE4.2 flags to the beginning of
184                 # CFLAGS?
185                 #
186                 # Note that if there's a mix of "enable SSE 4.2" and
187                 # "disable SSE 4.2" flags, this may not indicate that
188                 # we can use the header.  That's not a bug, that's a
189                 # feature; the other flags may have been forced by
190                 # the build process, e.g. in Gentoo Linux, and we want
191                 # to check this with whatever flags will actually be
192                 # used when building (see bug 10792).
193                 #
194                 cmake_push_check_state()
195                 set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
196                 check_include_file("nmmintrin.h" HAVE_SSE4_2)
197                 cmake_pop_check_state()
198         endif()
199 endif()
200 if(HAVE_SSE4_2)
201         list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
202 endif()
203
204 if(NOT HAVE_GETOPT_LONG)
205         list(APPEND WSUTIL_FILES getopt_long.c)
206 endif()
207
208 if(NOT HAVE_STRPTIME)
209         list(APPEND WSUTIL_FILES strptime.c)
210 endif()
211
212 if(APPLE)
213         #
214         # We assume that APPLE means macOS so that we have the macOS
215         # frameworks.
216         #
217         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
218 endif()
219
220 set_source_files_properties(
221         ${WSUTIL_FILES}
222         PROPERTIES
223         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
224 )
225 if (HAVE_SSE4_2)
226         # TODO with CMake 2.8.12, we could use COMPILE_OPTIONS and just append
227         # instead of this COMPILE_FLAGS duplication...
228         set_source_files_properties(
229                 ws_mempbrk_sse42.c
230                 PROPERTIES
231                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
232         )
233 endif()
234
235 add_library(wsutil
236         ${WSUTIL_FILES}
237         ${CMAKE_BINARY_DIR}/image/libwsutil.rc
238 )
239
240 set_target_properties(wsutil PROPERTIES
241         PREFIX "lib"
242         COMPILE_DEFINITIONS "WS_BUILD_DLL"
243         LINK_FLAGS "${WS_LINK_FLAGS}"
244         VERSION "0.0.0" SOVERSION 0
245         FOLDER "DLLs"
246 )
247
248 ABICHECK(libwsutil)
249
250 add_custom_command(OUTPUT libwsutil.abi.tar.gz
251         COMMAND ${CMAKE_COMMAND} -E remove_directory ${ABICHECK_TMPDIR}
252         COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}
253         COMMAND ${ABI_COPY_COMMAND} ../config.h ${ABICHECK_TMPDIR}/ ${ABI_COPY_FLAGS}
254         COMMAND ${ABI_COPY_COMMAND} ${ABICHECK_HEADERS} ${ABICHECK_TMPDIR}/ ${ABI_COPY_FLAGS}
255         COMMAND ${ABICHECK_COMMAND}
256         COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps/libwsutil/libwsutil_* ${CMAKE_CURRENT_BINARY_DIR}/libwsutil.abi.tar.gz
257         COMMAND rm -rf ${ABICHECK_TMPDIR} ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps
258         DEPENDS ${HEADERS} wsutil)
259
260 target_link_libraries(wsutil
261         PUBLIC
262         ${CMAKE_DL_LIBS}
263         ${APPLE_CORE_FOUNDATION_LIBRARY}
264         ${GMODULE2_LIBRARIES}
265         ${GLIB2_LIBRARIES}
266         ${PCAP_LIBRARIES}
267         ${GCRYPT_LIBRARIES}
268         ${WIN_WSOCK32_LIBRARY}
269         ${GNUTLS_LIBRARIES}
270 )
271
272 if(WIN32)
273         target_link_libraries(wsutil PRIVATE "iphlpapi.lib" "ws2_32.lib")
274 endif(WIN32)
275
276 target_include_directories(wsutil SYSTEM
277         PUBLIC
278                 ${PCAP_INCLUDE_DIRS}
279                 ${GCRYPT_INCLUDE_DIRS}
280                 ${GNUTLS_INCLUDE_DIRS}
281 )
282
283 install(TARGETS wsutil
284         EXPORT WiresharkTargets
285         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
286         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
287         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
288 )
289
290 install(FILES ${WSUTIL_PUBLIC_HEADERS}
291         DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${CPACK_PACKAGE_NAME}/wsutil"
292 )
293
294 CHECKAPI(
295         NAME
296           wsutil
297         SWITCHES
298           --group termoutput:2 --summary-group termoutput --build
299         SOURCES
300           ${WSUTIL_COMMON_FILES}
301 )
302
303 set_source_files_properties(jsmn.c PROPERTIES COMPILE_DEFINITIONS "JSMN_STRICT")
304
305 #
306 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
307 #
308 # Local variables:
309 # c-basic-offset: 8
310 # tab-width: 8
311 # indent-tabs-mode: t
312 # End:
313 #
314 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
315 # :indentSize=8:tabSize=8:noTabs=false:
316 #