VS: Suppress MSBuild default flags not specified by project or user

This commit is contained in:
AJIOB
2025-09-10 10:26:22 +03:00
parent 082071203f
commit 7202539fd4
2 changed files with 38 additions and 0 deletions

View File

@@ -3664,6 +3664,17 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
if (!clOptions.HasFlag("BasicRuntimeChecks")) {
clOptions.AddFlag("BasicRuntimeChecks", "Default");
}
if (!clOptions.HasFlag("BufferSecurityCheck")) {
clOptions.AddFlag("BufferSecurityCheck", "");
}
if (!clOptions.HasFlag("CallingConvention")) {
clOptions.AddFlag("CallingConvention", "");
}
// We cannot use the `Default` value, because it is incompatible with
// VS2019 & first releases of VS2022
if (!clOptions.HasFlag("FloatingPointModel")) {
clOptions.AddFlag("FloatingPointModel", "");
}
if (!clOptions.HasFlag("ForceConformanceInForLoopScope")) {
clOptions.AddFlag("ForceConformanceInForLoopScope", "");
}

View File

@@ -5,12 +5,24 @@ macro(VsDefaultCompilerFlags_check tgt)
return()
endif()
set(HAVE_BufferSecurityCheck 0)
set(HAVE_CallingConvention 0)
set(HAVE_FloatingPointModel 0)
set(HAVE_ForceConformanceInForLoopScope 0)
set(HAVE_RemoveUnreferencedCodeData 0)
set(HAVE_TreatWChar_tAsBuiltInType 0)
file(STRINGS "${vcProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "^ *<BufferSecurityCheck></BufferSecurityCheck>")
set(HAVE_BufferSecurityCheck 1)
endif()
if(line MATCHES "^ *<CallingConvention></CallingConvention>")
set(HAVE_CallingConvention 1)
endif()
if(line MATCHES "^ *<FloatingPointModel></FloatingPointModel>")
set(HAVE_FloatingPointModel 1)
endif()
if(line MATCHES "^ *<ForceConformanceInForLoopScope></ForceConformanceInForLoopScope>")
set(HAVE_ForceConformanceInForLoopScope 1)
endif()
@@ -22,6 +34,21 @@ macro(VsDefaultCompilerFlags_check tgt)
endif()
endforeach()
if(NOT HAVE_BufferSecurityCheck)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <BufferSecurityCheck> property.")
return()
endif()
if(NOT HAVE_CallingConvention)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <CallingConvention> property.")
return()
endif()
if(NOT HAVE_FloatingPointModel)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <FloatingPointModel> property.")
return()
endif()
if(NOT HAVE_ForceConformanceInForLoopScope)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <ForceConformanceInForLoopScope> property.")
return()