VS: Add UseDebugLibraries to vcxproj files by default

Use heuristics to select a reasonable value.  Add policy CMP0162
to provide compatibility with existing projects.

Fixes: #25327
This commit is contained in:
Brad King
2024-02-16 12:42:37 -05:00
parent 47136b6959
commit 721d8b192a
24 changed files with 130 additions and 9 deletions
@@ -1633,6 +1633,19 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesCommon(
if (!useDebugLibraries.empty()) {
maybeUseDebugLibraries = cmIsOn(useDebugLibraries);
}
} else if (this->GeneratorTarget->GetPolicyStatusCMP0162() ==
cmPolicies::NEW) {
// The project did not explicitly specify a value for this target.
// If the target compiles sources for a known MSVC runtime library,
// base our default value on that.
if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
maybeUseDebugLibraries = this->ClOptions[config]->UsingDebugRuntime();
}
// For other targets, such as UTILITY targets, base our default
// on the configuration name.
if (!maybeUseDebugLibraries) {
maybeUseDebugLibraries = cmSystemTools::UpperCase(config) == "DEBUG"_s;
}
}
if (maybeUseDebugLibraries) {
if (*maybeUseDebugLibraries) {