From 9c593114adc793a4ce5ff98bdd5b6536d965b6a8 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 27 Jan 2025 00:10:29 +0100 Subject: [PATCH 1/4] use `VERSION_GREATER_EQUAL` in CMake it was introduced in CMake 3.7 --- cmake/compilerDefinitions.cmake | 2 +- cmake/compileroptions.cmake | 2 +- cmake/options.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index 08854b65823..da795ee5e14 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -16,7 +16,7 @@ endif() if(CPPCHK_GLIBCXX_DEBUG AND UNIX AND CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(USE_LIBCXX) - if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 18 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 18) + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) else() add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index e42145d8809..a91ddbfdef7 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -86,7 +86,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") #add_compile_options_safe(-Wunused-macros) #add_compile_options_safe(-Wpedantic) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14) + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14) # TODO: verify this regression still exists in clang-15 if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") # work around performance regression - see https://github.com/llvm/llvm-project/issues/53555 diff --git a/cmake/options.cmake b/cmake/options.cmake index dbbbfecb93d..4e1e4c96c66 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -82,7 +82,7 @@ option(NO_WINDOWS_SEH "Disable usage of Windows SEH" # TODO: disable by default like make build? option(FILESDIR "Hard-coded directory for files to load from" OFF) -if(CMAKE_VERSION VERSION_EQUAL "3.16" OR CMAKE_VERSION VERSION_GREATER "3.16") +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.16") set(CMAKE_DISABLE_PRECOMPILE_HEADERS Off CACHE BOOL "Disable precompiled headers") # need to disable the prologue or it will be treated like a system header and not emit any warnings # see https://gitlab.kitware.com/cmake/cmake/-/issues/21219 From 0554a11d207bffc03e2cf6b6aeef5d487545337d Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 27 Jan 2025 00:11:51 +0100 Subject: [PATCH 2/4] removed CMake option `ANALYZE_DATAFLOW` it cannot be used on its own - it generates data which can be leveraged by tools --- cmake/dynamic_analyzer_options.cmake | 6 ------ cmake/options.cmake | 1 - cmake/printInfo.cmake | 1 - 3 files changed, 8 deletions(-) diff --git a/cmake/dynamic_analyzer_options.cmake b/cmake/dynamic_analyzer_options.cmake index 405bdfc6117..1d82fc2dbf4 100644 --- a/cmake/dynamic_analyzer_options.cmake +++ b/cmake/dynamic_analyzer_options.cmake @@ -31,9 +31,3 @@ if(ANALYZE_UNDEFINED) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=nullability") endif() endif() - -if(ANALYZE_DATAFLOW) - add_compile_options(-fsanitize=dataflow) - - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=dataflow") -endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 4e1e4c96c66..36b79a53cf0 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -16,7 +16,6 @@ option(ANALYZE_MEMORY "Clang dynamic analyzer: detector of uninitialized r option(ANALYZE_ADDRESS "Clang dynamic analyzer: fast memory error detector. " OFF) option(ANALYZE_THREAD "Clang dynamic analyzer: tool that detects data races. " OFF) option(ANALYZE_UNDEFINED "Clang dynamic analyzer: undefined behavior checker. " OFF) -option(ANALYZE_DATAFLOW "Clang dynamic analyzer: general dynamic dataflow analysis." OFF) option(WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF) option(EXTERNALS_AS_SYSTEM "Treat externals as system includes" OFF) diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 9ea57fe31a7..7feaf60f603 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -30,7 +30,6 @@ message(STATUS "ANALYZE_MEMORY = ${ANALYZE_MEMORY}") message(STATUS "ANALYZE_ADDRESS = ${ANALYZE_ADDRESS}") message(STATUS "ANALYZE_THREAD = ${ANALYZE_THREAD}") message(STATUS "ANALYZE_UNDEFINED = ${ANALYZE_UNDEFINED}") -message(STATUS "ANALYZE_DATAFLOW = ${ANALYZE_DATAFLOW}") message(STATUS) message(STATUS "WARNINGS_ARE_ERRORS = ${WARNINGS_ARE_ERRORS}") message(STATUS "EXTERNALS_AS_SYSTEM = ${EXTERNALS_AS_SYSTEM}") From 3a03d079f269ff3cd13af6d1be889521f718cf4e Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 27 Jan 2025 00:13:11 +0100 Subject: [PATCH 3/4] cmake/options.cmake: added some messages and bailouts instead of modifying/ignoring options silently --- cmake/options.cmake | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index 36b79a53cf0..e178901518e 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -6,16 +6,20 @@ if(DEFINED CMAKE_BUILD_TYPE) endif() if(NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type set - defaulting to Debug") set(CMAKE_BUILD_TYPE "Debug") endif() # ---------------------------------------------------------------------------- # PROJECT CONFIGURATION # ---------------------------------------------------------------------------- -option(ANALYZE_MEMORY "Clang dynamic analyzer: detector of uninitialized reads." OFF) -option(ANALYZE_ADDRESS "Clang dynamic analyzer: fast memory error detector. " OFF) -option(ANALYZE_THREAD "Clang dynamic analyzer: tool that detects data races. " OFF) -option(ANALYZE_UNDEFINED "Clang dynamic analyzer: undefined behavior checker. " OFF) +option(ANALYZE_MEMORY "Build with MemorySanitizer to detect usage of uninitialized memory" OFF) +if(ANALYZE_MEMORY) + message(STATUS "MemorySanitzer requires an instrumented libc++") +endif() +option(ANALYZE_ADDRESS "Build with AddressSanitzer to detect memory error" OFF) +option(ANALYZE_THREAD "Build with ThreadSanitizer to detect data races" OFF) +option(ANALYZE_UNDEFINED "Build with UndefinedBehaviorSanitizer to detect undefined behavior" OFF) option(WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF) option(EXTERNALS_AS_SYSTEM "Treat externals as system includes" OFF) @@ -41,8 +45,8 @@ else() endif() option(BUILD_CORE_DLL "Build lib as cppcheck-core.dll with Visual Studio" OFF) -if(NOT MSVC) - set(BUILD_CORE_DLL OFF) +if(BUILD_CORE_DLL AND NOT MSVC) + message(FATAL_ERROR "Building of lib as DLL is only supported with Visual Studio") endif() option(BUILD_TESTS "Build tests" OFF) option(REGISTER_TESTS "Register tests in CTest" ON) @@ -59,19 +63,21 @@ option(REGISTER_GUI_TESTS "Register GUI tests in CTest" option(BUILD_ONLINE_HELP "Build online help" OFF) option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF) -option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON) -if(BUILD_CORE_DLL) - set(USE_BUNDLED_TINYXML2 ON) +option(USE_BUNDLED_TINYXML2 "Usage of bundled TinyXML2 library" ON) +if(BUILD_CORE_DLL AND NOT USE_BUNDLED_TINYXML2) + message(FATAL_ERROR "Cannot use external TinyXML2 library when building lib as DLL") endif() option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON) option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j" OFF) -option(USE_BOOST "Usage of Boost" OFF) -option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF) -option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF) - if(DISALLOW_THREAD_EXECUTOR AND WIN32) message(FATAL_ERROR "Cannot disable usage of ThreadExecutor on Windows as no other executor implementation is currently available") endif() +option(USE_BOOST "Usage of Boost" OFF) +option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF) +if (NOT USE_BOOST AND USE_BOOST_INT128) + message(FATAL_ERROR "USE_BOOST_INT128 requires USE_BOOST to be enabled") +endif() +option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF) option(DISABLE_CRTDBG_MAP_ALLOC "Disable usage of Visual Studio C++ memory leak detection in Debug build" OFF) option(NO_UNIX_SIGNAL_HANDLING "Disable usage of Unix Signal Handling" OFF) From d69f71ec27b51924fab35adcf835adf12bdeceff Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 27 Jan 2025 00:15:43 +0100 Subject: [PATCH 4/4] fixed #13147 - deprecated `WARNINGS_ARE_ERRORS` in favor of `CMAKE_COMPILE_WARNING_AS_ERROR` --- cmake/compileroptions.cmake | 4 ++-- cmake/options.cmake | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index a91ddbfdef7..108e8da30fd 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -33,7 +33,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" # "Release" uses -O3 by default add_compile_options(-O2) endif() - if(WARNINGS_ARE_ERRORS) + if(CMAKE_COMPILE_WARNING_AS_ERROR) add_compile_options(-Werror) endif() add_compile_options(-pedantic) # TODO: is this implied by -Weverything? @@ -158,7 +158,7 @@ if(MSVC) # General add_compile_options(/W4) # Warning Level add_compile_options(/Zi) # Debug Information Format - Program Database - if(WARNINGS_ARE_ERRORS) + if(CMAKE_COMPILE_WARNING_AS_ERROR) add_compile_options(/WX) # Treat Warning As Errors endif() add_compile_options(/MP) # Multi-processor Compilation diff --git a/cmake/options.cmake b/cmake/options.cmake index e178901518e..dc68e03fe84 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -22,6 +22,12 @@ option(ANALYZE_THREAD "Build with ThreadSanitizer to detect data races" option(ANALYZE_UNDEFINED "Build with UndefinedBehaviorSanitizer to detect undefined behavior" OFF) option(WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF) +if(WARNINGS_ARE_ERRORS) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + message(WARNING "WARNINGS_ARE_ERRORS is deprecated - please use CMAKE_COMPILE_WARNING_AS_ERROR instead") + endif() + set(CMAKE_COMPILE_WARNING_AS_ERROR On) +endif() option(EXTERNALS_AS_SYSTEM "Treat externals as system includes" OFF) set(USE_MATCHCOMPILER "Auto" CACHE STRING "Usage of match compiler")