Merge topic 'msvc-flags-fix-for-27177'

9851ddfc11 VS: Check all default suppressed MSBuild flags
7202539fd4 VS: Suppress MSBuild default flags not specified by project or user

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11165
This commit is contained in:
Brad King
2025-09-12 15:42:58 +00:00
committed by Kitware Robot
2 changed files with 83 additions and 0 deletions

View File

@@ -3669,6 +3669,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,33 +5,105 @@ macro(VsDefaultCompilerFlags_check tgt)
return()
endif()
set(HAVE_BasicRuntimeChecks 0)
set(HAVE_BufferSecurityCheck 0)
set(HAVE_CallingConvention 0)
set(HAVE_FloatingPointModel 0)
set(HAVE_ForceConformanceInForLoopScope 0)
set(HAVE_MinimalRebuild 0)
set(HAVE_Optimization 0)
set(HAVE_RemoveUnreferencedCodeData 0)
set(HAVE_RuntimeLibrary 0)
set(HAVE_SupportJustMyCode 0)
set(HAVE_TreatWChar_tAsBuiltInType 0)
file(STRINGS "${vcProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "^ *<BasicRuntimeChecks>Default</BasicRuntimeChecks>")
set(HAVE_BasicRuntimeChecks 1)
endif()
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()
if(line MATCHES "^ *<MinimalRebuild></MinimalRebuild>")
set(HAVE_MinimalRebuild 1)
endif()
if(line MATCHES "^ *<Optimization>[^\\n<]*</Optimization>")
set(HAVE_Optimization 1)
endif()
if(line MATCHES "^ *<RemoveUnreferencedCodeData></RemoveUnreferencedCodeData>")
set(HAVE_RemoveUnreferencedCodeData 1)
endif()
if(line MATCHES "^ *<RuntimeLibrary>[^\\n<]*</RuntimeLibrary>")
set(HAVE_RuntimeLibrary 1)
endif()
if(line MATCHES "^ *<SupportJustMyCode></SupportJustMyCode>")
set(HAVE_SupportJustMyCode 1)
endif()
if(line MATCHES "^ *<TreatWChar_tAsBuiltInType></TreatWChar_tAsBuiltInType>")
set(HAVE_TreatWChar_tAsBuiltInType 1)
endif()
endforeach()
if(NOT HAVE_BasicRuntimeChecks)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <BasicRuntimeChecks> property.")
return()
endif()
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()
endif()
if(NOT HAVE_MinimalRebuild)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <MinimalRebuild> property.")
return()
endif()
if(NOT HAVE_Optimization)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <Optimization> property.")
return()
endif()
if(NOT HAVE_RemoveUnreferencedCodeData)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <RemoveUnreferencedCodeData> property.")
return()
endif()
if(NOT HAVE_RuntimeLibrary)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <RuntimeLibrary> property.")
return()
endif()
if(NOT HAVE_SupportJustMyCode)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <SupportJustMyCode> property.")
return()
endif()
if(NOT HAVE_TreatWChar_tAsBuiltInType)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <TreatWChar_tAsBuiltInType> property.")
return()