File tree Expand file tree Collapse file tree 6 files changed +61
-91
lines changed
Expand file tree Collapse file tree 6 files changed +61
-91
lines changed Original file line number Diff line number Diff line change 1313
1414set (ZEEK_LEGACY_ANALYZERS CACHE INTERNAL "" )
1515set (ZEEK_SKIPPED_ANALYZERS CACHE INTERNAL "" )
16+ include (RequireCXXStd)
1617
1718# Force Spicy include directories to the front of the include paths.
1819#
@@ -92,7 +93,7 @@ function (spicy_add_analyzer)
9293
9394 set (lib "spicy_${SPICY_ANALYZER_NAME} " )
9495 add_library (${lib} OBJECT ${generated_sources} ${cxx_sources} )
95- target_compile_features (${lib} PRIVATE cxx_std_17 )
96+ target_compile_features (${lib} PRIVATE ${ZEEK_CXX_STD} )
9697 set_target_properties (${lib} PROPERTIES CXX_EXTENSIONS OFF )
9798
9899 target_include_directories (${lib} PRIVATE ${SPICY_PLUGIN_PATH} /include
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # Check for a specific C++ standard level, and require the compiler to
2+ # support that via some CMake settings.
3+
4+ if (DEFINED ZEEK_CXX_STD)
5+ return ()
6+ endif ()
7+
8+ # Require a specific C++ standard and set the proper flag when creating targets.
9+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
10+ set (CMAKE_CXX_STANDARD 20)
11+
12+ # Disable using extensions provided by various compilers. Notably this keeps us
13+ # setting it to c++20 instead of gnu++20 with GCC.
14+ set (CMAKE_CXX_EXTENSIONS OFF )
15+
16+ set (_old_cmake_required_flags "${CMAKE_REQUIRED_FLAGS} " )
17+ if (MSVC )
18+ set (CMAKE_REQUIRED_FLAGS "/std:c++20" )
19+ else ()
20+ set (CMAKE_REQUIRED_FLAGS "-std=c++20" )
21+ endif ()
22+
23+ include (CheckCXXSourceCompiles)
24+
25+ # The <version> header is a good baseline version of C++20 support for us
26+ # since we can use it to determine support for various features in other
27+ # places.
28+ set (cxx_std_testcode "#include <version>
29+ int main() { }" )
30+
31+ check_cxx_source_compiles("${cxx_std_testcode} " cxx_std_works)
32+
33+ set (CMAKE_REQUIRED_FLAGS "${_old_cmake_required_flags} " )
34+
35+ if (cxx_std_works)
36+ set (ZEEK_CXX_STD cxx_std_20)
37+ else ()
38+ message (FATAL_ERROR "failed using C++20 for compilation" )
39+ endif ()
Original file line number Diff line number Diff line change 33## This set is used by both static and dynamic plugins via
44## ZeekPluginStatic and ZeekPluginDynamic, respectively.
55
6+ include (RequireCXXStd)
7+
68# Begins a plugin definition, giving its namespace and name as the arguments.
79# The DISABLE_CPP_TESTS option disables unit test support. When not provided,
810# unit-testing is enabled when Zeek supports it, and disabled otherwise.
@@ -23,7 +25,7 @@ macro (zeek_plugin_begin ns name)
2325 set (_plugin_bif_files "" )
2426 set (_plugin_pac_args "" )
2527
26- target_compile_features (${_plugin_lib} PRIVATE cxx_std_17 )
28+ target_compile_features (${_plugin_lib} PRIVATE ${ZEEK_CXX_STD} )
2729 set_target_properties (${_plugin_lib} PROPERTIES CXX_EXTENSIONS OFF )
2830endmacro ()
2931
Original file line number Diff line number Diff line change 11include (GetArchitecture)
2+ include (RequireCXXStd)
23
34# Sets `target` to contain the CMake target name for a dynamic plugin.
45macro (zeek_get_dynamic_plugin_target target ns name )
@@ -29,7 +30,7 @@ function (zeek_add_dynamic_plugin ns name)
2930 if (NOT TARGET ${target_name} )
3031 add_library (${target_name} MODULE)
3132
32- target_compile_features (${target_name} PRIVATE cxx_std_17 )
33+ target_compile_features (${target_name} PRIVATE ${ZEEK_CXX_STD} )
3334 set_target_properties (${target_name} PROPERTIES CXX_EXTENSIONS OFF )
3435 endif ()
3536
Original file line number Diff line number Diff line change 11include (BifCl)
22include (BinPAC)
3+ include (RequireCXXStd)
34
45# Sets `target` to contain the CMake target name for a static plugin.
56macro (zeek_get_static_plugin_target target ns name )
@@ -17,7 +18,7 @@ function (zeek_add_static_plugin ns name)
1718 if (NOT TARGET ${target_name} )
1819 add_library (${target_name} OBJECT)
1920
20- target_compile_features (${target_name} PRIVATE cxx_std_17 )
21+ target_compile_features (${target_name} PRIVATE ${ZEEK_CXX_STD} )
2122 set_target_properties (${target_name} PROPERTIES CXX_EXTENSIONS OFF )
2223 endif ()
2324 add_dependencies (${target_name} zeek_autogen_files)
@@ -58,6 +59,19 @@ function (zeek_add_static_plugin ns name)
5859 #set(WERROR_FLAG "/WX")
5960 else ()
6061 set (WERROR_FLAG "-Werror" )
62+
63+ # With versions >=13.0 GCC gained `-Warray-bounds` which reports false
64+ # positives, see e.g., https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111273.
65+ if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
66+ list (APPEND WERROR_FLAG "-Wno-error=array-bounds" )
67+ endif ()
68+
69+ # With versions >=11.0 GCC is retruning false positives for -Wrestrict. See
70+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366. It's more prevalent
71+ # building with -std=c++20.
72+ if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
73+ list (APPEND WERROR_FLAG "-Wno-error=restrict" )
74+ endif ()
6175 endif ()
6276 endif ()
6377
You can’t perform that action at this time.
0 commit comments