From 65d9509c38604152cf162637956022ecdc741bd6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 9 Jul 2023 20:34:49 +0200 Subject: [PATCH] build: Add checked option to enable LTO --- .github/workflows/build.yml | 6 +++--- CMakeLists.txt | 1 + cmake/build_helpers.cmake | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04fb53fae..4c80dafa3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -291,7 +291,7 @@ jobs: -DIMHEX_COMMIT_HASH_SHORT="${{env.COMMIT_SHA_SHORT}}" \ -DIMHEX_COMMIT_HASH_LONG="${{env.COMMIT_SHA_LONG}}" \ -DIMHEX_COMMIT_BRANCH="${{env.COMMIT_BRANCH}}" \ - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ + -DIMHEX_ENABLE_LTO=ON \ .. make -j 4 install DESTDIR=DebDir @@ -364,7 +364,7 @@ jobs: -DIMHEX_COMMIT_HASH_SHORT="${GITHUB_SHA::7}" \ -DIMHEX_COMMIT_HASH_LONG="${GITHUB_SHA}" \ -DIMHEX_COMMIT_BRANCH="${GITHUB_REF##*/}" \ - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ + -DIMHEX_ENABLE_LTO=ON \ -DIMHEX_PLUGINS_IN_SHARE=ON \ -DIMHEX_USE_BUNDLED_CA=ON \ .. @@ -447,7 +447,7 @@ jobs: -DIMHEX_COMMIT_HASH_SHORT="${GITHUB_SHA::7}" \ -DIMHEX_COMMIT_HASH_LONG="${GITHUB_SHA}" \ -DIMHEX_COMMIT_BRANCH="${GITHUB_REF##*/}" \ - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ + -DIMHEX_ENABLE_LTO=ON \ .. make -j 4 install DESTDIR=installDir diff --git a/CMakeLists.txt b/CMakeLists.txt index ddf992380..e3908783f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ option(IMHEX_PATTERNS_PULL_MASTER "Download latest files from master branch of t option(IMHEX_IGNORE_BAD_COMPILER "Allow compiling with an unsupported compiler" OFF) option(IMHEX_USE_GTK_FILE_PICKER "Use GTK file picker instead of xdg-desktop-portals" OFF) option(IMHEX_DISABLE_STACKTRACE "Disables support for printing stack traces" OFF) +option(IMHEX_ENABLE_LTO "Enables Link Time Optimizations if possible" OFF) # Basic compiler and cmake configurations set(CMAKE_CXX_STANDARD 23) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index f896bac09..ea806a837 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -284,6 +284,17 @@ function(JOIN OUTPUT GLUE) endfunction() macro(configureCMake) + # Enable LTO if desired and supported + if (IMHEX_ENABLE_LTO) + include(CheckIPOSupported) + + check_ipo_supported(RESULT result) + if (result) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + else () + message(WARNING "LTO is not supported!") + endif () + endif () endmacro() function(message ${ARGN})