From e046b77d5b6ca5e8a89476a2df931950f38aa46d Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 23 Apr 2024 17:22:01 +0200 Subject: [PATCH] fixed #12666 - got rid of ill-conceived `USE_MATCHCOMPILER` CMake option validation I went quite overboard when I introduced the validation of the define. That was not necessary in CMake as we provide feedback on the usage of the matchcompiler. So only handle the special options and otherwise rely on the regular CMake logic. --- cmake/options.cmake | 24 ++++++++++++++---------- lib/CMakeLists.txt | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index 0c48c06d27f..36685883460 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -22,19 +22,23 @@ option(WARNINGS_ARE_ERRORS "Treat warnings as errors" option(EXTERNALS_AS_SYSTEM "Treat externals as system includes" OFF) set(USE_MATCHCOMPILER "Auto" CACHE STRING "Usage of match compiler") -set(_MATCHCOMPILER_STRINGS Auto Off On Verify) -set_property(CACHE USE_MATCHCOMPILER PROPERTY STRINGS ${_MATCHCOMPILER_STRINGS}) -if(NOT ${USE_MATCHCOMPILER} IN_LIST _MATCHCOMPILER_STRINGS) - message(FATAL_ERROR "Invalid USE_MATCHCOMPILER value '${USE_MATCHCOMPILER}'") -endif() -if(USE_MATCHCOMPILER STREQUAL "Auto") - if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - set(USE_MATCHCOMPILER_OPT "On") +set_property(CACHE USE_MATCHCOMPILER PROPERTY STRINGS Auto Off On Verify) +if(USE_MATCHCOMPILER) + if(USE_MATCHCOMPILER STREQUAL "Auto") + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(STATUS "Non-debug build detected - enabling matchcompiler") + set(USE_MATCHCOMPILER_OPT "On") + else() + message(STATUS "Debug build detected - disabling matchcompiler") + set(USE_MATCHCOMPILER_OPT "Off") + endif() + elseif(USE_MATCHCOMPILER STREQUAL "Verify") + set(USE_MATCHCOMPILER_OPT "Verify") else() - set(USE_MATCHCOMPILER_OPT "Off") + set(USE_MATCHCOMPILER_OPT "On") endif() else() - set(USE_MATCHCOMPILER_OPT ${USE_MATCHCOMPILER}) + set(USE_MATCHCOMPILER_OPT "Off") endif() option(BUILD_CORE_DLL "Build lib as cppcheck-core.dll with Visual Studio" OFF) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 86a3970d8ff..7a884164761 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -10,7 +10,7 @@ function(build_src output filename) get_filename_component(file ${filename} NAME) set(outfile ${CMAKE_CURRENT_BINARY_DIR}/build/mc_${file}) set(${output} ${${output}} ${outfile} PARENT_SCOPE) - if (USE_MATCHCOMPILER STREQUAL "Verify") + if (USE_MATCHCOMPILER_OPT STREQUAL "Verify") set(verify_option "--verify") endif() add_custom_command(