Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Allow enabling LTO for Qt frontend and libcelestia.so #1955

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
-DENABLE_QT6=ON `
-DENABLE_FFMPEG=ON `
-DENABLE_MINIAUDIO=ON `
-DENABLE_LTO=ON `
-DUSE_ICU=ON `
-DUSE_WIN_ICU=OFF

Expand Down
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -408,6 +409,22 @@ else()
endif()
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")
else()
message(WARNING "LTO is not supported")
set(ENABLE_LTO OFF)
endif()
endif()
endif()

# Turning all debug on dramatically decreases performance
if(OCTREE_DEBUG)
add_definitions(-DOCTREE_DEBUG)
Expand Down
6 changes: 5 additions & 1 deletion src/celestia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/celestia/qt/qtsolarsystembrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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);
}


Expand Down
4 changes: 4 additions & 0 deletions src/celestia/qt5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions src/celestia/qt6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down