TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / wsutil / CMakeLists.txt
blobb083edfd22c0e9dda574aa4c778ebe71b32ec8d3
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 "${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
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         eax.c
182         failure_message_simple.c
183         feature_list.c
184         filesystem.c
185         filter_files.c
186         g711.c
187         inet_addr.c
188         inet_cidr.c
189         interface.c
190         introspection.c
191         jsmn.c
192         json_dumper.c
193         mpeg-audio.c
194         nstime.c
195         cpu_info.c
196         os_version_info.c
197         please_report_bug.c
198         privileges.c
199         regex.c
200         rsa.c
201         sober128.c
202         socket.c
203         strnatcmp.c
204         str_util.c
205         strtoi.c
206         report_message.c
207         tempfile.c
208         time_util.c
209         to_str.c
210         type_util.c
211         unicode-utils.c
212         version_info.c
213         ws_getopt.c
214         ws_mempbrk.c
215         ws_pipe.c
216         ws_strptime.c
217         wsgcrypt.c
218         wsjson.c
219         wslog.c
220         xtea.c
223 if(WIN32)
224         list(APPEND WSUTIL_COMMON_FILES
225                 console_win32.c
226         )
227 endif()
229 if(ENABLE_PLUGINS)
230         list(APPEND WSUTIL_COMMON_FILES
231                 plugins.c
232         )
233 endif()
235 set(WSUTIL_FILES
236         ${WMEM_FILES}
237         ${WSUTIL_COMMON_FILES}
240 if(WIN32)
241         list(APPEND WSUTIL_FILES
242                 file_util.c
243                 win32-utils.c
244         )
245 endif(WIN32)
248 if(HAVE_MACOS_FRAMEWORKS)
249         list(APPEND WSUTIL_FILES cfutils.c)
250 endif()
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)
263         set(SSE4_2_FLAG "")
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")
268         else()
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")
272                 endif()
273         endif()
274 else()
275         set(COMPILE_CAN_HANDLE_SSE4_2 FALSE)
276         set(SSE4_2_FLAG "")
277 endif()
279 if(SSE4_2_FLAG)
280         message(STATUS "SSE4.2 compiler flag: ${SSE4_2_FLAG}")
281 else()
282         message(STATUS "No SSE4.2 compiler flag enabled")
283 endif()
284 if(COMPILER_CAN_HANDLE_SSE4_2)
285         #
286         # Make sure we have the necessary headers for the SSE4.2 intrinsics
287         # and that we can use them.
288         #
289         # First, check whether we have emmintrin.h and can use it
290         # *without* the SSE 4.2 flag.
291         #
292         check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
294         #
295         # OK, if that works, see whether we have nmmintrin.h and
296         # can use it *with* the SSE 4.2 flag.
297         #
298         if(EMMINTRIN_H_WORKS)
299                 #
300                 # Does this add the SSE4.2 flags to the beginning of
301                 # CFLAGS?
302                 #
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).
310                 #
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()
315         endif()
316 endif()
317 if(HAVE_SSE4_2)
318         list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
319 endif()
321 if(APPLE)
322         #
323         # We assume that APPLE means macOS so that we have the macOS
324         # frameworks.
325         #
326         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
327 endif()
329 set_source_files_properties(
330         ${WSUTIL_FILES}
331         PROPERTIES
332         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
335 if (HAVE_SSE4_2)
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(
339                 ws_mempbrk_sse42.c
340                 PROPERTIES
341                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
342         )
343 endif()
345 if (ENABLE_APPLICATION_BUNDLE)
346         set_source_files_properties(
347                 filesystem.c
348                 PROPERTIES
349                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} -DENABLE_APPLICATION_BUNDLE"
351 endif()
353 add_library(wsutil
354         ${WSUTIL_FILES}
355         ${CMAKE_BINARY_DIR}/resources/libwsutil.rc
358 if(NOT VCSVERSION_OVERRIDE)
359         add_dependencies(wsutil vcs_version)
360 endif()
362 target_compile_definitions(wsutil PRIVATE
363         WS_BUILD_DLL
364         BUILD_WSUTIL
367 set_target_properties(wsutil PROPERTIES
368         PREFIX "lib"
369         LINK_FLAGS "${WS_LINK_FLAGS}"
370         VERSION "0.0.0" SOVERSION 0
371         FOLDER "DLLs"
372         INSTALL_RPATH "${LIBRARY_INSTALL_RPATH}"
374 if(MSVC)
375         set_target_properties(wsutil PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
376 endif()
378 target_link_libraries(wsutil
379         PUBLIC
380                 ${GLIB2_LIBRARIES}
381         PRIVATE
382                 ${GMODULE2_LIBRARIES}
383                 ${APPLE_CORE_FOUNDATION_LIBRARY}
384                 ${CMAKE_DL_LIBS}
385                 ${GCRYPT_LIBRARIES}
386                 ${GNUTLS_LIBRARIES}
387                 ${M_LIBRARIES}
388                 ${ZLIB_LIBRARIES}
389                 ${ZLIBNG_LIBRARIES}
390                 $<IF:$<CONFIG:Debug>,${PCRE2_DEBUG_LIBRARIES},${PCRE2_LIBRARIES}>
391                 ${WIN_IPHLPAPI_LIBRARY}
392                 ${WIN_WS2_32_LIBRARY}
395 target_include_directories(wsutil SYSTEM
396         PUBLIC
397                 ${GLIB2_INCLUDE_DIRS}
398                 ${GCRYPT_INCLUDE_DIRS}
399                 ${GNUTLS_INCLUDE_DIRS}
400         PRIVATE
401                 ${GMODULE2_INCLUDE_DIRS}
402                 ${ZLIB_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"
417         EXCLUDE_FROM_ALL
420 install(FILES ${WSUTIL_PUBLIC_HEADERS}
421         DESTINATION "${PROJECT_INSTALL_INCLUDEDIR}/wsutil"
422         COMPONENT "Development"
423         EXCLUDE_FROM_ALL
426 add_library(wsutil_static STATIC
427         ${WSUTIL_FILES}
430 target_compile_definitions(wsutil_static PRIVATE
431         ENABLE_STATIC
432         BUILD_WSUTIL
435 target_link_libraries(wsutil_static
436         PUBLIC
437                 ${GLIB2_LIBRARIES}
438         PRIVATE
439                 ${GMODULE2_LIBRARIES}
440                 ${APPLE_CORE_FOUNDATION_LIBRARY}
441                 ${CMAKE_DL_LIBS}
442                 ${GCRYPT_LIBRARIES}
443                 ${GNUTLS_LIBRARIES}
444                 ${ZLIB_LIBRARIES}
445                 ${ZLIBNG_LIBRARIES}
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
452         PUBLIC
453                 ${GLIB2_INCLUDE_DIRS}
454                 ${GCRYPT_INCLUDE_DIRS}
455                 ${GNUTLS_INCLUDE_DIRS}
456         PRIVATE
457                 ${GMODULE2_INCLUDE_DIRS}
458                 ${ZLIB_INCLUDE_DIRS}
459                 ${ZLIBNG_INCLUDE_DIRS}
460                 ${PCRE2_INCLUDE_DIRS}
463 if(NOT VCSVERSION_OVERRIDE)
464         add_dependencies(wsutil_static vcs_version)
465 endif()
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
472         FOLDER "Tests"
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
479         test_wsutil.c
482 target_link_libraries(test_wsutil ${GLIB2_LIBRARIES} wsutil)
484 set_target_properties(test_wsutil PROPERTIES
485         FOLDER "Tests"
486         EXCLUDE_FROM_DEFAULT_BUILD True
487         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
490 CHECKAPI(
491         NAME
492           wsutil
493         SWITCHES
494         SOURCES
495           ${WMEM_FILES}
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
504 # Local variables:
505 # c-basic-offset: 8
506 # tab-width: 8
507 # indent-tabs-mode: t
508 # End:
510 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
511 # :indentSize=8:tabSize=8:noTabs=false: