mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 03:39:43 -06:00
VS: Suppress MSBuild default flags not specified by project or user
`Microsoft.Cl.Common.props` adds some `cl` flags by default, but for CMake they may not match what's produced by command-line generators. If the `-Zc:wchar_t`, `-Zc:forScope`, and/or `-Zc:inline` flags are not specified by the project or user, suppress them. Fixes: #26964
This commit is contained in:
@@ -3632,18 +3632,27 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
|
||||
if (!clOptions.HasFlag("BasicRuntimeChecks")) {
|
||||
clOptions.AddFlag("BasicRuntimeChecks", "Default");
|
||||
}
|
||||
if (!clOptions.HasFlag("ForceConformanceInForLoopScope")) {
|
||||
clOptions.AddFlag("ForceConformanceInForLoopScope", "");
|
||||
}
|
||||
if (!clOptions.HasFlag("MinimalRebuild")) {
|
||||
clOptions.AddFlag("MinimalRebuild", "");
|
||||
}
|
||||
if (!clOptions.HasFlag("Optimization")) {
|
||||
clOptions.AddFlag("Optimization", "");
|
||||
}
|
||||
if (!clOptions.HasFlag("RemoveUnreferencedCodeData")) {
|
||||
clOptions.AddFlag("RemoveUnreferencedCodeData", "");
|
||||
}
|
||||
if (!clOptions.HasFlag("RuntimeLibrary")) {
|
||||
clOptions.AddFlag("RuntimeLibrary", "");
|
||||
}
|
||||
if (!clOptions.HasFlag("SupportJustMyCode")) {
|
||||
clOptions.AddFlag("SupportJustMyCode", "");
|
||||
}
|
||||
if (!clOptions.HasFlag("TreatWChar_tAsBuiltInType")) {
|
||||
clOptions.AddFlag("TreatWChar_tAsBuiltInType", "");
|
||||
}
|
||||
}
|
||||
|
||||
this->ClOptions[configName] = std::move(pOptions);
|
||||
|
||||
@@ -34,6 +34,7 @@ run_cmake(VsCSharpReferenceProps)
|
||||
run_cmake(VsCSharpWithoutSources)
|
||||
run_cmake(VsCSharpDeployFiles)
|
||||
run_cmake(VSCSharpDefines)
|
||||
run_cmake(VsDefaultFlags)
|
||||
run_cmake(VsSdkDirectories)
|
||||
run_cmake(VsGlobals)
|
||||
run_cmake(VsProjectImport)
|
||||
|
||||
41
Tests/RunCMake/VS10Project/VsDefaultFlags-check.cmake
Normal file
41
Tests/RunCMake/VS10Project/VsDefaultFlags-check.cmake
Normal file
@@ -0,0 +1,41 @@
|
||||
macro(VsDefaultFlags_check tgt)
|
||||
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/${tgt}.vcxproj")
|
||||
if(NOT EXISTS "${vcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
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 "^ *<ForceConformanceInForLoopScope></ForceConformanceInForLoopScope>")
|
||||
set(HAVE_ForceConformanceInForLoopScope 1)
|
||||
endif()
|
||||
if(line MATCHES "^ *<RemoveUnreferencedCodeData></RemoveUnreferencedCodeData>")
|
||||
set(HAVE_RemoveUnreferencedCodeData 1)
|
||||
endif()
|
||||
if(line MATCHES "^ *<TreatWChar_tAsBuiltInType></TreatWChar_tAsBuiltInType>")
|
||||
set(HAVE_TreatWChar_tAsBuiltInType 1)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT HAVE_ForceConformanceInForLoopScope)
|
||||
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <ForceConformanceInForLoopScope> 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_TreatWChar_tAsBuiltInType)
|
||||
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <TreatWChar_tAsBuiltInType> property.")
|
||||
return()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
VsDefaultFlags_check(empty)
|
||||
2
Tests/RunCMake/VS10Project/VsDefaultFlags.cmake
Normal file
2
Tests/RunCMake/VS10Project/VsDefaultFlags.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
enable_language(C)
|
||||
add_library(empty empty.c)
|
||||
Reference in New Issue
Block a user