check_ipo_supported command fails with MSVC
Steps to reproduce the issue
- Install Visual Studio Community 2019 16.2.1 with "Desktop development with C++" workload
- Open "x64 Native Tools Command Prompt for VS 2019"
- Run cmake
Here is the CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(test CXX)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT output)
message("${output}")
Here is the output:
D:\Documents\test\build>cmake --version
cmake version 3.14.19060802-MSVC_2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
D:\Documents\test\build>cmake ..
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The CXX compiler identification is MSVC 19.22.27905.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.22.27905/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.22.27905/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Change Dir: D:/Documents/test/build/CMakeFiles/_CMakeLTOTest-CXX/bin
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe ALL_BUILD.vcxproj /p:Configuration=Debug /p:Platform=Win32 /p:VisualStudioVersion=16.0 /v:m
.NET Framework 向け Microsoft (R) Build Engine バージョン 16.2.37902+b5aaefc9f
Copyright (C) Microsoft Corporation.All rights reserved.
Checking Build System
CMake does not need to re-run because D:/Documents/test/build/CMakeFiles/_CMakeLTOTest-CXX/bin/CMakeFiles/generate.stamp is up-to-date.
Building Custom Rule D:/Documents/test/build/CMakeFiles/_CMakeLTOTest-CXX/src/CMakeLists.txt
CMake does not need to re-run because D:/Documents/test/build/CMakeFiles/_CMakeLTOTest-CXX/bin/CMakeFiles/generate.stamp is up-to-date.
Microsoft (R) C/C++ Optimizing Compiler Version 19.22.27905 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
cl /c /ZI /JMC /W3 /WX- /diagnostics:column /Od /Ob0 /Oy- /GL /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"foo.dir\Debug\\" /Fd"foo.dir\Debug\foo.pdb" /Gd /TP /analyze- /errorReport:queue "D:\Documents\test\build\CMakeFiles\_CMakeLTOTest-CXX\src\foo.cpp"
cl : Command line error D8016 : '/ZI' and '/GL' command-line options are incompatible
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(429,5): error MSB6006: "CL.exe" はコード 2 を伴って終了しました。 [D:\Documents\test\build\CMakeFiles\_CMakeLTOTest-CXX\bin\foo.vcxproj]
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Documents/test/build
foo.cpp is built with "/ZI" option (which is part of CMAKE_CXX_FLAGS_DEBUG), but it shouldn't.