Regression: 3.27 ignores toolchain CMAKE_RC_COMPILER in link.exe command Ninja build
To reproduce you need a Windows PC with Visual Studio. Open a PowerShell in a directory of your choice and type:
Invoke-WebRequest "https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-windows-x86_64.zip" -OutFile "cmake-3.26.zip"
Invoke-WebRequest "https://github.com/Kitware/CMake/releases/download/v3.27.0-rc3/cmake-3.27.0-rc3-windows-x86_64.zip" -OutFile "cmake-3.27.zip"
Invoke-WebRequest "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip" -OutFile "ninja.zip"
Invoke-WebRequest "https://github.com/fmtlib/fmt/archive/refs/tags/10.0.0.zip" -OutFile "fmt.zip"
Invoke-WebRequest "https://gitlab.kitware.com/cmake/cmake/uploads/b9a6cc2cb554316762202262414a8c88/msvc_toolchain.zip" -OutFile msvc_toolchain.zip
Expand-Archive cmake-3.26.zip -DestinationPath .
Expand-Archive cmake-3.27.zip -DestinationPath .
Expand-Archive ninja.zip -DestinationPath .\cmake-3.26.4-windows-x86_64\bin
Expand-Archive ninja.zip -DestinationPath .\cmake-3.27.0-rc3-windows-x86_64\bin
Expand-Archive fmt.zip -DestinationPath .
Expand-Archive msvc_toolchain.zip -DestinationPath .
mkdir build
cd build
# Success
$env:Path = "$pwd\..\cmake-3.26.4-windows-x86_64\bin"
Remove-Item * -Recurse -Force
cmake -GNinja '-DCMAKE_TOOLCHAIN_FILE=../windows_msvc.cmake' '-DFMT_DOC=OFF' '-DFMT_TEST=OFF' '-DBUILD_SHARED_LIBS=ON' '..\fmt-10.0.0'
cmake --build .
# Error
$env:Path = "$pwd\..\cmake-3.27.0-rc3-windows-x86_64\bin"
Remove-Item * -Recurse -Force
cmake -GNinja '-DCMAKE_TOOLCHAIN_FILE=../windows_msvc.cmake' '-DFMT_DOC=OFF' '-DFMT_TEST=OFF' '-DBUILD_SHARED_LIBS=ON' '..\fmt-10.0.0'
cmake --build .
The 3.26.4 build succeeds.
The 3.27.0-rc3 build fails with
[3/3] Linking CXX shared library bin\fmt.dll
FAILED: bin/fmt.dll fmt.lib
cmd.exe /C "cd . && C:\Temp\fmt_build\cmake-3.27.0-rc3-windows-x86_64\bin\cmake.exe -E vs_link_dll --intdir=CMakeFiles\fmt.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\fmt.dir\src\format.cc.obj CMakeFiles\fmt.dir\src\os.cc.obj /out:bin\fmt.dll /implib:fmt.lib /pdb:bin\fmt.pdb /dll /version:10.0 /machine:x64 /INCREMENTAL:NO -LIBPATH:C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\ATLMFC\lib\x64 -LIBPATH:C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\lib\x64 -LIBPATH:C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\lib\x86\store\REFERE~1 -LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100190~1.0\ucrt\x64 -LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100190~1.0\um\x64 -LIBPATH:"C:\Program Files (x86)\Windows Kits\10\References\x64" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\fmt.dir\src\format.cc.obj CMakeFiles\fmt.dir\src\os.cc.obj /out:bin\fmt.dll /implib:fmt.lib /pdb:bin\fmt.pdb /dll /version:10.0 /machine:x64 /INCREMENTAL:NO -LIBPATH:C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\ATLMFC\lib\x64 -LIBPATH:C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\lib\x64 -LIBPATH:C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\lib\x86\store\REFERE~1 -LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100190~1.0\ucrt\x64 -LIBPATH:C:\PROGRA~2\WI3CF2~1\10\lib\100190~1.0\um\x64 -LIBPATH:C:\Program Files (x86)\Windows Kits\10\References\x64 kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=2" failed (exit code 1158) with the following output:
Creating library fmt.lib and object fmt.exp
LINK : fatal error LNK1158: cannot run 'rc.exe'
ninja: build stopped: subcommand failed.
As you can see, my toolchain files set rc.exe
with full path via CMAKE_RC_COMPILER
. That works with 3.26, but not with 3.27. (Tested with rc1 and rc3).
Note that I remove anything from PATH environement variable except the cmake bin.
Edited by Benjamin Buch