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 "${LOG_EXTCAP_INSTALL_LIBDIR}" PATH_LOG_EXTCAP_DIR)
26 string(REPLACE "\\" "\\\\" PATH_LOG_EXTCAP_DIR "${PATH_LOG_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
182 failure_message_simple.c
224 list(APPEND WSUTIL_COMMON_FILES
230 list(APPEND WSUTIL_COMMON_FILES
237 ${WSUTIL_COMMON_FILES}
241 list(APPEND WSUTIL_FILES
248 if(HAVE_MACOS_FRAMEWORKS)
249 list(APPEND WSUTIL_FILES cfutils.c)
253 # XXX - we're assuming MSVC doesn't require a flag to enable SSE 4.2
254 # support, and that, if the compiler supports a flag for SSE 4.2
255 # support, the intrinsics are supported iff we can include the
256 # <nmmintrin.h> flag.
258 # We only check for the GCC-style -msse4.2 flag and the Sun C
259 # -xarch=sse4_2 flag.
261 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
262 set(COMPILER_CAN_HANDLE_SSE4_2 TRUE)
264 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686|x86|x86_64|AMD64")
265 check_c_compiler_flag(-msse4.2 COMPILER_CAN_HANDLE_SSE4_2)
266 if(COMPILER_CAN_HANDLE_SSE4_2)
267 set(SSE4_2_FLAG "-msse4.2")
269 check_c_compiler_flag(-xarch=sse4_2 COMPILER_CAN_HANDLE_SSE4_2)
270 if(COMPILER_CAN_HANDLE_SSE4_2)
271 set(SSE4_2_FLAG "-xarch=sse4_2")
275 set(COMPILE_CAN_HANDLE_SSE4_2 FALSE)
280 message(STATUS "SSE4.2 compiler flag: ${SSE4_2_FLAG}")
282 message(STATUS "No SSE4.2 compiler flag enabled")
284 if(COMPILER_CAN_HANDLE_SSE4_2)
286 # Make sure we have the necessary headers for the SSE4.2 intrinsics
287 # and that we can use them.
289 # First, check whether we have emmintrin.h and can use it
290 # *without* the SSE 4.2 flag.
292 check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
295 # OK, if that works, see whether we have nmmintrin.h and
296 # can use it *with* the SSE 4.2 flag.
298 if(EMMINTRIN_H_WORKS)
300 # Does this add the SSE4.2 flags to the beginning of
303 # Note that if there's a mix of "enable SSE 4.2" and
304 # "disable SSE 4.2" flags, this may not indicate that
305 # we can use the header. That's not a bug, that's a
306 # feature; the other flags may have been forced by
307 # the build process, e.g. in Gentoo Linux, and we want
308 # to check this with whatever flags will actually be
309 # used when building (see bug 10792).
311 cmake_push_check_state()
312 set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
313 check_include_file("nmmintrin.h" HAVE_SSE4_2)
314 cmake_pop_check_state()
318 list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
323 # We assume that APPLE means macOS so that we have the macOS
326 FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
329 set_source_files_properties(
332 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
336 # TODO with CMake 2.8.12, we could use COMPILE_OPTIONS and just append
337 # instead of this COMPILE_FLAGS duplication...
338 set_source_files_properties(
341 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
345 if (ENABLE_APPLICATION_BUNDLE)
346 set_source_files_properties(
349 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} -DENABLE_APPLICATION_BUNDLE"
355 ${CMAKE_BINARY_DIR}/resources/libwsutil.rc
358 if(NOT VCSVERSION_OVERRIDE)
359 add_dependencies(wsutil vcs_version)
362 target_compile_definitions(wsutil PRIVATE
367 set_target_properties(wsutil PROPERTIES
369 LINK_FLAGS "${WS_LINK_FLAGS}"
370 VERSION "0.0.0" SOVERSION 0
372 INSTALL_RPATH "${LIBRARY_INSTALL_RPATH}"
375 set_target_properties(wsutil PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
378 target_link_libraries(wsutil
382 ${GMODULE2_LIBRARIES}
383 ${APPLE_CORE_FOUNDATION_LIBRARY}
390 $<IF:$<CONFIG:Debug>,${PCRE2_DEBUG_LIBRARIES},${PCRE2_LIBRARIES}>
391 ${WIN_IPHLPAPI_LIBRARY}
392 ${WIN_WS2_32_LIBRARY}
395 target_include_directories(wsutil SYSTEM
397 ${GLIB2_INCLUDE_DIRS}
398 ${GCRYPT_INCLUDE_DIRS}
399 ${GNUTLS_INCLUDE_DIRS}
401 ${GMODULE2_INCLUDE_DIRS}
403 ${ZLIBNG_INCLUDE_DIRS}
404 ${PCRE2_INCLUDE_DIRS}
407 install(TARGETS wsutil
408 EXPORT WiresharkTargets
409 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
410 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
411 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
414 install(FILES ${WMEM_PUBLIC_HEADERS}
415 DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil/wmem"
416 COMPONENT "Development"
420 install(FILES ${WSUTIL_PUBLIC_HEADERS}
421 DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil"
422 COMPONENT "Development"
426 add_library(wsutil_static STATIC
430 target_compile_definitions(wsutil_static PRIVATE
435 target_link_libraries(wsutil_static
439 ${GMODULE2_LIBRARIES}
440 ${APPLE_CORE_FOUNDATION_LIBRARY}
446 $<IF:$<CONFIG:Debug>,${PCRE2_DEBUG_LIBRARIES},${PCRE2_LIBRARIES}>
447 ${WIN_IPHLPAPI_LIBRARY}
448 ${WIN_WS2_32_LIBRARY}
451 target_include_directories(wsutil_static SYSTEM
453 ${GLIB2_INCLUDE_DIRS}
454 ${GCRYPT_INCLUDE_DIRS}
455 ${GNUTLS_INCLUDE_DIRS}
457 ${GMODULE2_INCLUDE_DIRS}
459 ${ZLIBNG_INCLUDE_DIRS}
460 ${PCRE2_INCLUDE_DIRS}
463 if(NOT VCSVERSION_OVERRIDE)
464 add_dependencies(wsutil_static vcs_version)
467 add_executable(wmem_test EXCLUDE_FROM_ALL wmem/wmem_test.c ${WMEM_FILES})
469 target_link_libraries(wmem_test wsutil)
471 set_target_properties(wmem_test PROPERTIES
473 EXCLUDE_FROM_DEFAULT_BUILD True
474 COMPILE_DEFINITIONS "WS_BUILD_DLL"
475 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
478 add_executable(test_wsutil EXCLUDE_FROM_ALL
482 target_link_libraries(test_wsutil ${GLIB2_LIBRARIES} wsutil)
484 set_target_properties(test_wsutil PROPERTIES
486 EXCLUDE_FROM_DEFAULT_BUILD True
487 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
496 ${WSUTIL_COMMON_FILES}
499 set_source_files_properties(jsmn.c PROPERTIES COMPILE_DEFINITIONS "JSMN_STRICT")
502 # Editor modelines - https://www.wireshark.org/tools/modelines.html
507 # indent-tabs-mode: t
510 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
511 # :indentSize=8:tabSize=8:noTabs=false: