File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -97,20 +97,21 @@ endif()
9797# Note we don't enable LTO on RelWithDebInfo, as it breaks debugging symbols
9898# on at least AppleClang, making stepping through source code impossible.
9999
100+ # LTO is applied globally because it is a whole-program optimization.
101+ # Every translation unit must be compiled with LTO flags for the linker
102+ # to perform cross-module optimization effectively.
100103if (CMAKE_BUILD_TYPE STREQUAL "Release" )
101104 if (SOURCEMETA_COMPILER_GCC AND NOT BUILD_SHARED_LIBS )
102105 message (STATUS "Enabling Fat LTO" )
103- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -ffat-lto-objects" )
104- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto" )
105- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto" )
106+ add_compile_options (-flto -ffat-lto-objects )
107+ add_link_options (-flto )
106108 endif ()
107109
108110 # TODO: Make this work on Linux on LLVM
109111 if (SOURCEMETA_COMPILER_LLVM AND NOT BUILD_SHARED_LIBS AND APPLE )
110112 message (STATUS "Enabling Fat LTO" )
111- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=full" )
112- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=full" )
113- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto=full" )
113+ add_compile_options (-flto=full )
114+ add_link_options (-flto=full )
114115 endif ()
115116endif ()
116117
You can’t perform that action at this time.
0 commit comments