Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake support for link time optimization (aka IPO) #18

Open
morinim opened this issue Jul 21, 2018 · 1 comment
Open

CMake support for link time optimization (aka IPO) #18

morinim opened this issue Jul 21, 2018 · 1 comment

Comments

@morinim
Copy link
Owner

morinim commented Jul 21, 2018

CMake v3.9 finally supports LTO.

Here's an example code to show how it works:

cmake_minimum_required(VERSION 3.9.4)

include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)

add_executable(example Example.cpp)

if (supported)
  message(STATUS "IPO / LTO enabled")
  set_property(TARGET example PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else ()
  message(STATUS "IPO / LTO not supported: <${error}>")
endif()

See also:

@morinim
Copy link
Owner Author

morinim commented Feb 18, 2021

This code enables LTO (if available):

project(VITA)

include(CheckIPOSupported)
...

if (CMAKE_BUILD_TYPE MATCHES "Release")
check_ipo_supported(RESULT supported_ipo OUTPUT error_ipo)

if (supported_ipo)
  message(STATUS "IPO / LTO supported: <${supported_ipo}>")
  set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else ()
  message(STATUS "IPO / LTO not supported: <${error_ipo}>")
endif()
endif()

Unfortunately preliminary tests show worse performance. Further investigation required...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant