Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / wsutil / CMakeLists.txt
blob7133bc2032309bfef1bcad5a4d37ce473a7a9700
1 # CMakeLists.txt
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 # CMake says that these paths should be relative to the install prefix
11 # https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
12 # Things generally work if they're not, but it becomes impossible
13 # to relocate paths. Work around that, and just don't try to support
14 # relocation.
15 file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" PATH_INSTALL_PREFIX)
16 string(REPLACE "\\" "\\\\" PATH_INSTALL_PREFIX "${PATH_INSTALL_PREFIX}")
17 file(TO_NATIVE_PATH "${CMAKE_INSTALL_DATADIR}" PATH_DATA_DIR)
18 string(REPLACE "\\" "\\\\" PATH_DATA_DIR "${PATH_DATA_DIR}")
19 file(TO_NATIVE_PATH "${CMAKE_INSTALL_DOCDIR}" PATH_DOC_DIR)
20 string(REPLACE "\\" "\\\\" PATH_DOC_DIR "${PATH_DOC_DIR}")
21 file(TO_NATIVE_PATH "${PLUGIN_INSTALL_LIBDIR}" PATH_PLUGIN_DIR)
22 string(REPLACE "\\" "\\\\" PATH_PLUGIN_DIR "${PATH_PLUGIN_DIR}")
23 file(TO_NATIVE_PATH "${EXTCAP_INSTALL_LIBDIR}" PATH_EXTCAP_DIR)
24 string(REPLACE "\\" "\\\\" PATH_EXTCAP_DIR "${PATH_EXTCAP_DIR}")
25 file(TO_NATIVE_PATH "${STRATOSHARK_EXTCAP_INSTALL_LIBDIR}" PATH_STRATOSHARK_EXTCAP_DIR)
26 string(REPLACE "\\" "\\\\" PATH_STRATOSHARK_EXTCAP_DIR "${PATH_STRATOSHARK_EXTCAP_DIR}")
28 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/path_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/path_config.h)
30 include_directories(${CMAKE_CURRENT_BINARY_DIR})
32 set(WMEM_PUBLIC_HEADERS
33         wmem/wmem.h
34         wmem/wmem_array.h
35         wmem/wmem_core.h
36         wmem/wmem_list.h
37         wmem/wmem_map.h
38         wmem/wmem_miscutl.h
39         wmem/wmem_multimap.h
40         wmem/wmem_queue.h
41         wmem/wmem_stack.h
42         wmem/wmem_strbuf.h
43         wmem/wmem_strutl.h
44         wmem/wmem_tree.h
45         wmem/wmem_interval_tree.h
46         wmem/wmem_user_cb.h
49 set(WMEM_HEADER_FILES
50         ${WMEM_PUBLIC_HEADERS}
51         wmem/wmem_allocator.h
52         wmem/wmem_allocator_block.h
53         wmem/wmem_allocator_block_fast.h
54         wmem/wmem_allocator_simple.h
55         wmem/wmem_allocator_strict.h
56         wmem/wmem_interval_tree.h
57         wmem/wmem_map_int.h
58         wmem/wmem_tree-int.h
59         wmem/wmem_user_cb_int.h
62 set(WMEM_FILES
63         wmem/wmem_array.c
64         wmem/wmem_core.c
65         wmem/wmem_allocator_block.c
66         wmem/wmem_allocator_block_fast.c
67         wmem/wmem_allocator_simple.c
68         wmem/wmem_allocator_strict.c
69         wmem/wmem_interval_tree.c
70         wmem/wmem_list.c
71         wmem/wmem_map.c
72         wmem/wmem_miscutl.c
73         wmem/wmem_multimap.c
74         wmem/wmem_stack.c
75         wmem/wmem_strbuf.c
76         wmem/wmem_strutl.c
77         wmem/wmem_tree.c
78         wmem/wmem_user_cb.c
81 set(WSUTIL_PUBLIC_HEADERS
82         802_11-utils.h
83         adler32.h
84         application_flavor.h
85         array.h
86         base32.h
87         bits_count_ones.h
88         bits_ctz.h
89         bitswap.h
90         buffer.h
91         clopts_common.h
92         cmdarg_err.h
93         codecs.h
94         color.h
95         cpu_info.h
96         crash_info.h
97         crc5.h
98         crc6.h
99         crc7.h
100         crc8.h
101         crc10.h
102         crc11.h
103         crc16.h
104         crc16-plain.h
105         crc32.h
106         curve25519.h
107         eax.h
108         epochs.h
109         exported_pdu_tlvs.h
110         failure_message_simple.h
111         feature_list.h
112         filesystem.h
113         g711.h
114         inet_addr.h
115         inet_cidr.h
116         interface.h
117         introspection.h
118         jsmn.h
119         json_dumper.h
120         mpeg-audio.h
121         nstime.h
122         os_version_info.h
123         pint.h
124         please_report_bug.h
125         plugins.h
126         pow2.h
127         privileges.h
128         processes.h
129         regex.h
130         report_message.h
131         sign_ext.h
132         sober128.h
133         socket.h
134         str_util.h
135         strnatcmp.h
136         strtoi.h
137         tempfile.h
138         time_util.h
139         to_str.h
140         type_util.h
141         unicode-utils.h
142         utf8_entities.h
143         version_info.h
144         ws_assert.h
145         ws_cpuid.h
146         glib-compat.h
147         ws_getopt.h
148         ws_mempbrk.h
149         ws_mempbrk_int.h
150         ws_pipe.h
151         ws_roundup.h
152         ws_strptime.h
153         wsgcrypt.h
154         wsjson.h
155         wslog.h
156         xtea.h
159 set(WSUTIL_COMMON_FILES
160         802_11-utils.c
161         adler32.c
162         application_flavor.c
163         base32.c
164         bitswap.c
165         buffer.c
166         clopts_common.c
167         cmdarg_err.c
168         codecs.c
169         crash_info.c
170         crc10.c
171         crc16.c
172         crc16-plain.c
173         crc32.c
174         crc5.c
175         crc6.c
176         crc7.c
177         crc8.c
178         crc11.c
179         curve25519.c
180         dot11decrypt_wep.c
181         dtoa.c
182         eax.c
183         failure_message_simple.c
184         feature_list.c
185         filesystem.c
186         filter_files.c
187         g711.c
188         inet_addr.c
189         inet_cidr.c
190         interface.c
191         introspection.c
192         jsmn.c
193         json_dumper.c
194         mpeg-audio.c
195         nstime.c
196         cpu_info.c
197         os_version_info.c
198         please_report_bug.c
199         privileges.c
200         regex.c
201         rsa.c
202         sober128.c
203         socket.c
204         strnatcmp.c
205         str_util.c
206         strtoi.c
207         report_message.c
208         tempfile.c
209         time_util.c
210         to_str.c
211         type_util.c
212         unicode-utils.c
213         version_info.c
214         ws_getopt.c
215         ws_mempbrk.c
216         ws_pipe.c
217         ws_strptime.c
218         wsgcrypt.c
219         wsjson.c
220         wslog.c
221         xtea.c
224 if(WIN32)
225         list(APPEND WSUTIL_COMMON_FILES
226                 console_win32.c
227         )
228 endif()
230 if(ENABLE_PLUGINS)
231         list(APPEND WSUTIL_COMMON_FILES
232                 plugins.c
233         )
234 endif()
236 set(WSUTIL_FILES
237         ${WMEM_FILES}
238         ${WSUTIL_COMMON_FILES}
241 if(WIN32)
242         list(APPEND WSUTIL_FILES
243                 file_util.c
244                 win32-utils.c
245         )
246 endif(WIN32)
249 if(HAVE_MACOS_FRAMEWORKS)
250         list(APPEND WSUTIL_FILES cfutils.c)
251 endif()
254 # XXX - we're assuming MSVC doesn't require a flag to enable SSE 4.2
255 # support, and that, if the compiler supports a flag for SSE 4.2
256 # support, the intrinsics are supported iff we can include the
257 # <nmmintrin.h> flag.
259 # We only check for the GCC-style -msse4.2 flag and the Sun C
260 # -xarch=sse4_2 flag.
262 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
263         set(COMPILER_CAN_HANDLE_SSE4_2 TRUE)
264         set(SSE4_2_FLAG "")
265 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686|x86|x86_64|AMD64")
266         check_c_compiler_flag(-msse4.2 COMPILER_CAN_HANDLE_SSE4_2)
267         if(COMPILER_CAN_HANDLE_SSE4_2)
268                 set(SSE4_2_FLAG "-msse4.2")
269         else()
270                 check_c_compiler_flag(-xarch=sse4_2 COMPILER_CAN_HANDLE_SSE4_2)
271                 if(COMPILER_CAN_HANDLE_SSE4_2)
272                         set(SSE4_2_FLAG "-xarch=sse4_2")
273                 endif()
274         endif()
275 else()
276         set(COMPILE_CAN_HANDLE_SSE4_2 FALSE)
277         set(SSE4_2_FLAG "")
278 endif()
280 if(SSE4_2_FLAG)
281         message(STATUS "SSE4.2 compiler flag: ${SSE4_2_FLAG}")
282 else()
283         message(STATUS "No SSE4.2 compiler flag enabled")
284 endif()
285 if(COMPILER_CAN_HANDLE_SSE4_2)
286         #
287         # Make sure we have the necessary headers for the SSE4.2 intrinsics
288         # and that we can use them.
289         #
290         # First, check whether we have emmintrin.h and can use it
291         # *without* the SSE 4.2 flag.
292         #
293         check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
295         #
296         # OK, if that works, see whether we have nmmintrin.h and
297         # can use it *with* the SSE 4.2 flag.
298         #
299         if(EMMINTRIN_H_WORKS)
300                 #
301                 # Does this add the SSE4.2 flags to the beginning of
302                 # CFLAGS?
303                 #
304                 # Note that if there's a mix of "enable SSE 4.2" and
305                 # "disable SSE 4.2" flags, this may not indicate that
306                 # we can use the header.  That's not a bug, that's a
307                 # feature; the other flags may have been forced by
308                 # the build process, e.g. in Gentoo Linux, and we want
309                 # to check this with whatever flags will actually be
310                 # used when building (see bug 10792).
311                 #
312                 cmake_push_check_state()
313                 set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
314                 check_include_file("nmmintrin.h" HAVE_SSE4_2)
315                 cmake_pop_check_state()
316         endif()
317 endif()
318 if(HAVE_SSE4_2)
319         list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
320 endif()
322 if(APPLE)
323         #
324         # We assume that APPLE means macOS so that we have the macOS
325         # frameworks.
326         #
327         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
328 endif()
330 set_source_files_properties(
331         ${WSUTIL_FILES}
332         PROPERTIES
333         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
336 if (HAVE_SSE4_2)
337         # TODO with CMake 2.8.12, we could use COMPILE_OPTIONS and just append
338         # instead of this COMPILE_FLAGS duplication...
339         set_source_files_properties(
340                 ws_mempbrk_sse42.c
341                 PROPERTIES
342                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
343         )
344 endif()
346 if (ENABLE_APPLICATION_BUNDLE)
347         set_source_files_properties(
348                 filesystem.c
349                 PROPERTIES
350                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} -DENABLE_APPLICATION_BUNDLE"
352 endif()
354 add_library(wsutil
355         ${WSUTIL_FILES}
356         ${CMAKE_BINARY_DIR}/resources/libwsutil.rc
359 if(NOT VCSVERSION_OVERRIDE)
360         add_dependencies(wsutil vcs_version)
361 endif()
363 target_compile_definitions(wsutil PRIVATE
364         WS_BUILD_DLL
365         BUILD_WSUTIL
368 set_target_properties(wsutil PROPERTIES
369         PREFIX "lib"
370         LINK_FLAGS "${WS_LINK_FLAGS}"
371         VERSION "0.0.0" SOVERSION 0
372         FOLDER "DLLs"
373         INSTALL_RPATH "${LIBRARY_INSTALL_RPATH}"
375 if(MSVC)
376         set_target_properties(wsutil PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
377 endif()
379 target_link_libraries(wsutil
380         PUBLIC
381                 ${GLIB2_LIBRARIES}
382         PRIVATE
383                 ${GMODULE2_LIBRARIES}
384                 ${APPLE_CORE_FOUNDATION_LIBRARY}
385                 ${CMAKE_DL_LIBS}
386                 ${GCRYPT_LIBRARIES}
387                 ${GNUTLS_LIBRARIES}
388                 ${M_LIBRARIES}
389                 ${ZLIB_LIBRARIES}
390                 ${ZLIBNG_LIBRARIES}
391                 $<IF:$<CONFIG:Debug>,${PCRE2_DEBUG_LIBRARIES},${PCRE2_LIBRARIES}>
392                 ${WIN_IPHLPAPI_LIBRARY}
393                 ${WIN_WS2_32_LIBRARY}
396 target_include_directories(wsutil SYSTEM
397         PUBLIC
398                 ${GLIB2_INCLUDE_DIRS}
399                 ${GCRYPT_INCLUDE_DIRS}
400                 ${GNUTLS_INCLUDE_DIRS}
401         PRIVATE
402                 ${GMODULE2_INCLUDE_DIRS}
403                 ${ZLIB_INCLUDE_DIRS}
404                 ${ZLIBNG_INCLUDE_DIRS}
405                 ${PCRE2_INCLUDE_DIRS}
408 install(TARGETS wsutil
409         EXPORT WiresharkTargets
410         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
411         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
412         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
415 install(FILES ${WMEM_PUBLIC_HEADERS}
416         DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil/wmem"
417         COMPONENT "Development"
418         EXCLUDE_FROM_ALL
421 install(FILES ${WSUTIL_PUBLIC_HEADERS}
422         DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil"
423         COMPONENT "Development"
424         EXCLUDE_FROM_ALL
427 add_library(wsutil_static STATIC
428         ${WSUTIL_FILES}
431 target_compile_definitions(wsutil_static PRIVATE
432         ENABLE_STATIC
433         BUILD_WSUTIL
436 target_link_libraries(wsutil_static
437         PUBLIC
438                 ${GLIB2_LIBRARIES}
439         PRIVATE
440                 ${GMODULE2_LIBRARIES}
441                 ${APPLE_CORE_FOUNDATION_LIBRARY}
442                 ${CMAKE_DL_LIBS}
443                 ${GCRYPT_LIBRARIES}
444                 ${GNUTLS_LIBRARIES}
445                 ${M_LIBRARIES}
446                 ${ZLIB_LIBRARIES}
447                 ${ZLIBNG_LIBRARIES}
448                 $<IF:$<CONFIG:Debug>,${PCRE2_DEBUG_LIBRARIES},${PCRE2_LIBRARIES}>
449                 ${WIN_IPHLPAPI_LIBRARY}
450                 ${WIN_WS2_32_LIBRARY}
453 target_include_directories(wsutil_static SYSTEM
454         PUBLIC
455                 ${GLIB2_INCLUDE_DIRS}
456                 ${GCRYPT_INCLUDE_DIRS}
457                 ${GNUTLS_INCLUDE_DIRS}
458         PRIVATE
459                 ${GMODULE2_INCLUDE_DIRS}
460                 ${ZLIB_INCLUDE_DIRS}
461                 ${ZLIBNG_INCLUDE_DIRS}
462                 ${PCRE2_INCLUDE_DIRS}
465 if(NOT VCSVERSION_OVERRIDE)
466         add_dependencies(wsutil_static vcs_version)
467 endif()
469 add_executable(wmem_test EXCLUDE_FROM_ALL wmem/wmem_test.c ${WMEM_FILES})
471 target_link_libraries(wmem_test wsutil)
473 set_target_properties(wmem_test PROPERTIES
474         FOLDER "Tests"
475         EXCLUDE_FROM_DEFAULT_BUILD True
476         COMPILE_DEFINITIONS "WS_BUILD_DLL"
477         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
480 add_executable(test_wsutil EXCLUDE_FROM_ALL
481         test_wsutil.c
484 target_link_libraries(test_wsutil ${GLIB2_LIBRARIES} wsutil)
486 set_target_properties(test_wsutil PROPERTIES
487         FOLDER "Tests"
488         EXCLUDE_FROM_DEFAULT_BUILD True
489         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
492 CHECKAPI(
493         NAME
494           wsutil
495         SWITCHES
496         SOURCES
497           ${WMEM_FILES}
498           ${WSUTIL_COMMON_FILES}
501 set_source_files_properties(jsmn.c PROPERTIES COMPILE_DEFINITIONS "JSMN_STRICT")
504 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
506 # Local variables:
507 # c-basic-offset: 8
508 # tab-width: 8
509 # indent-tabs-mode: t
510 # End:
512 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
513 # :indentSize=8:tabSize=8:noTabs=false: