Skip to content

Commit

Permalink
CMake: Re-enable LTO for Release builds with CMake >= 3.9
Browse files Browse the repository at this point in the history
If you're using an earlier version, I suggest you upgrade, CMake 3.9 was
released in 2017....
  • Loading branch information
stenzek committed Sep 25, 2020
1 parent e7cfc69 commit fa46ba1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,19 @@ if(MSVC)

# Enable LTO/LTCG on Release builds.
if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
if (${CMAKE_VERSION} VERSION_LESS "3.9.0")
message(WARNING "CMake version is less than 3.9.0, we can't enable LTCG/IPO. This will make the build slightly slower, consider updating your CMake version.")
else()
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_IS_SUPPORTED)
if(IPO_IS_SUPPORTED)
message(STATUS "Enabling LTCG/IPO.")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(WARNING "LTCG/IPO is not supported, this will make the build slightly slower.")
endif()
endif()
endif()
endif()

Expand Down

0 comments on commit fa46ba1

Please sign in to comment.