Skip to content

Commit 6a1e3c3

Browse files
committed
cmake: Fix LTO problem with clang 21.
Ask cmake to enable link-time optimization instead of manually adding arguments to the compilation flags. This solves link time failures when using clang 21.
1 parent 2f066e0 commit 6a1e3c3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cmake/SetCompilerOptions.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
130130

131131
endif()
132132

133-
if(ENABLE_LTO AND NOT CMAKE_CROSSCOMPILING)
134-
list(APPEND CFLAGS -flto=auto)
135-
list(APPEND CXXFLAGS -flto=auto)
136-
list(APPEND LFLAGS -flto=auto)
133+
#
134+
# Check for Interprocedural Optimization, aka Link Time Optimization.
135+
#
136+
include(CheckIPOSupported)
137+
check_ipo_supported(RESULT has_ipo)
138+
if(ENABLE_LTO AND has_ipo AND NOT CMAKE_CROSSCOMPILING)
139+
message(STATUS "Enabling link-time optimization.")
140+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
137141
endif()
138142

139143
#

0 commit comments

Comments
 (0)