@@ -49,18 +49,6 @@ project(OpenROAD VERSION 1
4949 LANGUAGES CXX
5050)
5151
52- # LTO setting must come after project() for proper compiler detection
53- option (LINK_TIME_OPTIMIZATION "Flag to control link time optimization: on by default" ON )
54-
55- string (TOUPPER "${CMAKE_BUILD_TYPE} " UPPER_BUILD_TYPE)
56-
57- if (LINK_TIME_OPTIMIZATION AND NOT UPPER_BUILD_TYPE STREQUAL "DEBUG" )
58- set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE )
59- message (STATUS "LTO is enabled" )
60- else ()
61- message (STATUS "LTO is disabled" )
62- endif ()
63-
6452set (OPENROAD_HOME ${PROJECT_SOURCE_DIR} )
6553set (OPENROAD_SHARE ${CMAKE_INSTALL_PREFIX} /share/openroad)
6654
@@ -114,6 +102,27 @@ message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
114102message (STATUS "C++ Standard Required: ${CMAKE_CXX_STANDARD_REQUIRED} " )
115103message (STATUS "C++ Extensions: ${CMAKE_CXX_EXTENSIONS} " )
116104
105+ option (LINK_TIME_OPTIMIZATION "Flag to control link time optimization: on by default" ON )
106+ if (LINK_TIME_OPTIMIZATION)
107+ include (CheckIPOSupported)
108+ # 1. Check if the compiler/linker even supports LTO
109+ check_ipo_supported(RESULT lto_supported OUTPUT lto_error)
110+ if (lto_supported)
111+ # LTO is enabled globally for Release builds
112+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE )
113+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO FALSE )
114+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE )
115+
116+ string (TOUPPER "${CMAKE_BUILD_TYPE} " UPPER_BUILD_TYPE)
117+ if (UPPER_BUILD_TYPE STREQUAL "RELEASE" )
118+ message (STATUS "LTO/IPO is enabled" )
119+ else ()
120+ message (STATUS "LTO/IPO is disabled" )
121+ endif ()
122+ message (STATUS "LTO/IPO is not supported: ${lto_error} " )
123+ endif ()
124+ endif ()
125+
117126# configure a header file to pass some of the CMake settings
118127configure_file (
119128 ${OPENROAD_HOME} /include /ord/Version .hh.cmake
0 commit comments