-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
3464 lines (3174 loc) · 111 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(WIN32)
# Needed for add_custom_command() WORKING_DIRECTORY generator expressions
cmake_minimum_required(VERSION 3.13)
else()
cmake_minimum_required(VERSION 3.5)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0083)
cmake_policy(SET CMP0083 NEW)
endif()
if(WIN32)
set(_project_name Wireshark)
else()
set(_project_name wireshark)
endif()
project(${_project_name} C CXX)
# Updated by tools/make-version.pl
set(GIT_REVISION 0)
set(PROJECT_MAJOR_VERSION 3)
set(PROJECT_MINOR_VERSION 3)
set(PROJECT_PATCH_VERSION 0)
set(PROJECT_BUILD_VERSION ${GIT_REVISION})
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(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
include( CMakeOptions.txt )
# 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}")
#Where to find local cmake scripts
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
# 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(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE amd64)
else()
set(WIRESHARK_TARGET_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)
# 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}
RESULT_VARIABLE _win_setup_failed
)
if(_win_setup_failed)
message(FATAL_ERROR "Windows setup (win-setup.ps1) failed.")
endif()
set(EXTRA_INSTALLER_DIR ${_ws_lib_dir})
# XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
# Prepopulate some ConfigureChecks values. Compilation checks
# on Windows can be slow.
set(HAVE_FCNTL_H TRUE)
set(HAVE_FLOORL TRUE)
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 "CMake build type: ${CMAKE_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 ${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)
# 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 ".")
else()
# By default INSTALL_DATADIR is set to INSTALL_DATAROOTDIR, set the
# proper value here.
set(CMAKE_INSTALL_DATADIR "share/${PROJECT_NAME}"
CACHE PATH "Read-only architecture-independent data"
)
endif()
include(GNUInstallDirs)
set(PROJECT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
# 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://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
set(LIBRARY_INSTALL_RPATH "")
set(EXECUTABLE_INSTALL_RPATH "")
set(EXTCAP_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
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
set(_enable_rpath_origin TRUE)
if(BUILD_dumpcap AND ENABLE_PCAP)
# dumpcap will most likely be installed with
# capabilities or setuid. Relative RPATHs that
# resolve to non-standard library directories
# are ignored for such binaries and since we
# cannot achieve relocatable builds, just
# disable it by default.
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.
set(ENABLE_RPATH_ORIGIN ${_enable_rpath_origin} CACHE BOOL
"Use $ORIGIN with INSTALL_RPATH")
mark_as_advanced(ENABLE_RPATH_ORIGIN)
else()
set(ENABLE_RPATH_ORIGIN FALSE)
endif()
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(WIN32)
# Linking with wsetargv.obj enables "wildcard expansion" of
# command-line arguments.
set(WILDCARD_OBJ wsetargv.obj)
endif(WIN32)
# 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(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}
)
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)
# Path to our generated executables (or wrapper scripts)
if(WIN32)
set(WS_PROGRAM_PATH ./run/$<CONFIG>)
else()
set(WS_PROGRAM_PATH ./run)
endif()
if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
if ((MSVC_VERSION LESS "1900") OR (MSVC_VERSION GREATER_EQUAL "2000"))
message(FATAL_ERROR "You are using an unsupported version of MSVC")
endif()
add_definitions(
/DWIN32_LEAN_AND_MEAN
/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.
# 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
)
if(NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
endif()
set(LOCAL_CFLAGS
/MP
)
set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
# To do: Add /external:... See https://devblogs.microsoft.com/cppblog/broken-warnings-theory/
#
# /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 /Zo /utf-8 /guard:cf)
set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /guard:cf")
# /Qspectre is not available for VS2015 or older VS2017. Test for its availability.
set(WIRESHARK_COMMON_FLAGS /Qspectre)
if(ENABLE_CODE_ANALYSIS)
list(APPEND 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
## 4100: unreferenced formal parameter
## 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
list(APPEND LOCAL_CFLAGS /w34295 /w34100 /w34189 /wd4200)
# 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)
set(MIN_MACOS_VERSION 10.6) # Arbitrary.
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})
message(STATUS "Building for Mac OS X/OS X/macOS ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET only applies when building for macOS")
endif()
#
# Do whatever is necessary to enable as much C99 support as
# possible in the C compiler. Newer versions of compilers
# might default to supporting C99, but older versions may
# require a special flag.
#
# We do not want strict C99 support, as we may also want to
# use compiler extensions.
#
# Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have
# any effect, so, unless and until we require CMake 3.1 or
# later, we have to do it ourselves on pre-3.1 CMake, so we
# just do it ourselves on all versions of CMake.
#
# Note: with CMake 3.1 through 3.5, the only compilers for
# which CMake handles CMAKE_C_STANDARD are GCC and Clang.
# 3.6 adds support only for Intel C; 3.9 adds support for
# PGI C, Sun C, and IBM XL C, and 3.10 adds support for
# Cray C and IAR C, but no version of CMake has support for
# HP C. Therefore, even if we use CMAKE_C_STANDARD with
# compilers for which CMake supports it, we may still have
# to do it ourselves on other compilers.
#
# In addition, CMake 3.5.2 seems to think that GCC versions
# less than 4.4 don't support -std=gnu99, which we need in
# order to get support for "for (int i = 0; i < n; i++) ;",
# which is another reason not to rely on CMake's CMAKE_C_STANDARD
# support.
#
# See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID
# variables for a list of compiler IDs.
#
# We don't worry about MSVC; it doesn't have such a flag -
# either it doesn't support the C99 features we need at all,
# or it supports them regardless of the compiler flag.
#
# XXX - we add the flag for a given compiler to CMAKE_C_FLAGS,
# so we test whether it works and add it if we do. We don't
# test whether it's necessary in order to get the C99 features
# that we use; if we ever have a user who tries to compile with
# a compiler that can't be made to support those features, we
# can add a test to make sure we actually *have* C99 support.
#
if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
#
# We use -std=gnu99 rather than -std=c99 because, for
# some older compilers such as GCC 4.4.7, -std=gnu99
# is required to avoid errors about C99 constructs
# such as "for (int i = 0; i < n; i++) ;".
#
set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
#
# We want support for extensions picked up for
# GNU C compatibility, so we use -qlanglvl=extc99.
#
set(CMAKE_C_FLAGS "-qlanglvl=extc99 ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
#
# We also need to add -Wp,-H200000 to handle some large
# #defines we have; that flag is not necessary for the
# C++ compiler unless the "legacy" C++ preprocessor is
# being used (+legacy_cpp). We don't want the legacy
# preprocessor if it's not the default, so we just add
# -Wp,-H200000 to the C flags. (If there are older
# versions of aC++ that only support the legacy
# preprocessor, and require that we boost the table
# size, we'd have to check whether -Wp,-H200000 is
# supported by the C++ compiler and add it only if it is.)
#
set(CMAKE_C_FLAGS "-AC99 -Wp,-H200000 $WS_CFLAGS ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
#
# We also crank up the warning level.
#
set(CMAKE_C_FLAGS "-xc99 -v ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
set(CMAKE_C_FLAGS "-c99 ${CMAKE_C_FLAGS}")
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()
list(APPEND WIRESHARK_COMMON_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
-Wcomma
-Wshorten-64-to-32
)
#
# 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(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
-Wframe-larger-than=32768
)
endif()
list(APPEND WIRESHARK_C_ONLY_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 checked for that; we
# don't.
-Wshadow
-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 checked for that;
# we don't.
#
-Wlogical-op
-Wjump-misses-init
#
# 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 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 "10.0"))
if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_LESS "4.7")
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
-Wextra-semi
)
#
# These are not enabled by default, because the warnings they
# produce are very hard or impossible to eliminate.
#
if(ENABLE_EXTRA_COMPILER_WARNINGS) # This overrides -Werror
list(APPEND WIRESHARK_COMMON_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
#
# 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
)
#
# 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
)
else()
#
# -Wpointer-sign is a default test we get with -Wall and
# -W, but for some reason we were suppressing it -
# unconditionally. Suppress it only without the extra
# warnings, so we can at least see how much we get.
# (This would have caught at least one error - the one
# in change https://code.wireshark.org/review/33234,
# which would have suggested that the wrong
# proto_tree_add_ret_ call was being used.)
#
list(APPEND WIRESHARK_C_ONLY_FLAGS
-Wno-pointer-sign
)
endif()
add_definitions(
-DG_DISABLE_DEPRECATED
-DG_DISABLE_SINGLE_INCLUDES
)
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()
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()
if(ENABLE_FUZZER)
# Available since Clang >= 6
# Will enable coverage flags which can be used by the fuzzshark target.
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=fuzzer-no-link")
check_c_compiler_flag(-fsanitize=fuzzer C__fsanitize_fuzzer_no_link_VALID)
check_cxx_compiler_flag(-fsanitize=fuzzer CXX__fsanitize_fuzzer_no_link_VALID)
cmake_pop_check_state()
if(NOT C__fsanitize_fuzzer_no_link_VALID OR NOT CXX__fsanitize_fuzzer_no_link_VALID)
message(FATAL_ERROR "ENABLE_FUZZER was requested, but not supported!")
endif()
set(CMAKE_C_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_CXX_FLAGS}")
endif()
set(WERROR_COMMON_FLAGS "")
if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(WERROR_COMMON_FLAGS "/WX")
else()
#
# If a warning has been enabled by -Wall or -W,
# and have specified -Werror, there appears to be
# no way, in Apple's llvm-gcc, to prevent that
# particular warning from giving an error - not
# with a pragma, not with -Wno-{warning}, and not
# with -Wno-error={warning}.
#
# Therefore, with that compiler, we just disable
# -Werror.
#
if ((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "Clang")
check_c_compiler_flag(-Werror WERROR)
if (WERROR)
set(WERROR_COMMON_FLAGS "-Werror")
endif()
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()
include(CheckCLinkerFlag)
if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC" AND NOT OSS_FUZZ)
#
# The -pie linker option produces a position-independent executable.
# Some Linux distributions have this enabled by default in the compiler,
# so setting it here will be superfluous though.
#
# Note that linking with static libraries that are not position
# independent may fail, the user can set CMAKE_EXE_LINKER_FLAGS=-no-pie
# as a workaround.
#
if(CMAKE_VERSION VERSION_LESS "3.14")
check_c_linker_flag(-pie LINK_pie_VALID)
if(LINK_pie_VALID)
set(CMAKE_EXE_LINKER_FLAGS "-pie ${CMAKE_EXE_LINKER_FLAGS}")
endif()
else()
include(CheckPIESupported)
check_pie_supported()
endif()
endif()
foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
string(MAKE_C_IDENTIFIER "LINK${THIS_FLAG}_VALID" _flag_var)
check_c_linker_flag(${THIS_FLAG} ${_flag_var})
if (${_flag_var})
set(WS_LINK_FLAGS "${WS_LINK_FLAGS} ${THIS_FLAG}")
endif()
endforeach()
message(STATUS "Linker flags: ${WS_LINK_FLAGS}")
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()
# Resets cache variables if the <PackageName>_LIBRARY has become invalid.
# Call it before a find_package(<PackageName> ...) invocation that uses
# find_library(<PackageName>_LIBRARY ...).
#
# Usage: reset_find_package(<PackageName> [<extra variables to clear>])
function(reset_find_package _package_name)
set(variables
# find_library / find_package
${_package_name}_LIBRARY
${_package_name}_INCLUDE_DIR
# mark_as_advanced
${_package_name}_LIBRARIES
${_package_name}_INCLUDE_DIRS
# Others
${_package_name}_DLL_DIR
${_package_name}_DLLS
${_package_name}_DLL
${_package_name}_PDB
${ARGN}
)
if(NOT ${_package_name}_LIBRARY OR EXISTS ${${_package_name}_LIBRARY})
# Cache variable is already missing or cache entry is valid.
return()
endif()
message(STATUS "Package ${_package_name} has changed, clearing cache.")
foreach(_var IN LISTS variables)