Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BuiltInSpicyAnalyzer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

set(ZEEK_LEGACY_ANALYZERS CACHE INTERNAL "")
set(ZEEK_SKIPPED_ANALYZERS CACHE INTERNAL "")
include(RequireCXXStd)

# Force Spicy include directories to the front of the include paths.
#
Expand Down Expand Up @@ -92,7 +93,7 @@ function (spicy_add_analyzer)

set(lib "spicy_${SPICY_ANALYZER_NAME}")
add_library(${lib} OBJECT ${generated_sources} ${cxx_sources})
target_compile_features(${lib} PRIVATE cxx_std_17)
target_compile_features(${lib} PRIVATE ${ZEEK_CXX_STD})
set_target_properties(${lib} PROPERTIES CXX_EXTENSIONS OFF)

target_include_directories(${lib} PRIVATE ${SPICY_PLUGIN_PATH}/include
Expand Down
87 changes: 0 additions & 87 deletions RequireCXX17.cmake

This file was deleted.

39 changes: 39 additions & 0 deletions RequireCXXStd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Check for a specific C++ standard level, and require the compiler to
# support that via some CMake settings.

if (DEFINED ZEEK_CXX_STD)
return()
endif ()

# Require a specific C++ standard and set the proper flag when creating targets.
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)

# Disable using extensions provided by various compilers. Notably this keeps us
# setting it to c++20 instead of gnu++20 with GCC.
set(CMAKE_CXX_EXTENSIONS OFF)

set(_old_cmake_required_flags "${CMAKE_REQUIRED_FLAGS}")
if (MSVC)
set(CMAKE_REQUIRED_FLAGS "/std:c++20")
else ()
set(CMAKE_REQUIRED_FLAGS "-std=c++20")
endif ()

include(CheckCXXSourceCompiles)

# The <version> header is a good baseline version of C++20 support for us
# since we can use it to determine support for various features in other
# places.
set(cxx_std_testcode "#include <version>
int main() { }")

check_cxx_source_compiles("${cxx_std_testcode}" cxx_std_works)

set(CMAKE_REQUIRED_FLAGS "${_old_cmake_required_flags}")

if (cxx_std_works)
set(ZEEK_CXX_STD cxx_std_20)
else ()
message(FATAL_ERROR "failed using C++20 for compilation")
endif ()
4 changes: 3 additions & 1 deletion ZeekPluginCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## This set is used by both static and dynamic plugins via
## ZeekPluginStatic and ZeekPluginDynamic, respectively.

include(RequireCXXStd)

# Begins a plugin definition, giving its namespace and name as the arguments.
# The DISABLE_CPP_TESTS option disables unit test support. When not provided,
# unit-testing is enabled when Zeek supports it, and disabled otherwise.
Expand All @@ -23,7 +25,7 @@ macro (zeek_plugin_begin ns name)
set(_plugin_bif_files "")
set(_plugin_pac_args "")

target_compile_features(${_plugin_lib} PRIVATE cxx_std_17)
target_compile_features(${_plugin_lib} PRIVATE ${ZEEK_CXX_STD})
set_target_properties(${_plugin_lib} PROPERTIES CXX_EXTENSIONS OFF)
endmacro ()

Expand Down
3 changes: 2 additions & 1 deletion ZeekPluginDynamic.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(GetArchitecture)
include(RequireCXXStd)

# Sets `target` to contain the CMake target name for a dynamic plugin.
macro (zeek_get_dynamic_plugin_target target ns name)
Expand Down Expand Up @@ -29,7 +30,7 @@ function (zeek_add_dynamic_plugin ns name)
if (NOT TARGET ${target_name})
add_library(${target_name} MODULE)

target_compile_features(${target_name} PRIVATE cxx_std_17)
target_compile_features(${target_name} PRIVATE ${ZEEK_CXX_STD})
set_target_properties(${target_name} PROPERTIES CXX_EXTENSIONS OFF)
endif ()

Expand Down
16 changes: 15 additions & 1 deletion ZeekPluginStatic.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include(BifCl)
include(BinPAC)
include(RequireCXXStd)

# Sets `target` to contain the CMake target name for a static plugin.
macro (zeek_get_static_plugin_target target ns name)
Expand All @@ -17,7 +18,7 @@ function (zeek_add_static_plugin ns name)
if (NOT TARGET ${target_name})
add_library(${target_name} OBJECT)

target_compile_features(${target_name} PRIVATE cxx_std_17)
target_compile_features(${target_name} PRIVATE ${ZEEK_CXX_STD})
set_target_properties(${target_name} PROPERTIES CXX_EXTENSIONS OFF)
endif ()
add_dependencies(${target_name} zeek_autogen_files)
Expand Down Expand Up @@ -58,6 +59,19 @@ function (zeek_add_static_plugin ns name)
#set(WERROR_FLAG "/WX")
else ()
set(WERROR_FLAG "-Werror")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again? :-)

If there's more proliferation over time, maybe a that could be unified in RequireCXXStd then.

# With versions >=13.0 GCC gained `-Warray-bounds` which reports false
# positives, see e.g., https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111273.
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
list(APPEND WERROR_FLAG "-Wno-error=array-bounds")
endif ()

# With versions >=11.0 GCC is retruning false positives for -Wrestrict. See
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366. It's more prevalent
# building with -std=c++20.
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
list(APPEND WERROR_FLAG "-Wno-error=restrict")
endif ()
endif ()
endif ()

Expand Down
Loading