From 993794f5f64b75d40333dfc9fefe8f4e88a158bc Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 8 Sep 2025 11:16:09 -0400 Subject: [PATCH] CheckCompilerFlag: Avoid matching parts of multiple messages Diagnostic messages for unsupported flags appear on a single line. Do not accidentally match unrelated messages across multiple lines. Fixes: #27156 --- ...CMakeCheckCompilerFlagCommonPatterns.cmake | 24 ++++++++--------- Modules/Internal/CheckFlagCommonConfig.cmake | 26 +++++++++---------- Modules/Internal/CheckLinkerFlag.cmake | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake index 3633c53d9a..92fdc69413 100644 --- a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake +++ b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake @@ -8,24 +8,24 @@ macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR) set(${_VAR} - FAIL_REGEX "[Uu]nrecogni[sz]ed .*option" # GNU, NAG, Fujitsu - FAIL_REGEX "switch .* is no longer supported" # GNU - FAIL_REGEX "unknown .*option" # Clang - FAIL_REGEX "optimization flag .* not supported" # Clang + FAIL_REGEX "[Uu]nrecogni[sz]ed [^\n]*option" # GNU, NAG, Fujitsu + FAIL_REGEX "switch [^\n]* is no longer supported" # GNU + FAIL_REGEX "unknown [^\n]*option" # Clang + FAIL_REGEX "optimization flag [^\n]* not supported" # Clang FAIL_REGEX "unknown argument ignored" # Clang (cl) FAIL_REGEX "ignoring unknown option" # MSVC, Intel FAIL_REGEX "warning D9002" # MSVC, any lang - FAIL_REGEX "option.*not supported" # Intel - FAIL_REGEX "invalid argument .*option" # Intel - FAIL_REGEX "ignoring option .*argument required" # Intel - FAIL_REGEX "ignoring option .*argument is of wrong type" # Intel + FAIL_REGEX "option[^\n]*not supported" # Intel + FAIL_REGEX "invalid argument [^\n]*option" # Intel + FAIL_REGEX "ignoring option [^\n]*argument required" # Intel + FAIL_REGEX "ignoring option [^\n]*argument is of wrong type" # Intel # noqa: spellcheck off FAIL_REGEX "[Uu]nknown option" # HP # noqa: spellcheck on FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro - FAIL_REGEX "command option .* is not recognized" # XL - FAIL_REGEX "command option .* contains an incorrect subargument" # XL - FAIL_REGEX "Option .* is not recognized. Option will be ignored." # XL + FAIL_REGEX "command option [^\n]* is not recognized" # XL + FAIL_REGEX "command option [^\n]* contains an incorrect subargument" # XL + FAIL_REGEX "Option [^\n]* is not recognized. Option will be ignored." # XL FAIL_REGEX "not supported in this configuration. ignored" # AIX FAIL_REGEX "File with unknown suffix passed to linker" # PGI # noqa: spellcheck off @@ -35,7 +35,7 @@ macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR) FAIL_REGEX "Incorrect command line option:" # Borland FAIL_REGEX "Warning: illegal option" # SunStudio 12 FAIL_REGEX "[Ww]arning: Invalid suboption" # Fujitsu - FAIL_REGEX "An invalid option .* appears on the command line" # Cray + FAIL_REGEX "An invalid option [^\n]* appears on the command line" # Cray FAIL_REGEX "WARNING: invalid compiler option" # TI armcl ) endmacro () diff --git a/Modules/Internal/CheckFlagCommonConfig.cmake b/Modules/Internal/CheckFlagCommonConfig.cmake index 845666b327..a5459d189b 100644 --- a/Modules/Internal/CheckFlagCommonConfig.cmake +++ b/Modules/Internal/CheckFlagCommonConfig.cmake @@ -12,31 +12,31 @@ macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS) if("${_LANG}" STREQUAL "C") set(${_SRC} "int main(void) { return 0; }") set(${_PATTERNS} - FAIL_REGEX "command[ -]line option .* is valid for .* but not for C" - FAIL_REGEX "-Werror=.* argument .* is not valid for C" + FAIL_REGEX "command[ -]line option [^\n]* is valid for [^\n]* but not for C" + FAIL_REGEX "-Werror=[^\n]* argument [^\n]* is not valid for C" ) elseif("${_LANG}" STREQUAL "CXX") set(${_SRC} "int main() { return 0; }") set(${_PATTERNS} - FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" - FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+" + FAIL_REGEX "command[ -]line option [^\n]* is valid for [^\n]* but not for C\\+\\+" + FAIL_REGEX "-Werror=[^\n]* argument [^\n]* is not valid for C\\+\\+" ) elseif("${_LANG}" STREQUAL "CUDA") set(${_SRC} "__host__ int main() { return 0; }") set(${_PATTERNS} - FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU - FAIL_REGEX "argument unused during compilation: .*" # Clang + FAIL_REGEX "command[ -]line option [^\n]* is valid for [^\n]* but not for C\\+\\+" # Host GNU + FAIL_REGEX "argument unused during compilation: [^\n]*" # Clang ) elseif("${_LANG}" STREQUAL "Fortran") set(${_SRC} " program test\n stop\n end program") set(${_PATTERNS} - FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran" - FAIL_REGEX "argument unused during compilation: .*" # LLVMFlang + FAIL_REGEX "command[ -]line option [^\n]* is valid for [^\n]* but not for Fortran" + FAIL_REGEX "argument unused during compilation: [^\n]*" # LLVMFlang ) elseif("${_LANG}" STREQUAL "HIP") set(${_SRC} "__host__ int main() { return 0; }") set(${_PATTERNS} - FAIL_REGEX "argument unused during compilation: .*" # Clang + FAIL_REGEX "argument unused during compilation: [^\n]*" # Clang ) elseif("${_LANG}" STREQUAL "OBJC") set(${_SRC} [=[ @@ -45,8 +45,8 @@ macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS) #endif int main(void) { return 0; }]=]) set(${_PATTERNS} - FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU - FAIL_REGEX "argument unused during compilation: .*" # Clang + FAIL_REGEX "command[ -]line option [^\n]* is valid for [^\n]* but not for Objective-C" # GNU + FAIL_REGEX "argument unused during compilation: [^\n]*" # Clang ) elseif("${_LANG}" STREQUAL "OBJCXX") set(${_SRC} [=[ @@ -55,8 +55,8 @@ macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS) #endif int main(void) { return 0; }]=]) set(${_PATTERNS} - FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU - FAIL_REGEX "argument unused during compilation: .*" # Clang + FAIL_REGEX "command[ -]line option [^\n]* is valid for [^\n]* but not for Objective-C\\+\\+" # GNU + FAIL_REGEX "argument unused during compilation: [^\n]*" # Clang ) elseif("${_LANG}" STREQUAL "ISPC") set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }") diff --git a/Modules/Internal/CheckLinkerFlag.cmake b/Modules/Internal/CheckLinkerFlag.cmake index 64fdff831a..461c765b8c 100644 --- a/Modules/Internal/CheckLinkerFlag.cmake +++ b/Modules/Internal/CheckLinkerFlag.cmake @@ -27,7 +27,7 @@ function(CMAKE_CHECK_LINKER_FLAG _lang _flag _var) foreach(flag IN LISTS _flag) string(REGEX REPLACE "([][+.*?()^$])" [[\\\1]] _flag_regex "${flag}") list(APPEND _common_patterns - FAIL_REGEX "warning: .*${_flag_regex}.* ignored" + FAIL_REGEX "warning: [^\n]*${_flag_regex}[^\n]* ignored" ) endforeach()