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
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
45 wmem/wmem_interval_tree.h
50 ${WMEM_PUBLIC_HEADERS}
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
59 wmem/wmem_user_cb_int.h
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
81 set(WSUTIL_PUBLIC_HEADERS
110 failure_message_simple.h
159 set(WSUTIL_COMMON_FILES
183 failure_message_simple.c
225 list(APPEND WSUTIL_COMMON_FILES
231 list(APPEND WSUTIL_COMMON_FILES
238 ${WSUTIL_COMMON_FILES}
242 list(APPEND WSUTIL_FILES
249 if(HAVE_MACOS_FRAMEWORKS)
250 list(APPEND WSUTIL_FILES cfutils.c)
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)
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")
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")
276 set(COMPILE_CAN_HANDLE_SSE4_2 FALSE)
281 message(STATUS "SSE4.2 compiler flag: ${SSE4_2_FLAG}")
283 message(STATUS "No SSE4.2 compiler flag enabled")
285 if(COMPILER_CAN_HANDLE_SSE4_2)
287 # Make sure we have the necessary headers for the SSE4.2 intrinsics
288 # and that we can use them.
290 # First, check whether we have emmintrin.h and can use it
291 # *without* the SSE 4.2 flag.
293 check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
296 # OK, if that works, see whether we have nmmintrin.h and
297 # can use it *with* the SSE 4.2 flag.
299 if(EMMINTRIN_H_WORKS)
301 # Does this add the SSE4.2 flags to the beginning of
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).
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()
319 list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
324 # We assume that APPLE means macOS so that we have the macOS
327 FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
330 set_source_files_properties(
333 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
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(
342 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
346 if (ENABLE_APPLICATION_BUNDLE)
347 set_source_files_properties(
350 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} -DENABLE_APPLICATION_BUNDLE"
356 ${CMAKE_BINARY_DIR}/resources/libwsutil.rc
359 if(NOT VCSVERSION_OVERRIDE)
360 add_dependencies(wsutil vcs_version)
363 target_compile_definitions(wsutil PRIVATE
368 set_target_properties(wsutil PROPERTIES
370 LINK_FLAGS "${WS_LINK_FLAGS}"
371 VERSION "0.0.0" SOVERSION 0
373 INSTALL_RPATH "${LIBRARY_INSTALL_RPATH}"
376 set_target_properties(wsutil PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
379 target_link_libraries(wsutil
383 ${GMODULE2_LIBRARIES}
384 ${APPLE_CORE_FOUNDATION_LIBRARY}
391 $<IF:$<CONFIG:Debug>,${PCRE2_DEBUG_LIBRARIES},${PCRE2_LIBRARIES}>
392 ${WIN_IPHLPAPI_LIBRARY}
393 ${WIN_WS2_32_LIBRARY}
396 target_include_directories(wsutil SYSTEM
398 ${GLIB2_INCLUDE_DIRS}
399 ${GCRYPT_INCLUDE_DIRS}
400 ${GNUTLS_INCLUDE_DIRS}
402 ${GMODULE2_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"
421 install(FILES ${WSUTIL_PUBLIC_HEADERS}
422 DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil"
423 COMPONENT "Development"
427 add_library(wsutil_static STATIC
431 target_compile_definitions(wsutil_static PRIVATE
436 target_link_libraries(wsutil_static
440 ${GMODULE2_LIBRARIES}
441 ${APPLE_CORE_FOUNDATION_LIBRARY}
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
455 ${GLIB2_INCLUDE_DIRS}
456 ${GCRYPT_INCLUDE_DIRS}
457 ${GNUTLS_INCLUDE_DIRS}
459 ${GMODULE2_INCLUDE_DIRS}
461 ${ZLIBNG_INCLUDE_DIRS}
462 ${PCRE2_INCLUDE_DIRS}
465 if(NOT VCSVERSION_OVERRIDE)
466 add_dependencies(wsutil_static vcs_version)
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
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
484 target_link_libraries(test_wsutil ${GLIB2_LIBRARIES} wsutil)
486 set_target_properties(test_wsutil PROPERTIES
488 EXCLUDE_FROM_DEFAULT_BUILD True
489 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
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
509 # indent-tabs-mode: t
512 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
513 # :indentSize=8:tabSize=8:noTabs=false: