IPO support for MSVC
Hi, I am trying to enable IPO aka LTO using "Visual Studio 15 2017" generator.
This is my CMakeLists.txt file:
cmake_minimum_required (VERSION 3.9)
project(cmake-ipo LANGUAGES CXX)
add_executable(cmake-ipo cmake-ipo.cpp)
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_target_properties(cmake-ipo PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(WARNING "${output}")
endif()
I am expecting CMake to use:
- Whole Program Optimization (/GL) for compiling
- Link Time Code Generation (/LTCG) for linking
Unfortunately I am getting an error "CMake doesn't support IPO for current generator".
I've debugged the issue and this message is coming from CheckIPOSupported.cmake.
if(CMAKE_GENERATOR MATCHES "^Visual Studio ")
_ipo_not_supported("CMake doesn't support IPO for current generator")
return()
endif()
At the same time in Windows-MSVC.cmake there is code handling IPO for MSVC compiler.
if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "/GL")
set(CMAKE_${lang}_LINK_OPTIONS_IPO "/INCREMENTAL:NO" "/LTCG")
string(REPLACE "<LINK_FLAGS> " "/LTCG <LINK_FLAGS> "
CMAKE_${lang}_CREATE_STATIC_LIBRARY_IPO "${CMAKE_${lang}_CREATE_STATIC_LIBRARY}")
elseif(...
I'm not sure about state of IPO support for MSVC, but to me it looks incomplete.
Is is possible to fix it or at least mention in the documentation of
CheckIPOSupported
that MSVC is not supported?