VS: Don't set LinkToolExe for targets that don't drive linking

A pure ASM_NASM target has no linker of its own, so emitting
CMAKE_LINKER as <LinkToolExe> broke the build (TRK0005) when it was
not found.  Let MSBuild link via the toolset, as MSVC C/CXX targets
already do.

Fixes: #27458
This commit is contained in:
Daksh Mamodiya
2026-09-02 19:20:35 +05:30
parent 3773fb5a46
commit 5f3d66a024
5 changed files with 30 additions and 0 deletions
+6
View File
@@ -4094,6 +4094,12 @@ std::string cmGeneratorTarget::GetLinkerTool(std::string const& lang,
"CMAKE_", lang, this->IsDeviceLink() ? "_DEVICE_" : "_", "LINK_MODE");
auto mode = this->Makefile->GetDefinition(linkMode);
if (!mode || mode != "LINKER"_s) {
// On the Visual Studio generators the project links via the platform
// toolset, so languages without a LINKER-mode toolchain (e.g. ASM_NASM)
// must not force a linker; defer to the toolset's default.
if (this->GetGlobalGenerator()->IsVisualStudio()) {
return std::string{};
}
return this->Makefile->GetDefinition("CMAKE_LINKER");
}
@@ -18,6 +18,7 @@ run_cmake(VsCSharpCompilerOpts)
run_cmake(ExplicitCMakeLists)
run_cmake(InterfaceLibSources)
run_cmake(NoImpLib)
run_cmake(VsNASMLinkTool)
run_cmake(RuntimeLibrary)
run_cmake(SourceGroupCMakeLists)
run_cmake(SourceGroupTreeCMakeLists)
@@ -0,0 +1,13 @@
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/nasmexe.vcxproj")
if(NOT EXISTS "${vcProjectFile}")
# No ASM_NASM compiler was available, so there is nothing to verify.
return()
endif()
file(STRINGS "${vcProjectFile}" linkToolExeLines REGEX "<LinkToolExe>")
if(linkToolExeLines)
string(REPLACE ";" "\n " linkToolExeLines "${linkToolExeLines}")
set(RunCMake_TEST_FAILED
"nasmexe.vcxproj should not set <LinkToolExe> for an ASM_NASM target; "
"MSBuild should link via the toolset. Found:\n ${linkToolExeLines}")
endif()
@@ -0,0 +1,9 @@
enable_language(C)
include(CheckLanguage)
check_language(ASM_NASM)
if(CMAKE_ASM_NASM_COMPILER)
enable_language(ASM_NASM)
# A target whose link language is ASM_NASM must not force CMAKE_LINKER into
# <LinkToolExe>; the Visual Studio toolset performs the link.
add_executable(nasmexe nasm_main.asm)
endif()
+1
View File
@@ -0,0 +1 @@
section .text