Merge topic 'vs-link-defaults'

46e59b5168 Merge branch 'backport-vs-link-defaults' into vs-link-defaults
b6defd96c9 VS: Restore subsystem link flag for DLLs
91b9db90e5 VS: Restore subsystem link flag for DLLs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Alex Overchenko <aleksandr9809@gmail.com>
Merge-request: !11524
This commit is contained in:
Brad King 2025-12-18 15:29:59 +00:00 committed by Kitware Robot
commit 756c0757b2
2 changed files with 34 additions and 49 deletions

View File

@ -4624,35 +4624,32 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
}
if (this->MSTools) {
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
// Specify an entry point for executables.
if (this->GeneratorTarget->IsWin32Executable(config)) {
if (this->GlobalGenerator->TargetsWindowsCE()) {
linkOptions.AddFlag("SubSystem", "WindowsCE");
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
if (this->CharSet[config] == MsvcCharSet::Unicode) {
linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
} else {
linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
}
if (this->GeneratorTarget->IsWin32Executable(config)) {
if (this->GlobalGenerator->TargetsWindowsCE()) {
linkOptions.AddFlag("SubSystem", "WindowsCE");
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
if (this->CharSet[config] == MsvcCharSet::Unicode) {
linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
} else {
linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
}
} else {
linkOptions.AddFlag("SubSystem", "Windows");
}
} else {
if (this->GlobalGenerator->TargetsWindowsCE()) {
linkOptions.AddFlag("SubSystem", "WindowsCE");
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
if (this->CharSet[config] == MsvcCharSet::Unicode) {
linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
} else {
linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
}
}
} else {
linkOptions.AddFlag("SubSystem", "Console");
};
linkOptions.AddFlag("SubSystem", "Windows");
}
} else {
if (this->GlobalGenerator->TargetsWindowsCE()) {
linkOptions.AddFlag("SubSystem", "WindowsCE");
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
if (this->CharSet[config] == MsvcCharSet::Unicode) {
linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
} else {
linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
}
}
} else {
linkOptions.AddFlag("SubSystem", "Console");
};
}
if (cmValue stackVal = this->Makefile->GetDefinition(

View File

@ -110,12 +110,12 @@ macro(VsDefaultCompilerFlags_check tgt)
endif()
endmacro()
macro(VsDefaultLinkerFlags_check tgt needs_subsystem_console)
macro(VsDefaultLinkerFlags_check tgt)
set(HAVE_DataExecutionPrevention 0)
set(HAVE_ImageHasSafeExceptionHandlers 0)
set(HAVE_LinkErrorReporting 0)
set(HAVE_RandomizedBaseAddress 0)
set(HAVE_SubSystem 0)
set(HAVE_SubSystem_Empty 0)
set(HAVE_SubSystem_Console 0)
file(STRINGS "${vcProjectFile}" lines)
@ -133,7 +133,7 @@ macro(VsDefaultLinkerFlags_check tgt needs_subsystem_console)
set(HAVE_RandomizedBaseAddress 1)
endif()
if(line MATCHES "^ *<SubSystem></SubSystem>")
set(HAVE_SubSystem 1)
set(HAVE_SubSystem_Empty 1)
endif()
if(line MATCHES "^ *<SubSystem>Console</SubSystem>")
set(HAVE_SubSystem_Console 1)
@ -160,33 +160,21 @@ macro(VsDefaultLinkerFlags_check tgt needs_subsystem_console)
return()
endif()
if(${needs_subsystem_console})
if(HAVE_SubSystem)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has a <SubSystem> property.")
return()
endif()
if(HAVE_SubSystem_Empty)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has a <SubSystem> property.")
return()
endif()
if(NOT HAVE_SubSystem_Console)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <SubSystem> property with 'Console' value.")
return()
endif()
else()
if(NOT HAVE_SubSystem)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <SubSystem> property.")
return()
endif()
if(HAVE_SubSystem_Console)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has a <SubSystem> property with 'Console' value.")
return()
endif()
if(NOT HAVE_SubSystem_Console)
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <SubSystem> property with 'Console' value.")
return()
endif()
endmacro()
VsDefaultCompilerFlags_check(emptyStatic)
VsDefaultCompilerFlags_check(emptyShared)
VsDefaultLinkerFlags_check(emptyShared OFF)
VsDefaultLinkerFlags_check(emptyShared)
VsDefaultCompilerFlags_check(main)
VsDefaultLinkerFlags_check(main ON)
VsDefaultLinkerFlags_check(main)