vs_link_exe swallows linker warnings
vs_link_exe
suppresses all output if linking succeeds which includes any warnings emitted by link.exe
.
Small repro:
// CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(app CXX)
add_library(lib STATIC lib.cpp)
set_property(TARGET lib PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
add_executable(app app.cpp)
set_property(TARGET app PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
target_link_libraries(app lib)
// lib.cpp
void f() {}
// app.cpp
void f();
int main() { f(); }
Here we link two objects with conflicting runtimes which should result in a LNK4098
warning.
Running cmake -B build -S . -GNinja && cmake --build build
gives:
-- The CXX compiler identification is MSVC 19.38.33133.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.6s)
-- Generating done (0.0s)
-- Build files have been written to: C:/dev/_repro/CmakeLinkWarnings/build
[4/4] Linking CXX executable app.exe
The warning only surfaces if linking fails with some other error or if the VERBOSE
environment variable is specified.