From 3ce5f4ca52fb1dccc377edfae99f3553839adc64 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Fri, 27 Oct 2023 17:33:25 +0300 Subject: [PATCH 1/4] [cmake] Enable LTO for release builds --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2113b1a5bc..a2280c62af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.9) option(LEGACY_OPENGL_LIBS "Use legacy OpenGL libraries instead of glvnd library (Default: off)" OFF) @@ -406,6 +406,16 @@ else() ) endif() endif() + if("${build_type_lc}" STREQUAL "release") + include(CheckIPOSupported) + check_ipo_supported(RESULT lto_supported) + if(lto_supported) + message(STATUS "LTO is supported") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) + else() + message(STATUS "LTO is not supported") + endif() + endif() endif() # Turning all debug on dramatically decreases performance From ccf6ef84f3b94c24f9442d49c4ea1c4bc571a4dd Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Fri, 27 Oct 2023 22:08:36 +0300 Subject: [PATCH 2/4] [ci] use ninja with windows as VS generator doesn't support LTO --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 608a313d70..159556f8cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,7 @@ jobs: } cmake -B '${{github.workspace}}/build' ` + -G Ninja ` -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" ` -DVCPKG_TARGET_TRIPLET=${{matrix.platform}}-windows ` -DCMAKE_GENERATOR_PLATFORM="$GeneratorPlatform" ` From d25b087d5c5095e5d26532431600360a54094e2b Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Sun, 5 Nov 2023 23:28:54 +0200 Subject: [PATCH 3/4] wip --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 17 ++++++++++++----- src/celestia/CMakeLists.txt | 6 +++++- src/celestia/qt5/CMakeLists.txt | 4 ++++ src/celestia/qt6/CMakeLists.txt | 4 ++++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 159556f8cd..697e2f7783 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,7 +74,6 @@ jobs: } cmake -B '${{github.workspace}}/build' ` - -G Ninja ` -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" ` -DVCPKG_TARGET_TRIPLET=${{matrix.platform}}-windows ` -DCMAKE_GENERATOR_PLATFORM="$GeneratorPlatform" ` @@ -86,6 +85,7 @@ jobs: -DENABLE_QT6=ON ` -DENABLE_FFMPEG=ON ` -DENABLE_MINIAUDIO=ON ` + -DENABLE_LTO=ON ` -DUSE_ICU=ON ` -DUSE_WIN_ICU=OFF diff --git a/CMakeLists.txt b/CMakeLists.txt index a2280c62af..89f74f1d1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,9 +58,10 @@ option(ENABLE_WIN "Build Windows native frontend? (Default: on)" ON) option(ENABLE_FFMPEG "Support video capture using FFMPEG (Default: off)" OFF) option(ENABLE_MINIAUDIO "Support audio playback using miniaudio (Default: off)" OFF) option(ENABLE_TOOLS "Build different tools? (Default: off)" OFF) -option(FAST_MATH "Build with unsafe fast-math compiller option (Default: off)" OFF) +option(ENABLE_FAST_MATH "Build with unsafe fast-math compiller option (Default: off)" OFF) option(ENABLE_TESTS "Enable unit tests? (Default: off)" OFF) option(ENABLE_GLES "Build for OpenGL ES 2.0 instead of OpenGL 2.1 (Default: off)" OFF) +option(ENABLE_LTO "Enable link time optimizations (Default: off)" OFF) option(USE_GTKGLEXT "Use libgtkglext1 for GTK2 frontend (Default: on)" ON) option(USE_GTK3 "Use Gtk3 in GTK2 frontend (Default: off)" OFF) option(USE_WAYLAND "Use Wayland in Qt frontend (Default: off)" OFF) @@ -172,7 +173,7 @@ if(USE_WEFFCPP AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() endif() -EnableFastMath(${FAST_MATH}) +EnableFastMath(${ENABLE_FAST_MATH}) # # NLS (Gettext) support @@ -406,14 +407,20 @@ else() ) endif() endif() - if("${build_type_lc}" STREQUAL "release") +endif() + +if(ENABLE_LTO) + if(WIN32) + message(WARNING "LTO is not supported yet when building for Windows") + set(ENABLE_LTO OFF) + else() include(CheckIPOSupported) check_ipo_supported(RESULT lto_supported) if(lto_supported) message(STATUS "LTO is supported") - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) else() - message(STATUS "LTO is not supported") + message(WARNING "LTO is not supported") + set(ENABLE_LTO OFF) endif() endif() endif() diff --git a/src/celestia/CMakeLists.txt b/src/celestia/CMakeLists.txt index bbdf6ab196..8c4fab74dd 100644 --- a/src/celestia/CMakeLists.txt +++ b/src/celestia/CMakeLists.txt @@ -101,10 +101,14 @@ if(ENABLE_FFMPEG) target_link_libraries(celestia ${FFMPEG_LIBRARIES}) endif() -if (HAVE_MESHOPTIMIZER) +if(HAVE_MESHOPTIMIZER) target_link_libraries(celestia meshoptimizer::meshoptimizer) endif() +if(ENABLE_LTO) + set_target_properties(celestia PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) +endif() + if(WIN32) install( TARGETS celestia diff --git a/src/celestia/qt5/CMakeLists.txt b/src/celestia/qt5/CMakeLists.txt index 4c2822322f..dbbea1abf9 100644 --- a/src/celestia/qt5/CMakeLists.txt +++ b/src/celestia/qt5/CMakeLists.txt @@ -46,6 +46,10 @@ if(APPLE) set_property(TARGET celestia-qt5 APPEND_STRING PROPERTY LINK_FLAGS " -framework CoreServices") endif() +if(ENABLE_LTO) + set_target_properties(celestia-qt5 PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) +endif() + install( TARGETS celestia-qt5 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/src/celestia/qt6/CMakeLists.txt b/src/celestia/qt6/CMakeLists.txt index e9cc942ae0..8c89897479 100644 --- a/src/celestia/qt6/CMakeLists.txt +++ b/src/celestia/qt6/CMakeLists.txt @@ -45,6 +45,10 @@ install( COMPONENT qt6gui ) +if(ENABLE_LTO) + set_target_properties(celestia-qt6 PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) +endif() + if(WIN32) qt6_generate_deploy_app_script(TARGET celestia-qt6 OUTPUT_SCRIPT deploy-celestia-qt6 From 5a055048abb96068a2a2253dace1b9c3c0f6939c Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Sun, 5 Nov 2023 23:54:38 +0200 Subject: [PATCH 4/4] Fix warning from linker and remove unneded variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In member function ‘addTreeItemChildrenFiltered’, inlined from ‘createTreeItem’ at src/celestia/qt/qtsolarsystembrowser.cpp:280:36: src/celestia/qt/qtsolarsystembrowser.cpp:349:51: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=] 349 | item->children = new TreeItem*[item->nChildren]; --- src/celestia/qt/qtsolarsystembrowser.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/celestia/qt/qtsolarsystembrowser.cpp b/src/celestia/qt/qtsolarsystembrowser.cpp index 14336220b4..803de9737a 100644 --- a/src/celestia/qt/qtsolarsystembrowser.cpp +++ b/src/celestia/qt/qtsolarsystembrowser.cpp @@ -342,18 +342,15 @@ SolarSystemBrowser::SolarSystemTreeModel::addTreeItemChildrenFiltered(TreeItem* } // Calculate the total number of children - if ((item->nChildren = bodies.size()) == 0) + // WARN: max(size_t) > max(int) so in theory it's possible to have a negative value + if ((item->nChildren = static_cast(bodies.size())) <= 0) return; - int childIndex = 0; item->children = new TreeItem*[item->nChildren]; // Add the direct children for (int i = 0; i < (int) bodies.size(); i++) - { - item->children[childIndex] = createTreeItem(bodies[i], item, childIndex); - childIndex++; - } + item->children[i] = createTreeItem(bodies[i], item, i); }