-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
3250 lines (2983 loc) · 97.8 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
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
project(Wireshark C CXX)
# Updated by make-version.pl
set(GIT_REVISION 0)
set(PROJECT_MAJOR_VERSION 2)
set(PROJECT_MINOR_VERSION 5)
set(PROJECT_PATCH_VERSION 0)
set(PROJECT_BUILD_VERSION ${GIT_REVISION})
set(PROJECT_VERSION_EXTENSION "")
set(PROJECT_RELEASE_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}")
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}")
# packaging information
if(WIN32)
set(CPACK_PACKAGE_NAME Wireshark)
else()
set(CPACK_PACKAGE_NAME wireshark)
endif()
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
if(WIN32)
# Needed for GREATER_EQUAL operator
cmake_minimum_required(VERSION 3.7)
else()
cmake_minimum_required(VERSION 2.8.11)
endif()
#Where to find local cmake scripts
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
# Set old behaviour for MACOSX_RPATH (since 3.0)
if (POLICY CMP0042)
cmake_policy(SET CMP0042 OLD)
endif()
# Set old behaviour for variable quoting (since 3.1)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 OLD)
endif()
# If our target platform is enforced by our generator, set
# WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
# %WIRESHARK_TARGET_PLATFORM%.
if(WIN32)
find_package(PowerShell REQUIRED)
if(${CMAKE_CL_64} OR "${CMAKE_GENERATOR}" MATCHES "Win64")
set(WIRESHARK_TARGET_PLATFORM win64)
elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
set(WIRESHARK_TARGET_PLATFORM win32)
else()
set(WIRESHARK_TARGET_PLATFORM $ENV{WIRESHARK_TARGET_PLATFORM})
endif()
if ("${WIRESHARK_TARGET_PLATFORM}" MATCHES "win64")
set(PROCESSOR_ARCHITECTURE amd64)
else()
set(PROCESSOR_ARCHITECTURE x86)
endif()
# Sanity check
if(DEFINED ENV{PLATFORM})
string(TOLOWER $ENV{PLATFORM} _vs_platform)
else()
set(_vs_platform "[undefined]") # x86
endif()
if(
(_vs_platform STREQUAL "x64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
OR
(_vs_platform STREQUAL "[undefined]" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win32")
)
message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
" doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
endif()
message(STATUS "Building for ${WIRESHARK_TARGET_PLATFORM} using ${CMAKE_GENERATOR}")
# Determine where the 3rd party libraries will be
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)
if(MSVC14)
set(_vsversion_args "14")
elseif(MSVC12)
set(_vsversion_args "12")
elseif(MSVC11)
set(_vsversion_args "11")
elseif(MSVC10)
set(_vsversion_args "10")
else()
message(FATAL_ERROR "Unsupported compiler ${CMAKE_C_COMPILER}")
endif()
# 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} -VSVersion ${_vsversion_args}
RESULT_VARIABLE _win_setup_failed
)
if (${_win_setup_failed})
message(FATAL_ERROR "Windows setup (win-setup.ps1) failed.")
endif()
# XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
# Head off any attempts to use Cygwin's Python.
include(LocatePythonExecutable)
endif(WIN32)
include(UseCustomIncludes)
ADD_CUSTOM_CMAKE_INCLUDE()
# This cannot be implemented via option(...)
if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
message(STATUS "CMAKE_C_FLAGS_${_build_type}: ${CMAKE_C_FLAGS_${_build_type}}")
message(STATUS "CMAKE_CXX_FLAGS_${_build_type}: ${CMAKE_CXX_FLAGS_${_build_type}}")
# 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 ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
"Single output directory for building all archives.")
endif()
if(NOT EXECUTABLE_OUTPUT_PATH)
set(EXECUTABLE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
"Single output directory for building all executables.")
endif()
if(NOT LIBRARY_OUTPUT_PATH)
set(LIBRARY_OUTPUT_PATH ${Wireshark_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 ...
include(GNUInstallDirs)
# Make sure our executables can can load our libraries if we install into
# a non-default directory on Unix-like systems other than macOS.
# https://cmake.org/Wiki/CMake_RPATH_handling
if(NOT CMAKE_INSTALL_RPATH AND NOT (WIN32 OR APPLE))
LIST(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
if("${IS_SYSTEM_DIR}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif("${IS_SYSTEM_DIR}" STREQUAL "-1")
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()
# These are required in .rc files and manifests
set(VERSION_MAJOR ${PROJECT_MAJOR_VERSION})
set(VERSION_MINOR ${PROJECT_MINOR_VERSION})
set(VERSION_MICRO ${PROJECT_PATCH_VERSION})
set(VERSION_BUILD ${PROJECT_BUILD_VERSION})
set(RC_VERSION ${PROJECT_MAJOR_VERSION},${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(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}
)
include( CMakeOptions.txt )
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()
if(APPLE AND EXISTS /usr/local/opt/qt5)
# Homebrew installs Qt5 (up to at least 5.9.1) in
# /usr/local/qt5, ensure it can be found by CMake since
# it is not in the default /usr/local prefix.
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt5")
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.
# Needed when either:
# - Qt5_POSITION_INDEPENDENT_CODE is set and CMake < 2.8.11
# - PIE is wanted (-pie) and you want to add -fPIC/-fPIE automatically.
# This option only has an effect on CMake >= 2.8.9
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
if (MSVC10)
set(MSC_VER_REQUIRED 1600)
elseif(MSVC11)
set(MSC_VER_REQUIRED 1700)
elseif(MSVC12)
set(MSC_VER_REQUIRED 1800)
elseif(MSVC14)
set(MSC_VER_REQUIRED 1900)
else()
message(FATAL_ERROR "You are using an unsupported version of MSVC")
endif()
add_definitions(
/DWIN32_LEAN_AND_MEAN
"/DMSC_VER_REQUIRED=${MSC_VER_REQUIRED}"
/D_CRT_SECURE_NO_DEPRECATE
# NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
# This avoids conflicts with the C++ standard library.
/DNOMINMAX
# -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.
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx
# -DBUILD_WINDOWS Starting from VS2013, GetVersionEx is deprecated and we are recommended to use
# VerifyVersionInfo instead
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724429(v=vs.85).aspx
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms725491(v=vs.85).aspx
# To continue to use GetVersionEx, we can define BUILD_WINDOWS
# -D_ALLOW_KEYWORD_MACROS For VS2012 onwards the, C++ STL does not permit macro redefinitions of keywords
# (see http://msdn.microsoft.com/en-us/library/bb531344(v=vs.110).aspx)
# 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
/DBUILD_WINDOWS
/D_ALLOW_KEYWORD_MACROS
)
if(NOT "${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64")
add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
endif()
# FIXME: WINPCAP_VERSION cannot be determined from source or executable.
set(WINPCAP_VERSION "4_1_3")
add_definitions("/DWINPCAP_VERSION=${WINPCAP_VERSION}")
set(LOCAL_CFLAGS
/MP
)
if(MSVC12)
# /Zo Enhanced debugging of optimised code for VS2013 Update 3 and beyond,
# Assume all VS2013 builds are at least Update 3.
# See http://msdn.microsoft.com/en-us/library/dn785163.aspx
set(LOCAL_CFLAGS ${LOCAL_CFLAGS} "/Zo")
elseif(MSVC14)
# /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.
set(LOCAL_CFLAGS ${LOCAL_CFLAGS} "/Zo" "/utf-8")
endif()
if(ENABLE_CODE_ANALYSIS)
set(LOCAL_CFLAGS ${LOCAL_CFLAGS} "/analyze:WX-")
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
## 4189: local variable is initialized but not referenced
# Disable warnings about about use of flexible array members:
## 4200: nonstandard extension used : zero-sized array in struct/union
set(WARNINGS_CFLAGS "/w34295 /w34189 /wd4200")
set(WIRESHARK_COMMON_FLAGS
${LOCAL_CFLAGS}
${WARNINGS_CFLAGS}
)
set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
else()
if(CMAKE_OSX_DEPLOYMENT_TARGET)
if(APPLE)
if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.0")
message(FATAL_ERROR "We don't support building for Mac OS X 10.0")
elseif(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.1")
message(FATAL_ERROR "We don't support building for Mac OS X 10.1")
elseif(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.2")
message(FATAL_ERROR "We don't support building for Mac OS X 10.2")
elseif(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.4" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
#
# Only 32-bit builds are supported. 10.5
# (and 10.4?) had a bug that causes some BPF
# functions not to work with 64-bit userland
# code, so capturing won't work.
#
set(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
set(WS_LINK_FLAGS "-m32 ${WS_LINK_FLAGS}")
endif()
message(STATUS "Building for Mac OS X/OS X/macOS ${CMAKE_OSX_DEPLOYMENT_TARGET}")
else()
message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET only applies when building for macOS")
endif()
endif()
if(CMAKE_VERSION VERSION_LESS "3.1")
# Many modern compilers use c99 by default, but for older ones
# (like GCC 4.4.7), -std=gnu99 is required to avoid errors about
# use constructs like "for (int i = 0; i < n; i++) ;"
#
# Older versions of IBM XL C may require -qlanglvl=extc99.
# With V7.0, the "xlc" command defaults to C89; with 10.1,
# it defaults to C99 (both with IBM syntax extensions).
#
# HP's manual for HP C/HP-UX B.11.11.04 (the tenth
# edition of the manual), for PA-RISC, "documents
# new HP C features that support C99 industry standards".
# The manual for Version A.06.25 for Itanium mentions an
# -AC99 flag to support C99, but says it's the default;
# some older versions might require -AC99.
#
# As of Sun Studio 8, the compiler appears to default
# to supporting some C99 language features, but not
# C99 library differences from C89; -xc99 will give
# you both. The earlier Sun Forte Developer 6 update 2
# might or might not support thosee C99 language features
# by default, and doesn't speak of library differences;
# if it doesn't support the language features by default,
# -xc99 will support them.
#
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
endif()
else()
#
# Current versions of CMake do not support options to
# request C99 for XL C, HP C, or Oracle C. (They may
# not be necessary for current versions.)
#
set(CMAKE_C_STANDARD 99)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
# avoid "argument unused during compilation" warnings
# (for example, when getting the -gsplit-dwarf option or
# when combining -fwrapv with -fno-strict-overflow)
-Qunused-arguments
)
else()
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
-fexcess-precision=fast
)
endif()
set(COMMON_WARN_FLAGS
# The following are for C and C++
# -O<X> and -g get set by the CMAKE_BUILD_TYPE
-Wall
-Wextra
-Wendif-labels
-Wpointer-arith
-Wformat-security
-fwrapv
-fno-strict-overflow
-Wvla
-Waddress
-Wattributes
-Wdiv-by-zero
-Wignored-qualifiers
-Wpragmas
-Wno-overlength-strings
-Wno-long-long
-Wheader-guard
)
#
# Code that may be worth looking into (coding practices)
#
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.
#
set(COMMON_WARN_FLAGS ${COMMON_WARN_FLAGS}
-Wframe-larger-than=16384
)
endif()
set(C_WARN_FLAGS
# The following are C only, not C++
-Wc++-compat
-Wunused-const-variable
#
# 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 checks for that; we
# don't.
-Wshadow
-Wno-pointer-sign
-Wold-style-definition
-Wstrict-prototypes
#
# Some versions of GCC, such as 4.3.2 and 4.4.5,
# generate logical-op warnings when strchr() is given a
# constant string. The autoconf script checks for that;
# we don't.
#
-Wlogical-op
-Wjump-misses-init
#
# The Qt headers generate a ton of shortening warnings
# on 64-bit systems, so we only enable this for C for
# now.
#
-Wshorten-64-to-32
#
# Implicit function declarations are an error in C++ and most
# likely a programming error in C. Turn -Wimplicit-int and
# -Wimplicit-function-declaration into an error by default.
#
-Werror=implicit
#
# The Qt headers in version 5.10 introduced a lot of
# "Possible misuse of comma operator here" warnings.
#
-Wcomma
)
set(CXX_WARN_FLAGS
)
find_package(Qt5Core) # Needed to check for Qt version
if (Qt5Core_VERSION VERSION_GREATER 5.8)
# The Qt headers in version 5.8 and older generate a ton of shortening
# errors on 64-bit systems so only enable this for version 5.9 and greater.
set(CXX_WARN_FLAGS ${CXX_WARN_FLAGS}
-Wshorten-64-to-32
)
endif()
if (Qt5Core_VERSION VERSION_LESS 5.10)
# The Qt headers in version 5.10 introduced a lot of
# "Possible misuse of comma operator here" warnings.
set(CXX_WARN_FLAGS ${CXX_WARN_FLAGS}
-Wcomma
)
endif()
#
# These are not enabled by default, because the warnings they
# produce are very hard or impossible to eliminate.
#
set(COMMON_EXTRA_WARN_FLAGS
# The following are for C and C++
-Wpedantic
#
# 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
#
# Some generated ASN.1 dissectors block this one;
# multiple function declarations for the same
# function are being generated.
#
-Wredundant-decls
#
# Some loops are safe, but it's hard to convince the
# compiler of that.
#
-Wunsafe-loop-optimizations
#
# All the registration functions block these for now.
#
-Wmissing-prototypes
-Wmissing-declarations
#
# 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
#
# Works only with Clang
#
-Wunreachable-code
#
# Works only with Clang but generates a lot of warnings
# (about glib library not using Doxygen)
#
-Wdocumentation
#
# Works only with GCC 7
#
-Wduplicated-branches
#
# 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
)
set(C_EXTRA_WARN_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
)
set(CXX_EXTRA_WARN_FLAGS
)
if(ENABLE_EXTRA_COMPILER_WARNINGS) # This overrides -Werror
set(COMMON_WARN_FLAGS ${COMMON_WARN_FLAGS} ${COMMON_EXTRA_WARN_FLAGS})
set(C_WARN_FLAGS ${C_WARN_FLAGS} ${C_EXTRA_WARN_FLAGS})
set(CXX_WARN_FLAGS ${CXX_WARN_FLAGS} ${CXX_EXTRA_WARN_FLAGS})
endif()
add_definitions(
-DG_DISABLE_DEPRECATED
-DG_DISABLE_SINGLE_INCLUDES
)
endif()
set( C_FLAG_TESTS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS} )
set( CXX_FLAG_TESTS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS} )
set( C_WARN_TESTS ${COMMON_WARN_FLAGS} ${C_WARN_FLAGS} )
set( CXX_WARN_TESTS ${COMMON_WARN_FLAGS} ${CXX_WARN_FLAGS} )
# 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()
# Sigh: Have to use THIS_FLAG instead of ${F} for some reason
foreach(THIS_FLAG ${C_FLAG_TESTS})
string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
set(${F} ${THIS_FLAG})
set(V C_${F}_VALID)
message(STATUS "Checking for c-compiler flag: ${THIS_FLAG}")
check_c_compiler_flag("${ADDED_CMAKE_C_FLAGS} ${${F}}" ${V})
if (${${V}})
set(ADDED_CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${${F}}")
endif()
endforeach()
set(CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${CMAKE_C_FLAGS}")
foreach(THIS_FLAG ${CXX_FLAG_TESTS})
string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
set(${F} ${THIS_FLAG})
set(V CXX_${F}_VALID)
message(STATUS "Checking for c++-compiler flag: ${THIS_FLAG}")
check_cxx_compiler_flag("${ADDED_CMAKE_CXX_FLAGS} ${${F}}" ${V})
if (${${V}})
set(ADDED_CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${${F}}")
endif()
endforeach()
set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
foreach(THIS_FLAG ${C_WARN_TESTS})
string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
set(${F} ${THIS_FLAG})
set(V C_${F}_VALID)
message(STATUS "Checking for c-compiler flag: ${THIS_FLAG}")
check_c_compiler_flag("${C_FLAG_TESTS} ${${F}}" ${V})
if (${${V}})
set(ADDED_WARN_C_FLAGS "${ADDED_WARN_C_FLAGS} ${${F}}")
endif()
endforeach()
set(CMAKE_C_FLAGS "${ADDED_WARN_C_FLAGS} ${CMAKE_C_FLAGS}")
foreach(THIS_FLAG ${CXX_WARN_TESTS})
string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
set(${F} ${THIS_FLAG})
set(V CXX_${F}_VALID)
message(STATUS "Checking for c++-compiler flag: ${THIS_FLAG}")
check_cxx_compiler_flag("${CXX_FLAG_TESTS} ${${F}}" ${V})
if (${${V}})
set(ADDED_WARN_CXX_FLAGS "${ADDED_WARN_CXX_FLAGS} ${${F}}")
endif()
endforeach()
set(CMAKE_CXX_FLAGS "${ADDED_WARN_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
include(CMakePushCheckState)
if(ENABLE_ASAN)
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
check_c_compiler_flag(-fsanitize=address C__fsanitize_address_VALID)
check_cxx_compiler_flag(-fsanitize=address CXX__fsanitize_address_VALID)
cmake_pop_check_state()
if(NOT C__fsanitize_address_VALID OR NOT CXX__fsanitize_address_VALID)
message(FATAL_ERROR "ENABLE_ASAN was requested, but not supported!")
endif()
set(CMAKE_C_FLAGS "-fsanitize=address ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS}")
# Disable ASAN for build-time tools, e.g. lemon
check_c_compiler_flag(-fno-sanitize=all C__fno_sanitize_all_VALID)
if(C__fno_sanitize_all_VALID)
set(NO_SANITIZE_CFLAGS "-fno-sanitize=all")
set(NO_SANITIZE_LDFLAGS "-fno-sanitize=all")
endif()
endif()
if(ENABLE_TSAN)
# Available since Clang >= 3.2 and GCC >= 4.8
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=thread")
check_c_compiler_flag(-fsanitize=thread C__fsanitize_thread_VALID)
check_cxx_compiler_flag(-fsanitize=thread CXX__fsanitize_thread_VALID)
cmake_pop_check_state()
if(NOT C__fsanitize_thread_VALID OR NOT CXX__fsanitize_thread_VALID)
message(FATAL_ERROR "ENABLE_TSAN was requested, but not supported!")
endif()
set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}")
set(WS_LINK_FLAGS "-fsanitize=thread ${WS_LINK_FLAGS}")
endif()
if(ENABLE_UBSAN)
# Available since Clang >= 3.3 and GCC >= 4.9
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined")
check_c_compiler_flag(-fsanitize=undefined C__fsanitize_undefined_VALID)
check_cxx_compiler_flag(-fsanitize=undefined CXX__fsanitize_undefined_VALID)
cmake_pop_check_state()
if(NOT C__fsanitize_undefined_VALID OR NOT CXX__fsanitize_undefined_VALID)
message(FATAL_ERROR "ENABLE_UBSAN was requested, but not supported!")
endif()
set(CMAKE_C_FLAGS "-fsanitize=undefined ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=undefined ${CMAKE_CXX_FLAGS}")
endif()
set(WERROR_COMMON_FLAGS "")
set(NO_ERROR_DEPRECATED_DECLARATIONS_COMPILE_FLAGS "")
if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(WERROR_COMMON_FLAGS "/WX")
else()
check_c_compiler_flag(-Werror WERROR)
if (WERROR)
set(WERROR_COMMON_FLAGS "-Werror")
set(NO_ERROR_DEPRECATED_DECLARATIONS_COMPILE_FLAGS "-Wno-error=deprecated-declarations")
endif()
endif()
endif()
#
# Try to have the compiler default to hiding symbols, so that only
# symbols explicitly exported with WS_DLL_PUBLIC will be visible
# outside (shared) libraries; that way, more UN*X builds will catch
# failures to export symbols, rather than having that fail only on
# Windows.
#
# We don't need that with MSVC, as that's the default.
#
if( NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
#
# Try the GCC-and-compatible -fvisibility-hidden first.
#
check_c_compiler_flag(-fvisibility=hidden FVHIDDEN)
if(FVHIDDEN)
set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
else()
#
# OK, try the Sun^WOracle C -xldscope=hidden
#
check_c_compiler_flag(-xldscope=hidden XLDSCOPEHIDDEN)
if(XLDSCOPEHIDDEN)
set(CMAKE_C_FLAGS "-xldscope=hidden ${CMAKE_C_FLAGS}")
else()
#
# Anything else?
# If there is anything else, we might want to
# make a list of options to try, and try them
# in a loop.
#
message(WARNING "Hiding shared library symbols is not supported by the compiler."
" All shared library symbols will be exported.")
endif()
endif()
endif()
set(WIRESHARK_LD_FLAGS
-Wl,--as-needed
# -flto
# -fwhopr
# -fwhole-program
)
# CMAKE_POSITION_INDEPENDENT_CODE is only supported starting with CMake
# 2.8.9. Do not add -pie automatically for older versions.
#
# XXX - are there other compilers that don't support -pie? It's
# not as if the only platforms we support are Windows and Linux....
#
if(NOT CMAKE_VERSION VERSION_LESS "2.8.9")
set(WIRESHARK_LD_FLAGS ${WIRESHARK_LD_FLAGS}
-pie
)
endif()
include(CheckCLinkerFlag)
set(_C 0)
# Sigh: Have to use THIS_FLAG instead of ${F} for some reason
foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
set(F WS_LD_FLAG_${_C})
set(${F} ${THIS_FLAG})
set(V WS_LD_FLAG_VALID${_C})
check_c_linker_flag(${${F}} ${V})
if (${${V}})
set(WS_LINK_FLAGS "${WS_LINK_FLAGS} ${${F}}")
endif()
math(EXPR _C "${_C} + 1")
endforeach()
if(APPLE AND EXISTS /usr/local/opt/gettext)
# GLib on macOS requires libintl. Homebrew installs gettext (and
# libintl) in /usr/local/opt/gettext
include_directories(/usr/local/opt/gettext/include)
link_directories(/usr/local/opt/gettext/lib)
endif()
# The packagelist is doing some magic: If we add XXX to the packagelist, we
# - may optionally set XXX_OPTIONS to pass to the find_package command
# - will call FindXXX.cmake or find_package
# - return found libraries in XXX_LIBRARIES
# - return found include in XXX_INCLUDE_DIRS
# - set HAVE_XXX
# The minimum package list
set(PACKAGELIST Git GLIB2 GMODULE2 GTHREAD2 GCRYPT LEX YACC Perl SH PythonInterp)
set(LEX_OPTIONS REQUIRED)
set(GLIB2_OPTIONS REQUIRED)
set(GLIB2_FIND_OPTIONS REQUIRED)
set(GLIB2_MIN_VERSION 2.22.0)
set(GTHREAD2_OPTIONS REQUIRED)
set(GCRYPT_OPTIONS "1.4.2" REQUIRED)
set(PythonInterp_FIND_VERSION 2)
set(Python_ADDITIONAL_VERSIONS 3)
set(YACC_OPTIONS REQUIRED)
if (NOT WIN32)
set(PACKAGELIST ${PACKAGELIST} Gettext M)
set(M_OPTIONS REQUIRED)
endif()
set(PACKAGELIST ${PACKAGELIST} LIBSSH)
set(LIBSSH_OPTIONS "0.6")
if(ENABLE_PCAP)
set(PACKAGELIST ${PACKAGELIST} PCAP)
endif()
if(ENABLE_AIRPCAP)
set(PACKAGELIST ${PACKAGELIST} AIRPCAP)
endif()
# Build the GTK-GUI?
if(BUILD_wireshark_gtk)
if(ENABLE_GTK3)
set(PACKAGELIST ${PACKAGELIST} GTK3)
else()
set(PACKAGELIST ${PACKAGELIST} GTK2)
set(GTK2_OPTIONS COMPONENTS gtk)
set(GTK2_FIND_VERSION 2.12)
set(GTK2_DEBUG false)
endif()
endif()
# Build the Qt GUI?
if(BUILD_wireshark)
if(ENABLE_QT5)
# Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
# somewhere. The if WIN32 in this place is annoying as well.
if( WIN32 )
set( QT5_BASE_PATH "$ENV{QT5_BASE_DIR}" )
set( CMAKE_PREFIX_PATH "${QT5_BASE_PATH}" )
endif()
set(PACKAGELIST ${PACKAGELIST}
Qt5Core
Qt5LinguistTools
Qt5Multimedia
Qt5PrintSupport
Qt5Svg
Qt5Widgets
)
set(Qt5Core_OPTIONS REQUIRED)
set(Qt5LinguistTools_OPTIONS REQUIRED)
set(Qt5Multimedia_OPTIONS REQUIRED)
set(Qt5PrintSupport_OPTIONS REQUIRED)
set(Qt5Svg_OPTIONS REQUIRED)
set(Qt5Widgets_OPTIONS REQUIRED)
if (APPLE)
set(PACKAGELIST ${PACKAGELIST} Qt5MacExtras)
set(Qt5MacExtras_OPTIONS REQUIRED)
endif()
if( WIN32 )
set(PACKAGELIST ${PACKAGELIST} Qt5WinExtras)
set(Qt5WinExtras_OPTIONS REQUIRED)
endif()
set(QT_VERSION 5)
else()
set(PACKAGELIST ${PACKAGELIST} Qt4)
set(Qt4_OPTIONS 4.8 REQUIRED QtCore QtGui)
set(QT_VERSION 4)
endif()
endif()
# SMI SNMP
if(ENABLE_SMI)
set(PACKAGELIST ${PACKAGELIST} SMI)
endif()
# GNU SSL/TLS support
if(ENABLE_GNUTLS)
set(PACKAGELIST ${PACKAGELIST} GNUTLS)
# Minimum version needed.
set(GNUTLS_OPTIONS "2.12.0")
endif()
# Kerberos
if(ENABLE_KERBEROS)
set(PACKAGELIST ${PACKAGELIST} KERBEROS)
endif()
# Portable audio (GTK+ only)
if(ENABLE_PORTAUDIO AND BUILD_wireshark_gtk)
set(PACKAGELIST ${PACKAGELIST} PORTAUDIO)
endif()
# C Asynchronous resolver
if(ENABLE_CARES)
set(PACKAGELIST ${PACKAGELIST} CARES)
# Minimum version needed.
set(CARES_OPTIONS "1.5.0")
endif()
# Zlib compression
if(ENABLE_ZLIB)
if (WIN32)
# On Windows we build our own version of zlib, so add the paths
set(ZLIB_SRC_DIR "${_PROJECT_LIB_DIR}/zlib-1.2.11-ws")
set(SKIP_INSTALL_ALL True) # We copy the DLL ourselves.
add_subdirectory("${ZLIB_SRC_DIR}" "${CMAKE_BINARY_DIR}/zlib")
unset(SKIP_INSTALL_ALL)
set(ZLIB_INCLUDE_DIR "${ZLIB_SRC_DIR}" "${CMAKE_BINARY_DIR}/zlib")
set(ZLIB_LIBRARY zlib)
set(ZLIB_DLL "zlib1.dll")
set_target_properties(zlib PROPERTIES FOLDER "Libs/zlib")
# Annoyingly zlib also builds some other stuff we aren't interested in
set_target_properties(zlibstatic PROPERTIES FOLDER "Libs/zlib")
endif()
set(PACKAGELIST ${PACKAGELIST} ZLIB)
endif()
# LZ4 compression
if(ENABLE_LZ4)
set(PACKAGELIST ${PACKAGELIST} LZ4)
endif()
# Snappy compression
if(ENABLE_SNAPPY)
set(PACKAGELIST ${PACKAGELIST} SNAPPY)
endif()
# Enhanced HTTP/2 dissection
if(ENABLE_NGHTTP2)
set(PACKAGELIST ${PACKAGELIST} NGHTTP2)
endif()
# Embedded Lua interpreter
if(ENABLE_LUA)
set(PACKAGELIST ${PACKAGELIST} LUA)
endif()
# GeoIP address resolving
if(ENABLE_GEOIP)
set(PACKAGELIST ${PACKAGELIST} GEOIP)
endif()