Skip to content

Commit 31a5f32

Browse files
committed
Enabled LTO for Release only. Disabled LTO for RelWithDebInfo and Debug build types
Signed-off-by: Jaehyun Kim <[email protected]>
1 parent cf965b7 commit 31a5f32

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

CMakeLists.txt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
6452
set(OPENROAD_HOME ${PROJECT_SOURCE_DIR})
6553
set(OPENROAD_SHARE ${CMAKE_INSTALL_PREFIX}/share/openroad)
6654

@@ -114,6 +102,27 @@ message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
114102
message(STATUS "C++ Standard Required: ${CMAKE_CXX_STANDARD_REQUIRED}")
115103
message(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
118127
configure_file(
119128
${OPENROAD_HOME}/include/ord/Version.hh.cmake

0 commit comments

Comments
 (0)