forked from wireshark/wireshark
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
4521 lines (4151 loc) · 152 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# CMakeLists.txt
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <[email protected]>
# Copyright 1998 Gerald Combs
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
if(DEFINED ENV{FORCE_CMAKE_NINJA_NON_VERBOSE})
#
# Forcibly unset CMAKE_VERBOSE_MAKEFILE,
# to make *CERTAIN* that we don't do
# anything verbose here!
#
unset(CMAKE_VERBOSE_MAKEFILE CACHE)
endif()
# https://doc.qt.io/qt-6/cmake-supported-cmake-versions.html
cmake_minimum_required(VERSION 3.16)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
if(WIN32 AND NOT DEFINED ENV{MSYSTEM})
set(_project_name Wireshark)
set(_log_project_name Stratoshark)
else()
set(_project_name wireshark)
set(_log_project_name stratoshark)
endif()
project(${_project_name} C CXX)
if(WIN32)
set(_msystem False)
set(_repository False)
if(DEFINED ENV{MSYSTEM})
set(_msystem $ENV{MSYSTEM})
message(STATUS "Using MSYS2 with MSYSTEM=${_msystem}")
elseif(MSVC)
set(_repository True)
message(STATUS "Using 3rd party repository")
else()
# Neither own package repository nor MSYS2 repository.
endif()
set(USE_MSYSTEM ${_msystem} CACHE INTERNAL "Use MSYS2 subsystem")
set(HAVE_MSYSTEM ${USE_MSYSTEM}) # For config.h
set(USE_REPOSITORY ${_repository} CACHE INTERNAL "Use Wireshark 3rd Party Repository")
endif()
# Updated by tools/make-version.py
set(PROJECT_MAJOR_VERSION 4)
set(PROJECT_MINOR_VERSION 5)
set(PROJECT_PATCH_VERSION 0)
set(PROJECT_BUILD_VERSION 0)
set(PROJECT_VERSION_EXTENSION "")
if(DEFINED ENV{WIRESHARK_VERSION_EXTRA})
set(PROJECT_VERSION_EXTENSION "$ENV{WIRESHARK_VERSION_EXTRA}")
endif()
set(PROJECT_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
set(LOG_PROJECT_NAME ${_log_project_name})
set(LOG_PROJECT_MAJOR_VERSION 0)
set(LOG_PROJECT_MINOR_VERSION 9)
set(LOG_PROJECT_PATCH_VERSION 0)
set(LOG_PROJECT_VERSION "${LOG_PROJECT_MAJOR_VERSION}.${LOG_PROJECT_MINOR_VERSION}.${LOG_PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
include( CMakeOptions.txt )
# We require minimum C11
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# We require minimum C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
if(USE_MSYSTEM)
# Prevent FindPython3.cmake from using the Python path in the registry,
# only use the $PATH environment variable (which is set up for MSYS2).
set(Python3_FIND_REGISTRY NEVER)
endif()
find_package(Python3 3.6 REQUIRED)
# Set a default build type if none was specified
set(_default_build_type "RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "${_default_build_type}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Build type is ignored by multi-config generators.
if (NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Using \"${CMAKE_GENERATOR}\" generator and build type \"${CMAKE_BUILD_TYPE}\"")
else()
message(STATUS "Using \"${CMAKE_GENERATOR}\" generator (multi-config)")
endif()
#Where to find local cmake scripts
set(WS_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
set(CMAKE_MODULE_PATH ${WS_CMAKE_MODULE_PATH})
# CMake >= 3.9.0 supports LTO/IPO.
if (ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported OUTPUT lto_output)
if(lto_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
message(STATUS "LTO/IPO is enabled for Release configuration")
else()
message(STATUS "LTO/IPO requested but it is not supported by the compiler: ${lto_output}")
endif()
else()
message(STATUS "LTO/IPO is not enabled")
endif()
# If our target platform is enforced by our generator, set
# WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
# %WIRESHARK_TARGET_PLATFORM%.
if(WIN32)
if(DEFINED ENV{WIRESHARK_TARGET_PLATFORM})
string(TOLOWER $ENV{WIRESHARK_TARGET_PLATFORM} _target_platform)
set(WIRESHARK_TARGET_PLATFORM ${_target_platform})
elseif(USE_MSYSTEM MATCHES "MINGW64|CLANG64|UCRT64")
# https://www.msys2.org/docs/environments
# MSYS2 comes with different environments/subsystems and
# the first thing you have to decide is which one to use.
# The differences among the environments are mainly environment
# variables, default compilers/linkers, architecture,
# system libraries used etc. If you are unsure, go with UCRT64.
set(WIRESHARK_TARGET_PLATFORM x64)
elseif(USE_MSYSTEM)
if($ENV{MSYSTEM_CARCH} MATCHES "x86_64")
set(WIRESHARK_TARGET_PLATFORM x64)
elseif($ENV{MSYSTEM_CARCH} MATCHES "i686")
set(WIRESHARK_TARGET_PLATFORM win32)
elseif($ENV{MSYSTEM_CARCH} MATCHES "aarch64")
set(WIRESHARK_TARGET_PLATFORM "arm64")
else()
set(WIRESHARK_TARGET_PLATFORM "$ENV{MSYSTEM_CARCH}")
endif()
elseif($ENV{Platform} MATCHES arm64 OR CMAKE_GENERATOR_PLATFORM MATCHES arm64)
set(WIRESHARK_TARGET_PLATFORM arm64)
elseif(CMAKE_CL_64 OR CMAKE_GENERATOR MATCHES x64)
set(WIRESHARK_TARGET_PLATFORM x64)
else()
message(WARNING "Assuming \"x64\" target platform")
set(WIRESHARK_TARGET_PLATFORM x64)
endif()
if(WIRESHARK_TARGET_PLATFORM MATCHES "win32")
message(FATAL_ERROR "Deprecated target platform ${WIRESHARK_TARGET_PLATFORM}. See https://gitlab.com/wireshark/wireshark/-/issues/17779 for details.")
elseif(NOT (WIRESHARK_TARGET_PLATFORM MATCHES "x64" OR WIRESHARK_TARGET_PLATFORM MATCHES "arm64"))
message(FATAL_ERROR "Invalid target platform: ${WIRESHARK_TARGET_PLATFORM}")
endif()
# Sanity check
if(MSVC AND DEFINED ENV{PLATFORM})
string(TOLOWER $ENV{PLATFORM} _vs_platform)
if(
(_vs_platform STREQUAL "x64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "x64")
OR
(_vs_platform STREQUAL "arm64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "arm64")
)
message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
" doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
endif()
endif()
message(STATUS
"Building for ${WIRESHARK_TARGET_PLATFORM}"
)
if(NOT CMAKE_CROSSCOMPILING)
find_package(PowerShell REQUIRED)
endif()
# Determine where the 3rd party libraries will be
if(USE_REPOSITORY)
if( DEFINED ENV{WIRESHARK_LIB_DIR} )
# The buildbots set WIRESHARK_LIB_DIR but not WIRESHARK_BASE_DIR.
file( TO_CMAKE_PATH "$ENV{WIRESHARK_LIB_DIR}" _PROJECT_LIB_DIR )
elseif( DEFINED ENV{WIRESHARK_BASE_DIR} )
file( TO_CMAKE_PATH "$ENV{WIRESHARK_BASE_DIR}" _WS_BASE_DIR )
set( _PROJECT_LIB_DIR "${_WS_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs" )
else()
# Don't know what to do
message(FATAL_ERROR "Neither WIRESHARK_BASE_DIR or WIRESHARK_LIB_DIR are defined")
endif()
# Download third-party libraries
file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/win-setup.ps1 _win_setup)
file (TO_NATIVE_PATH ${_PROJECT_LIB_DIR} _ws_lib_dir)
file (TO_NATIVE_PATH ${CMAKE_COMMAND} _win_cmake_command)
# Is it possible to have a one-time, non-cached option in CMake? If
# so, we could add a "-DFORCE_WIN_SETUP" which passes -Force to
# win-setup.ps1.
execute_process(
COMMAND ${POWERSHELL_COMMAND} "\"${_win_setup}\"" -Destination "${_ws_lib_dir}" -Platform ${WIRESHARK_TARGET_PLATFORM} -CMakeExecutable "\"${_win_cmake_command}\""
RESULT_VARIABLE _win_setup_failed
ERROR_VARIABLE _win_setup_error_output
)
if(_win_setup_failed)
message(FATAL_ERROR "Windows setup (win-setup.ps1) failed: ${_win_setup_error_output}.")
endif()
set(EXTRA_INSTALLER_DIR ${_ws_lib_dir})
# XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
else()
set(EXTRA_INSTALLER_DIR ${CMAKE_BINARY_DIR}/packaging/nsis)
endif()
include(FetchContent)
set(LIBS_URL "https://dev-libs.wireshark.org/windows/packages")
file(TO_CMAKE_PATH ${EXTRA_INSTALLER_DIR} _file_download_dir)
# Download Npcap required by the Windows installer
set(NPCAP_VERSION "1.80")
set(NPCAP_SHA256 "ac4f26d7d9f994d6f04141b2266f02682def51af63c09c96a7268552c94a6535")
set(NPCAP_FILENAME "npcap-${NPCAP_VERSION}.exe")
set(NPCAP_URL "${LIBS_URL}/Npcap/${NPCAP_FILENAME}")
FetchContent_Declare(Npcap
URL ${NPCAP_URL}
DOWNLOAD_DIR ${_file_download_dir}
URL_HASH SHA256=${NPCAP_SHA256}
DOWNLOAD_NO_EXTRACT True
)
# Download USBPcap required by the Windows installer
set(USBPCAP_VERSION "1.5.4.0")
set(USBPCAP_SHA256 "87a7edf9bbbcf07b5f4373d9a192a6770d2ff3add7aa1e276e82e38582ccb622")
set(USBPCAP_FILENAME "USBPcapSetup-${USBPCAP_VERSION}.exe")
set(USBPCAP_URL "${LIBS_URL}/USBPcap/${USBPCAP_FILENAME}")
FetchContent_Declare(USBPcap
URL ${USBPCAP_URL}
DOWNLOAD_DIR ${_file_download_dir}
URL_HASH SHA256=${USBPCAP_SHA256}
DOWNLOAD_NO_EXTRACT True
)
endif(WIN32)
include(UseCustomIncludes)
ADD_CUSTOM_CMAKE_INCLUDE()
# Ensure that all executables and libraries end up in the same directory. Actual
# files might end up in a configuration subdirectory, e.g. run/Debug or
# run/Release. We try to set DATAFILE_DIR to actual location below.
if(NOT ARCHIVE_OUTPUT_PATH)
set(ARCHIVE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
"Single output directory for building all archives.")
endif()
if(NOT EXECUTABLE_OUTPUT_PATH)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
"Single output directory for building all executables.")
endif()
if(NOT LIBRARY_OUTPUT_PATH)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
"Single output directory for building all libraries.")
endif()
#
# The release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG for
# the Unix Makefile generator.
#
# Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
if(WIN32 AND NOT USE_MSYSTEM)
# Override some values on Windows, to match the existing
# convention of installing everything to a single root folder.
set(CMAKE_INSTALL_BINDIR ".")
set(CMAKE_INSTALL_LIBDIR ".")
set(CMAKE_INSTALL_INCLUDEDIR "include")
set(CMAKE_INSTALL_DATADIR ".")
set(CMAKE_INSTALL_DOCDIR ".")
endif()
include(GNUInstallDirs)
set(PROJECT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
# Make sure our executables can load our libraries if we install into
# a non-default directory on Unix-like systems other than macOS.
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
set(LIBRARY_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}")
set(EXECUTABLE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}")
set(EXTCAP_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}")
if(NOT (WIN32 OR APPLE OR USE_STATIC))
# Try to set a RPATH for installed binaries if the library directory is
# not already included in the default search list.
list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
if(IS_SYSTEM_DIR EQUAL -1)
# Some systems support $ORIGIN in RPATH to enable relocatable
# binaries. In other cases, only absolute paths can be used.
# https://www.lekensteyn.nl/rpath.html
#
# Also note that some systems (notably those using GNU libc)
# silently ignore $ORIGIN in RPATH for binaries that are
# setuid root or use privileged capabilities.
#
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
set(_enable_rpath_origin TRUE)
else()
set(_enable_rpath_origin FALSE)
endif()
# Provide a knob to optionally force absolute rpaths,
# to support old/buggy systems and as a user preference
# for hardening.
# XXX Should this be a CMake option?
set(ENABLE_RPATH_ORIGIN ${_enable_rpath_origin} CACHE BOOL
"Use $ORIGIN with INSTALL_RPATH")
mark_as_advanced(ENABLE_RPATH_ORIGIN)
if(ENABLE_RPATH_ORIGIN)
set(LIBRARY_INSTALL_RPATH "$ORIGIN")
set(EXECUTABLE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
set(EXTCAP_INSTALL_RPATH "$ORIGIN/../..")
else()
set(LIBRARY_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
set(EXECUTABLE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
set(EXTCAP_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
# Include non-standard external libraries by default in RPATH.
if(NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
endif()
endif()
# Ensure that executables in the build directory always have the same RPATH.
# This ensures relocatable binaries and reproducible builds (invariant of the
# build directory location). (Requires CMake 3.14)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
if(MSVC)
# Linking with wsetargv.obj enables "wildcard expansion" of
# command-line arguments.
set(WILDCARD_OBJ wsetargv.obj)
endif()
include(CheckSymbolExists)
#
# Large file support on UN*X, a/k/a LFS.
#
# On Windows, we require _fseeki64() and _ftelli64(). Visual
# Studio has had supported them since Visual Studio 2005/MSVCR80,
# and we require newer versions, so we know we have them.
#
if(NOT MSVC)
include(FindLFS)
if(LFS_FOUND)
#
# Add the required #defines.
#
add_definitions(${LFS_DEFINITIONS})
endif()
#
# Check for fseeko as well.
#
include(FindFseeko)
if(FSEEKO_FOUND)
set(HAVE_FSEEKO ON)
#
# Add the required #defines.
#
add_definitions(${FSEEKO_DEFINITIONS})
endif()
endif()
# Banner shown at top right of Qt welcome screen.
if(DEFINED ENV{WIRESHARK_VERSION_FLAVOR})
set(VERSION_FLAVOR "$ENV{WIRESHARK_VERSION_FLAVOR}")
else()
set(VERSION_FLAVOR "Development Build")
endif()
# Used in .rc files and manifests
set(MANIFEST_PROCESSOR_ARCHITECTURE ${WIRESHARK_TARGET_PLATFORM})
if (MANIFEST_PROCESSOR_ARCHITECTURE MATCHES "x64")
set(MANIFEST_PROCESSOR_ARCHITECTURE "amd64")
endif()
set(RC_VERSION ${PROJECT_MAJOR_VERSION},${PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
set(LOG_RC_VERSION ${LOG_PROJECT_MAJOR_VERSION},${LOG_PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
include(UseLemon)
include(UseMakePluginReg)
include(UseMakeTaps)
include(UseExecutableResources)
include(UseAsn2Wrs)
# The following snippet has been taken from
# https://github.com/USESystemEngineeringBV/cmake-eclipse-helper/wiki/HowToWorkaroundIndexer
# The eclipse indexer otherwise assumes __cplusplus=199711L which will lead to broken
# lookup tables for the epan libraries
# Check if CXX flags have been set to c++11 -> Setup Eclipse Indexer correctly!
# Also setup the project slightly different
if(CMAKE_EXTRA_GENERATOR MATCHES "Eclipse CDT4")
SET(CXX_ENABLED 0)
LIST(LENGTH CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS LIST_LEN)
if(LIST_LEN GREATER 0)
SET(CXX_ENABLED 1)
endif()
SET(C_ENABLED 0)
LIST(LENGTH CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS LIST_LEN)
if(LIST_LEN GREATER 0)
SET(C_ENABLED 1)
endif()
if(C_ENABLED EQUAL 1 AND CXX_ENABLED EQUAL 1)
# Combined project (C and CXX). This will confuse the indexer. For that reason
# we unsert set the __cplusplus variable for the indexer
list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "__cplusplus" GEN_MACRO_INDEX)
if(GEN_MACRO_INDEX GREATER -1)
list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
endif()
SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
elseif((CXX_ENABLED EQUAL 1) AND (CMAKE_CXX_FLAGS MATCHES ".*-std=c\\+\\+11.*"))
#add_definitions (-D__cplusplus=201103L)
# CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS
list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "199711L" GEN_MACRO_INDEX)
if(GEN_MACRO_INDEX GREATER -1)
list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
list(INSERT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX} "201103L")
SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
endif()
endif()
endif()
include_directories(
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include
)
if( DUMPCAP_INSTALL_OPTION STREQUAL "suid" )
set( DUMPCAP_SETUID "SETUID" )
else()
set( DUMPCAP_SETUID )
endif()
if( NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
DUMPCAP_INSTALL_OPTION STREQUAL "capabilities" )
message( WARNING "Capabilities are only supported on Linux" )
set( DUMPCAP_INSTALL_OPTION )
endif()
set(OSS_FUZZ OFF CACHE BOOL "Whether building for oss-fuzz")
mark_as_advanced(OSS_FUZZ)
if(OSS_FUZZ)
if(ENABLE_FUZZER)
# In oss-fuzz mode, the fuzzing engine can be afl or libFuzzer.
message(FATAL_ERROR "Cannot force libFuzzer when using oss-fuzz")
endif()
# Must not depend on external dependencies so statically link all libs.
set(USE_STATIC ON)
endif()
if(USE_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
#
# Linking can consume a lot of memory, especially when built with ASAN and
# static libraries (like oss-fuzz) or Debug mode. With Ninja, the number of
# parallel linker processes is constrained by job parallelism (-j), but this can
# be reduced further by setting "job pools" to a lower number.
#
if(CMAKE_MAKE_PROGRAM MATCHES "ninja" AND OSS_FUZZ)
# Assume oss-fuzz linker jobs do not require more than 1.2G per task
set(per_job_memory_mb 1200)
cmake_host_system_information(RESULT total_memory_mb QUERY TOTAL_PHYSICAL_MEMORY)
math(EXPR parallel_link_jobs "${total_memory_mb} / ${per_job_memory_mb}")
if(parallel_link_jobs LESS 1)
set(parallel_link_jobs 1)
endif()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${parallel_link_jobs})
set(CMAKE_JOB_POOL_LINK link_job_pool)
message(STATUS "Ninja job pool size: ${parallel_link_jobs}")
endif()
# Always enable position-independent code when compiling, even for
# executables, so you can build position-independent executables.
# -pie is added below for non-MSVC, but requires objects to be built with
# -fPIC/-fPIE (so set CMAKE_POSITION_INDEPENDENT_CODE to enable that).
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Preprocessor definitions common to all compilers
set_property(DIRECTORY
PROPERTY COMPILE_DEFINITIONS
"G_DISABLE_DEPRECATED"
"G_DISABLE_SINGLE_INCLUDES"
$<$<OR:$<BOOL:${ENABLE_DEBUG}>,$<CONFIG:Debug>>:WS_DEBUG>
$<$<OR:$<AND:$<BOOL:${ENABLE_DEBUG}>,$<BOOL:${ENABLE_DEBUG_UTF_8}>>,$<CONFIG:Debug>>:WS_DEBUG_UTF_8>
$<$<BOOL:${ENABLE_ASSERT}>:ENABLE_ASSERT>
)
if(WIN32)
#
# NOTE: Because of the way Qt moc is including "config.h" (not as the
# first header) this *MUST* be defined on the command line to precede
# every included header and not trigger symbol redefinition errors.
#
add_definitions(
-DWIN32_LEAN_AND_MEAN
#
# Use Unicode in Windows runtime functions.
#
-DUNICODE
-D_UNICODE
#
# NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
# This avoids conflicts with the C++ standard library.
#
-DNOMINMAX
)
endif()
if(MINGW)
add_definitions(
#
# Enable POSIX APIs. This will switch stdio to ANSI C functions and
# enable C99 conformant vsnprintf() among other things.
#
-D_POSIX
)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_POSIX)
endif()
if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
if (MSVC_VERSION LESS "1928")
message(FATAL_ERROR "Microsoft Visual Studio 2019 version 16.8 or later is required")
endif()
if (MSVC_VERSION GREATER_EQUAL "2000")
message(FATAL_ERROR "You are using an unsupported version of MSVC")
endif()
add_definitions(
/D_CRT_SECURE_NO_DEPRECATE
# -DPSAPI_VERSION=1 Programs that must run on earlier versions of Windows as well as Windows 7 and later
# versions should always call this function as GetProcessMemoryInfo. To ensure correct
# resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program
# with -DPSAPI_VERSION=1.To use run-time dynamic linking, load Psapi.dll.
# https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
# -D_ALLOW_KEYWORD_MACROS For VS2012 onwards the, C++ STL does not permit macro redefinitions of keywords
# (see https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/bb531344(v=vs.110))
# This definition prevents the complaint about the redefinition of inline by WinPCap
# in pcap-stdinc.h when compiling C++ files, e.g. the Qt UI
/DPSAPI_VERSION=1
/D_ALLOW_KEYWORD_MACROS
# Disable deprecation of POSIX function names.
# https://stackoverflow.com/questions/37845163/what-is-the-purpose-of-microsofts-underscore-c-functions
/D_CRT_NONSTDC_NO_WARNINGS
)
if(NOT WIRESHARK_TARGET_PLATFORM STREQUAL "x64")
add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
endif()
# TODO: Re-enable /W3. It was disabled for a year and some warnings crept
# in that will fail with /Wx.
set(LOCAL_CFLAGS
/MP
/W3
)
set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
# To do: Add /external:... See https://devblogs.microsoft.com/cppblog/broken-warnings-theory/
#
# /diagnostics:caret Place a caret under compilation issues similar to
# Clang and gcc.
# /Zo Enhanced debugging of optimised code
# /utf-8 Set Source and Executable character sets to UTF-8
# VS2015(MSVC14): On by default when /Zi or /Z7 used.
# /guard:cf Control Flow Guard (compile and link).
# See https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard
# Note: This requires CMake 3.9.0 or newer.
# https://gitlab.kitware.com/cmake/cmake/commit/f973d49ab9d4c59b93f6dac812a94bb130200836
# /Qspectre Speculative execution attack mitigation
# See https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
list(APPEND LOCAL_CFLAGS /diagnostics:caret /Zo /utf-8 /guard:cf)
set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /guard:cf")
set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /STACK:0x800000")
# /Qspectre depends on the optional "Microsoft.VisualStudio.Component...Spectre" components,
# so we need to test for its availability.
set(WIRESHARK_COMMON_FLAGS /Qspectre)
if(ENABLE_CODE_ANALYSIS)
# We should probably add a code_analysis.props file and use it to set
# CAExcludePath, otherwise we trigger on Qt's headers:
# https://stackoverflow.com/questions/59669026/how-to-add-property-to-affect-code-analysis-in-cmake
# https://gitlab.kitware.com/cmake/cmake/-/issues/19682
# For now, we set CAExcludePath=C:\Qt;%include% in the Visual Studio
# Code Analys builder's environment.
list(APPEND LOCAL_CFLAGS
/analyze:WX-
/analyze:log:format:sarif
)
endif()
# Additional compiler warnings to be treated as "Level 3"
# when compiling Wireshark sources. (Selected from "level 4" warnings).
## 4295: array is too small to include a terminating null character
## 4100: unreferenced formal parameter
## 4189: local variable is initialized but not referenced
# Disable warnings about use of flexible array members:
## 4200: nonstandard extension used : zero-sized array in struct/union
list(APPEND LOCAL_CFLAGS /w34295 /w34100 /w34189 /wd4200)
# MSVC 14.28 + C11 enables C5105, but older Windows SDKs aren't completely compatible.
# Windows SDK 10.0.17763.0 generates syntax errors with C11 enabled.
# The variable CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION does not work with the Ninja generator. Presumably it requires a VS generator.
if (CMAKE_GENERATOR MATCHES "Visual Studio")
if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.18362.0)
message(FATAL_ERROR "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} doesn't support C11. Please make sure you're using 10.0.20348.0 or later.")
endif()
# Windows SDK 10.0.18362.0 to 10.0.19041.685 generate warning C5105 with C11 enabled.
if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.20348.0)
message(WARNING "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} doesn't support C11. Please make sure you're using 10.0.20348.0 or later.")
## 5105: macro expansion producing 'defined' has undefined behavior
list(APPEND LOCAL_CFLAGS /wd5105)
endif()
endif()
# We've matched these to specific compiler versions using the
# checks above. There's no need to pass them to check_c_compiler_flag
# or check_cxx_compiler_flag, which can be slow.
string(REPLACE ";" " " _flags "${LOCAL_CFLAGS}")
set(CMAKE_C_FLAGS "${_flags} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${_flags} ${CMAKE_CXX_FLAGS}")
else() # ! MSVC
if(APPLE)
# MIN_MACOS_VERSION is used to set LSMinimumSystemVersion
# in Info.plist, so start with something low.
set(MIN_MACOS_VERSION 10.13)
if(CMAKE_OSX_DEPLOYMENT_TARGET)
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
message(FATAL_ERROR "We don't support building for macOS < ${MIN_MACOS_VERSION}")
endif()
set(MIN_MACOS_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
endif()
endif()
#
# NOTE: Adding new warnings is a policy decision that can have far-reaching
# implications for the project and each developers workflow. Modern
# C compilers are on a race to add new warnings, not always sensibly.
# They are opt-in so take a moment to fully consider the implications
# of enabling the latest shiny new warning.
# If in doubt ask on the Wireshark developer list (recommended).
#
list(APPEND WIRESHARK_COMMON_FLAGS
#
### Flags common to C and C++ ###
#
# -O<X> and -g get set by the CMAKE_BUILD_TYPE
-Wall
-Wextra
-Wformat
-Wformat=2
-Wtrampolines # Enable warnings about trampolines that require executable stacks
-Wbidi-chars=any
-Wpointer-arith
-Wformat-security
-fexcess-precision=fast # GCC-only
-Wvla
-Wattributes
-Wpragmas # Clang-only
-Wheader-guard # Clang-only
-Wcomma # Clang-only
-Wshorten-64-to-32 # Clang-only
-Wredundant-decls
-Wunreachable-code # Clang-only
-Wdocumentation # Clang-only
-Wlogical-op # GCC-only
# Run-time protections mechanisms
-fstrict-flex-arrays=3 # Consider a trailing array in a struct as a flexible array if declared as []
-fstack-clash-protection # Increased reliability of stack overflow detection
-fcf-protection=full # Enable control flow protection to counter Return Oriented Programming (ROP) and Jump Oriented Programming (JOP) attacks on many x86 architectures
-mbranch-protection=standard # Enable branch protection to counter Return Oriented Programming (ROP) and Jump Oriented Programming (JOP) attacks on AArch64
-D_GLIBCXX_ASSERTIONS # Precondition checks for C++ standard library calls. Can impact performance.
-fstack-protector-strong # Stack smashing protector
-fno-delete-null-pointer-checks # Force retention of null pointer checks
# The above used to fail on macOS El Capitan clang (see below in PEDANTIC) Does it work now?
-fno-strict-overflow # Defines signed overflow as wrapping on gcc and clang, prevents optimizations that assume overflow never happens
-fno-strict-aliasing # Do not assume strict aliasing
-ftrivial-auto-var-init # Perform trivial auto variable initialization
-fexceptions # Enable exception propagation to harden multi-threaded C code
#
# Disable errors unconditionally for some static analysis warnings
# that are dormant at lower optimizations levels or active only in
# bleeding edge versions of a compiler and possibly also
# prone to false positives and compiler bugs. This is
# a big nuisance because the warning is dormant and a low
# priority target for action. That is very disruptive
# with -Werror enabled (the default on the master branch).
#
#-Wno-error=stringop-overflow=
#
# XXX Now that we have a CI job with Release build type (using
# -O3 optimization level) the dormancy issue should be ameliorated
# so comment out these exceptions to re-evaluate the impact.
#-Wno-error=maybe-uninitialized
#-Wno-error=alloc-size-larger-than=
#
# Updating external dependencies can introduce new deprecations.
# Also fixing new internal deprecations takes time.
# We want to be able to build with -Werror in that case. New
# code should not introduce new deprecations in any case.
#
#-Wno-error=deprecated-declarations
)
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
# Avoid "argument unused during compilation" warnings for
# -fstack-clash-protection and -mbranch-protection=standard
list(APPEND WIRESHARK_COMMON_FLAGS -Qunused-arguments)
endif()
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# _FORTIFY_SOURCE requires -O1 or higher, and the Debug
# build type has no optimization
if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0") OR
(CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0"))
# On some gcc < 12.0, test_compiler_flag will report that
# -D_FORTIFY_SOURCE=3 is valid, but actually trying to compile
# with it will give a warning that it has the same effect as
# -D_FORTIFY_SOURCE=2
list(APPEND WIRESHARK_COMMON_FLAGS
-U_FORTIFY_SOURCE # Run-time buffer overflow detection. For dist like Ubuntu, U_FORTIFY_SOURCE must be input before D_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=3 # Fortify sources with compile- and run-time checks for unsafe libc usage and buffer overflows. Requires -O1 or higher
)
endif()
endif()
# test_compiler_flag doesn't seem to test that a flag is supported on
# a cross-compiled target, only for the native architecture. (Thus
# conversely it does work to verify that -mbranch-protection=standard
# doesn't work on x64 when compiling natively.)
# TODO: Check that this approach works.
#if(NOT CMAKE_CROSSCOMPILING)
# list(APPEND WIRESHARK_COMMON_FLAGS
# -fhardened # Enable pre-determined set of hardening options in GCC. Currently, -fhardened is only supported on GNU/Linux targets
# )
#endif()
if((NOT ENABLE_ASAN) AND (NOT ENABLE_TSAN) AND (NOT ENABLE_UBSAN) AND (NOT DISABLE_FRAME_LARGER_THAN_WARNING))
#
# Only do this if none of ASan, TSan, and UBSan are
# enabled; the instrumentation they add increases
# the stack usage - we only care about stack
# usage in normal operation.
#
list(APPEND WIRESHARK_COMMON_FLAGS
-Wframe-larger-than=32768
)
endif()
list(APPEND WIRESHARK_C_ONLY_FLAGS
#
### Flags for C only ###
#
#
# XXX - some versions of GCC, including the one in at
# least some Xcode versions that come with Mac OS X
# 10.5, complain about variables in function and
# function pointer *declarations* shadowing other
# variables. The autoconf script checked for that; we
# don't.
-Wshadow
-Wold-style-definition
-Wstrict-prototypes
-Wincompatible-pointer-types
-Wint-conversion
)
#
# The universal zero initializer (in C: struct s x = { 0 };) for
# structures with multiple members is perfectly legal, but some older
# compilers warn about it. Silence those older compilers.
#
if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5.1") OR
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0") OR
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "12.0"))
if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_LESS "5.0")
list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-field-initializers)
endif()
# Silence warnings for initialization of nested structs like
# struct { struct { int a, b; } s; int c; } v = { 0 };
list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-braces)
endif()
list(APPEND WIRESHARK_CXX_ONLY_FLAGS
#
### Flags for C++ only ###
#
-Wextra-semi # Clang-only
)
#
# Not all warnings are the same. They fall on a spectrum from "critical"
# to "pedantic nonsense". These are warnings that realistically are worth
# fixing eventually.
# TODO https://gitlab.com/wireshark/wireshark/-/issues/19995
#
if(ENABLE_TODO_WARNINGS)
list(APPEND WIRESHARK_COMMON_FLAGS
#
# All the registration functions block these for now.
#
-Wmissing-prototypes
-Wmissing-declarations
-Wconversion
-Wsign-conversion
#
# A bunch of "that might not work on SPARC" code blocks
# this one for now; some of it is code that *will* work
# on SPARC, such as casts of "struct sockaddr *" to
# "struct sockaddr_in *", which are required by some
# APIs such as getifaddrs().
#
-Wcast-align
)
else()
list(APPEND WIRESHARK_COMMON_FLAGS
#
# Converting from g_printf() and g_snprintf() to stdio.h turns
# up many of these warnings. They will have to be handled later.
# It can be a lot of work to fix properly and none of them
# seem to flag very interesting issues.
#
-Wno-format-truncation # Enabled with -Wall
-Wno-format-nonliteral # Enabled with -Wformat=2
)
list(APPEND WIRESHARK_C_ONLY_FLAGS
-Wno-pointer-sign # Enabled with -Wall
)
endif()
#
# These are not enabled by default, because the warnings they
# produce are very hard or impossible to eliminate.
#
if(ENABLE_PEDANTIC_COMPILER_WARNINGS)
list(APPEND WIRESHARK_COMMON_FLAGS
# The following are for C and C++
-Wpedantic
-Wno-overlength-strings
-Wno-long-long
#
# As we use variadic macros, we don't want warnings
# about them, even with -Wpedantic.
#
-Wno-variadic-macros
#
# Various code blocks this one.
#
-Woverflow
-fstrict-overflow -Wstrict-overflow=4
#
# Due to various places where APIs we don't control
# require us to cast away constness, we can probably
# never enable this one with -Werror.
#
-Wcast-qual
#
# Doesn't warn of interesting issues. Usually the
# duplicated branches are protocol constants that
# happen to be equal and are relevant for documentation
# and readability and are trivially optimized by the
# compiler.
#
-Wduplicated-branches # GCC-only
#
# No longer supported by El Capitan clang on C++
# XXX - is this one of those where CMake's check
# doesn't fail, so it won't reject this?
#
-fno-delete-null-pointer-checks
)
#
# Some loops are safe, but it's hard to convince the compiler of
# that. Always disable the warning on GCC 7 due to a bug that
# cause lots of false positives.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408
#
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION MATCHES "^7\\.")
list(APPEND WIRESHARK_COMMON_FLAGS -Wunsafe-loop-optimizations)
endif()
list(APPEND WIRESHARK_C_ONLY_FLAGS
# The following are C only, not C++
#
# Due to various places where APIs we don't control
# require us to cast away constness, we can probably
# never enable this one with -Werror.
#
-Wbad-function-cast
)
list(APPEND WIRESHARK_CXX_ONLY_FLAGS
)
endif()
if(ENABLE_COMPILER_COLOR_DIAGNOSTICS)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
-fcolor-diagnostics
)
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
-fdiagnostics-color=always
)
endif()
endif()
set(WIRESHARK_LD_FLAGS
# See also CheckCLinkerFlag.cmake
-Wl,--as-needed
# -flto
# -fwhopr
# -fwhole-program
)
endif() # ! MSVC
# Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
if(ENABLE_STATIC)
set(BUILD_SHARED_LIBS 0)
else()
set(BUILD_SHARED_LIBS 1)
endif()
function(test_compiler_flag _lang _this_flag _valid_flags_var)
string(MAKE_C_IDENTIFIER "${_lang}${_this_flag}_VALID" _flag_var)
set(_test_flags "${${_valid_flags_var}} ${_this_flag}")
if(_lang STREQUAL "C")
check_c_compiler_flag("${_test_flags}" ${_flag_var})
elseif(_lang STREQUAL "CXX")
check_cxx_compiler_flag("${_test_flags}" ${_flag_var})
else()
message(FATAL_ERROR "Language must be C or CXX")
endif()
if (${_flag_var})
set(${_valid_flags_var} "${_test_flags}" PARENT_SCOPE)
endif()
endfunction()
foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS})
test_compiler_flag(C ${THIS_FLAG} ADDED_CMAKE_C_FLAGS)
endforeach()
set(CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${CMAKE_C_FLAGS}")
foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS})
test_compiler_flag(CXX ${THIS_FLAG} ADDED_CMAKE_CXX_FLAGS)
endforeach()
set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
# Strips the source and build directory prefix from the __FILE__ macro to ensure
# reproducible builds. Supported since GCC 8, Clang support is pending.
if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# If the build dir is within the source dir, CMake will use something
# like ../epan/dfilter/semcheck.c. Map these relative paths in addition
# to CMAKE_BINARY_DIR since compile_commands.json uses absolute paths.
file(RELATIVE_PATH _relative_source_dir "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
string(REGEX REPLACE "/$" "" _relative_source_dir "${_relative_source_dir}")
check_c_compiler_flag(-fmacro-prefix-map=old=new C_fmacro_prefix_map_old_new_VALID)
check_cxx_compiler_flag(-fmacro-prefix-map=old=new CXX_fmacro_prefix_map_old_new_VALID)
foreach(_lang C CXX)
if(${_lang}_fmacro_prefix_map_old_new_VALID)
set(_flags CMAKE_${_lang}_FLAGS)
set(${_flags} "${${_flags}} -fmacro-prefix-map=\"${CMAKE_SOURCE_DIR}/\"=")
set(${_flags} "${${_flags}} -fmacro-prefix-map=\"${CMAKE_BINARY_DIR}/\"=")
if(_relative_source_dir MATCHES "\\.\\.$")
set(${_flags} "${${_flags}} -fmacro-prefix-map=\"${_relative_source_dir}/\"=")
endif()
endif()
endforeach()
endif()