Enable LTO in release builds

Fixes #693
This commit is contained in:
ISSOtm
2021-01-09 03:57:48 +01:00
parent cab9cb06a3
commit b598911e96
4 changed files with 24 additions and 8 deletions

View File

@@ -12,3 +12,5 @@ case `echo $1 | cut -d '-' -f 1` in
esac esac
bison --version bison --version
make --version
cmake --version

View File

@@ -34,7 +34,7 @@ jobs:
if: matrix.buildsys == 'make' if: matrix.buildsys == 'make'
- name: Build & install using CMake - name: Build & install using CMake
run: | run: |
cmake -S . -B build -DCMAKE_VERBOSE_MAKEFILE=ON ${{ matrix.cmakevars }} cmake -S . -B build -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmakevars }}
cmake --build build cmake --build build
cp build/src/rgb{asm,link,fix,gfx} . cp build/src/rgb{asm,link,fix,gfx} .
sudo cmake --install build sudo cmake --install build

View File

@@ -6,8 +6,8 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
cmake_minimum_required(VERSION 3.0) # 3.9 required for LTO checks
cmake_policy(VERSION 3.0) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(rgbds project(rgbds
LANGUAGES C) LANGUAGES C)
@@ -23,10 +23,8 @@ if(srcdir STREQUAL bindir)
message(FATAL_ERROR "Terminating configuration") message(FATAL_ERROR "Terminating configuration")
endif() endif()
include_directories("${PROJECT_SOURCE_DIR}/include") option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
option(SANITIZERS "Build with sanitizers enabled" OFF)
option(MORE_WARNINGS "Turn on more warnings" OFF)
option(TRACE_PARSER "Trace parser execution" OFF) option(TRACE_PARSER "Trace parser execution" OFF)
option(TRACE_LEXER "Trace lexer execution" OFF) option(TRACE_LEXER "Trace lexer execution" OFF)
@@ -67,6 +65,8 @@ execute_process(COMMAND git describe --tags --dirty --always
ERROR_QUIET) ERROR_QUIET)
string(STRIP "${GIT_REV}" GIT_REV) string(STRIP "${GIT_REV}" GIT_REV)
include_directories("${PROJECT_SOURCE_DIR}/include")
add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}") add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}")
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
@@ -74,6 +74,20 @@ set(CMAKE_C_STANDARD_REQUIRED True)
add_subdirectory(src) add_subdirectory(src)
# By default, build in Release mode; Debug mode must be explicitly requested
# (You may want to augment it with the options above)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(CHECK_START "Checking if LTO is supported")
include(CheckIPOSupported)
check_ipo_supported(RESULT enable_lto)
if(enable_lto)
message(CHECK_PASS "yes")
set_property(TARGET rgbasm rgblink rgbfix rgbgfx PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(CHECK_FAIL "no")
endif()
endif()
if(TRACE_PARSER) if(TRACE_PARSER)
target_compile_definitions(rgbasm PRIVATE -DYYDEBUG) target_compile_definitions(rgbasm PRIVATE -DYYDEBUG)
endif() endif()

View File

@@ -33,7 +33,7 @@ VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
WARNFLAGS := -Wall WARNFLAGS := -Wall
# Overridable CFLAGS # Overridable CFLAGS
CFLAGS ?= -O3 -DNDEBUG CFLAGS ?= -O3 -flto -DNDEBUG
# Non-overridable CFLAGS # Non-overridable CFLAGS
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=gnu11 -D_POSIX_C_SOURCE=200809L \ REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=gnu11 -D_POSIX_C_SOURCE=200809L \
-Iinclude -Iinclude