History

configure: treat unrecognized flags as errors on MSVC

This is important for feature checking to work correctly. It can happen that an unrecognized flag passes the compile test with only a warning, while failing in preprocessor-only check with an error. This causes all test_cpp calls to fail and silently produces arguably broken MSVC builds. Also, all check_* functions don't work as expected, because they assume the check passed, even though there was a warning. Additionally, this brings the behavior in line with GCC/Clang based builds, failing early on unrecognized flags instead of silently continuing with warnings in the log. The /options:strict option is available starting in Visual Studio 2022 version 17.0. Because of that, we cannot use check_cflags alone, as it would add this flag for older MSVC versions and produce warnings. So, we need to manually perform a version check. A bit of a chicken and egg problem. Perform the version check before adding extra flags from the user to ensure we don't silently fail the preprocessor check due to invalid flags on older MSVC versions. Note that behavior differs depending on whether we are compiling or only preprocessing. This fixes silent different between handling: `cl.exe -P foo c.c` c1: fatal error C1083: Cannot open source file: 'foo': No such file or directory `cl.exe -c foo c.c` cl : Command line warning D9024 : unrecognized source file type 'foo', object file assumed Where -P fails, while -c throws warnings only. Of course `foo` is completely bogus here, but depends on the flags or configuration this may be unsupported argument. Or even some converted path from MSYS when run inside it. The objective is to always error out instead of silently hiding this. Use check_cflags even after the _MSC_FULL_VER check, for non-MSVC compilers. For example Clang-CL impersonate MSVC, but does not support -options:strict flag currently.

Kacper Michajłow committed 1 year ago

Commit bc012ac1 parent 50408c51 file · +6 −0Browse files

Unified · Split

configure+6−0
@@ -5284,6 +5284,12 @@ else · 5283 unmodified lines
5284 ar_o='$@'5284 ar_o='$@'
5285fi5285fi
5286 5286
5287# Treat unrecognized flags as errors on MSVC
5288test_cpp_condition windows.h "_MSC_FULL_VER >= 193030705" &&
5289 check_cflags -options:strict
5290test_host_cpp_condition windows.h "_MSC_FULL_VER >= 193030705" &&
5291 check_host_cflags -options:strict
5292
5287add_cflags $extra_cflags5293add_cflags $extra_cflags
5288add_cxxflags $extra_cxxflags5294add_cxxflags $extra_cxxflags
5289add_objcflags $extra_objcflags5295add_objcflags $extra_objcflags

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t