From 6b0ea3f33e0140129ef707a0bd24f0df4d138eaa Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Mon, 27 May 2024 19:03:50 +0200 Subject: [PATCH] meta: enable LTO Also set -Wa,--dsp also on C files because the fxSDK sets it globally and LTO complains if -Wa/-Xassembler options are not uniform across all compilation units. --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06c9b7b..e13ebf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ endif() if(FXLIBC_TARGET STREQUAL gint) list(APPEND TARGET_FOLDERS sh-generic) set(FXLIBC_ARCH sh) + set(FXLIBC_LTO 1) add_definitions(-D__SUPPORT_GINT) # Default to fxSDK install path @@ -58,11 +59,19 @@ add_compile_options(-Wall -Wextra -std=c11 -ffreestanding -Os) if(FXLIBC_PIC) add_compile_options(-fpic) endif() +if(FXLIBC_LTO) + add_compile_options(-flto) + # Generate the archive with gcc-ar instead of ar as it will load the LTO + # plugin which is required to generate a usable archive. + set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_C_COMPILER_AR} qcs ") + # Also the ranlib rule (useless because ar is passed the s flag anyway) + set(CMAKE_C_ARCHIVE_FINISH "${CMAKE_C_COMPILER_RANLIB} ") +endif() if(FXLIBC_ARCH STREQUAL sh) add_compile_options( "$<$:-m3;-mb>" - "$<$:-m4-nofpu;-mb;-Wa,--dsp>") + "$<$:-m4-nofpu;-mb>" -Wa,--dsp) endif() # Building