Skip to content

Commit e263d52

Browse files
committed
feat: Add Link-Time Optimization (LTO) type detection to makefiles
1 parent 4fb8f1c commit e263d52

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

examples/ImGui/makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ endif
102102

103103
LDFLAGS ?= -L./lib/
104104

105+
# ─── Link-Time Optimization (LTO) Type Detection ───────────────────────────────
106+
107+
# Automatically select LTO type based on compiler
108+
ifeq ($(CXX),clang++)
109+
LTO_FLAG := -flto=thin # Clang: thin LTO is more compatible and faster
110+
else ifeq ($(CXX),clang)
111+
LTO_FLAG := -flto=thin
112+
else ifneq ($(findstring clang,$(CXX)),)
113+
LTO_FLAG := -flto=thin # Any clang-like compiler
114+
else
115+
LTO_FLAG := -flto=auto # GCC: use auto LTO for better optimization
116+
endif
117+
105118
# ─── Optimization Flags ───────────────────────────────────────────────────────
106119

107120
ifeq ($(BUILD_TYPE),release)
@@ -110,8 +123,10 @@ ifeq ($(BUILD_TYPE),release)
110123
OPTFLAGS += -march=$(ARCH)
111124
endif
112125
ifeq ($(USE_LTO),true)
113-
OPTFLAGS += -flto=auto
114-
LDFLAGS += -flto=auto
126+
ifneq ($(LTO_FLAG),)
127+
OPTFLAGS += $(LTO_FLAG)
128+
LDFLAGS += $(LTO_FLAG)
129+
endif
115130
endif
116131
else ifeq ($(BUILD_TYPE),debug)
117132
OPTFLAGS := $(OPT_DEBUG) -ggdb3 -DDEBUG -D_GLIBCXX_DEBUG

templates/advanced/makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ endif
102102

103103
LDFLAGS ?= -L./lib/
104104

105+
# ─── Link-Time Optimization (LTO) Type Detection ───────────────────────────────
106+
107+
# Automatically select LTO type based on compiler
108+
ifeq ($(CXX),clang++)
109+
LTO_FLAG := -flto=thin # Clang: thin LTO is more compatible and faster
110+
else ifeq ($(CXX),clang)
111+
LTO_FLAG := -flto=thin
112+
else ifneq ($(findstring clang,$(CXX)),)
113+
LTO_FLAG := -flto=thin # Any clang-like compiler
114+
else
115+
LTO_FLAG := -flto=auto # GCC: use auto LTO for better optimization
116+
endif
117+
105118
# ─── Optimization Flags ───────────────────────────────────────────────────────
106119

107120
ifeq ($(BUILD_TYPE),release)
@@ -110,8 +123,10 @@ ifeq ($(BUILD_TYPE),release)
110123
OPTFLAGS += -march=$(ARCH)
111124
endif
112125
ifeq ($(USE_LTO),true)
113-
OPTFLAGS += -flto=auto
114-
LDFLAGS += -flto=auto
126+
ifneq ($(LTO_FLAG),)
127+
OPTFLAGS += $(LTO_FLAG)
128+
LDFLAGS += $(LTO_FLAG)
129+
endif
115130
endif
116131
else ifeq ($(BUILD_TYPE),debug)
117132
OPTFLAGS := $(OPT_DEBUG) -ggdb3 -DDEBUG -D_GLIBCXX_DEBUG

0 commit comments

Comments
 (0)