From 67de5b7b82c6f61c5d349c70de81dde58bb79dd1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 13 Feb 2024 15:16:26 -0500 Subject: VS: Suppress MSBuild default settings affected by UseDebugLibraries `Microsoft.Cl.Common.props` changes some default settings based on `UseDebugLibraries`. CMake models its own controls for these settings, so if the project does not set them, explicitly suppress them to avoid letting `UseDebugLibraries` affect them. --- Source/cmVisualStudio10TargetGenerator.cxx | 22 +++++++++++++++++++++- Tests/MSVCRuntimeLibrary/CMakeLists.txt | 4 ---- .../VS10Project/RuntimeLibrary-check.cmake | 2 +- .../RunCMake/VS10Project/VsJustMyCode-check.cmake | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ced7acd..8114b83 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3155,7 +3155,10 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( Options& linkOptions = *(this->LinkOptions[configName]); const std::string cond = this->CalcCondition(configName); - if (this->IPOEnabledConfigurations.count(configName) == 0) { + if (this->IPOEnabledConfigurations.count(configName) > 0) { + // Suppress LinkIncremental in favor of WholeProgramOptimization. + e1.WritePlatformConfigTag("LinkIncremental", cond, ""); + } else { const char* incremental = linkOptions.GetFlag("LinkIncremental"); e1.WritePlatformConfigTag("LinkIncremental", cond, (incremental ? incremental : "true")); @@ -3500,6 +3503,23 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.RemoveFlag("CompileAs"); } + if (this->ProjectType == VsProjectType::vcxproj && this->MSTools) { + // Suppress Microsoft.Cl.Common.props default settings for which the + // project specifies no flags. Do not let UseDebugLibraries affect them. + if (!clOptions.HasFlag("BasicRuntimeChecks")) { + clOptions.AddFlag("BasicRuntimeChecks", "Default"); + } + if (!clOptions.HasFlag("Optimization")) { + clOptions.AddFlag("Optimization", ""); + } + if (!clOptions.HasFlag("RuntimeLibrary")) { + clOptions.AddFlag("RuntimeLibrary", ""); + } + if (!clOptions.HasFlag("SupportJustMyCode")) { + clOptions.AddFlag("SupportJustMyCode", ""); + } + } + this->ClOptions[configName] = std::move(pOptions); return true; } diff --git a/Tests/MSVCRuntimeLibrary/CMakeLists.txt b/Tests/MSVCRuntimeLibrary/CMakeLists.txt index f7d9fec..f1ed9b4 100644 --- a/Tests/MSVCRuntimeLibrary/CMakeLists.txt +++ b/Tests/MSVCRuntimeLibrary/CMakeLists.txt @@ -57,10 +57,6 @@ function(verify lang src) # VS 2005 and above default to multi-threaded. target_compile_definitions(empty-${lang} PRIVATE VERIFY_MT) endif() - if(CMAKE_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])") - # VS 2010 and above have a different default runtime library for projects than 'cl'. - target_compile_definitions(empty-${lang} PRIVATE VERIFY_DLL) - endif() endif() endfunction() diff --git a/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake b/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake index 689b35f..b5b195a 100644 --- a/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake +++ b/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake @@ -9,7 +9,7 @@ macro(RuntimeLibrary_check tgt rtl_expect) file(STRINGS "${vcProjectFile}" lines) foreach(line IN LISTS lines) - if(line MATCHES "^ *([^<>]+)") + if(line MATCHES "^ *([^<>]*)") set(rtl_actual "${CMAKE_MATCH_1}") if(NOT "${rtl_actual}" STREQUAL "${rtl_expect}") set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has RuntimeLibrary '${rtl_actual}', not '${rtl_expect}'.") diff --git a/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake b/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake index 7119976..e76d931 100644 --- a/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake +++ b/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake @@ -9,7 +9,7 @@ macro(VsJustMyCode_check tgt jmc_expect) file(STRINGS "${vcProjectFile}" lines) foreach(line IN LISTS lines) - if(line MATCHES "^ *([^<>]+)") + if(line MATCHES "^ *([^<>]*)") set(jmc_actual "${CMAKE_MATCH_1}") if(NOT "${jmc_actual}" STREQUAL "${jmc_expect}") set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has '${jmc_actual}', not '${jmc_expect}'.") -- cgit v0.12