morinim / vita

Vita - Genetic Programming Framework
Mozilla Public License 2.0
35 stars 6 forks source link

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

Open morinim opened 6 years ago

morinim commented 6 years ago

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 commented 3 years ago

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...