Ninja on Windows swallows link.exe warnings in try_compile
Here's a minimal example:
cmake_minimum_required(VERSION 3.20)
project(repro)
set(script "${CMAKE_CURRENT_SOURCE_DIR}/repro.ldscript")
file(WRITE "${script}" "{ global: *; };")
include(CheckLinkerFlag)
check_linker_flag(CXX "LINKER:--version-script=${script}" LINKER_HAS_FLAG_VERSION_SCRIPT)
On Windows with Ninja, the check succeeds incorrectly:
D:\repro>cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B windows
-- The C compiler identification is MSVC 19.28.29913.0
-- The CXX compiler identification is MSVC 19.28.29913.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test LINKER_HAS_FLAG_VERSION_SCRIPT
-- Performing Test LINKER_HAS_FLAG_VERSION_SCRIPT - Success
-- Configuring done
-- Generating done
-- Build files have been written to: D:/repro/windows
On Linux, the check passes correctly:
alex@Alex-Desktop:/mnt/d/repro$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B linux
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test LINKER_HAS_FLAG_VERSION_SCRIPT
-- Performing Test LINKER_HAS_FLAG_VERSION_SCRIPT - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/d/repro/linux
While on Windows with the Visual Studio generator, the check fails correctly:
D:\repro>cmake -S . -B windows-vs
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.28.29913.0
-- The CXX compiler identification is MSVC 19.28.29913.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test LINKER_HAS_FLAG_VERSION_SCRIPT
-- Performing Test LINKER_HAS_FLAG_VERSION_SCRIPT - Failed
-- Configuring done
-- Generating done
-- Build files have been written to: D:/repro/windows-vs