From 806f39a8f85e9313028432f19ff681ec5a03753f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 3 May 2024 16:09:11 +0200 Subject: [PATCH] fixed #12666 - got rid of ill-conceived `USE_MATCHCOMPILER` CMake option validation (#6348) 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. (cherry picked from commit c4be14dde2a1217d07df65c9cdd08a4b5915386e) --- 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 d63d67079af..a18592f588a 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(