Skip to content

Commit b94b7bb

Browse files
committed
Allow to build PrusaSlicer with EGL support
A lot of Linux distribution don't build wxWidgets with EGL support yet. This is why by default this option is set to OFF. If a Linux distribution has built wxWidgets and GLEW with EGL support, you should turn that on!
1 parent 55139f4 commit b94b7bb

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ endif()
3535

3636
option(SLIC3R_STATIC "Compile PrusaSlicer with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL})
3737
option(SLIC3R_GUI "Compile PrusaSlicer with GUI components (OpenGL, wxWidgets)" 1)
38+
# A lot of Linux distribution don't build wxWidgets with EGL support yet. This
39+
# is why by default this option is set to OFF. If a Linux distribution has
40+
# built wxWidgets and GLEW with EGL support, you should turn that on!
41+
option(SLIC3R_EGL "Compile PrusaSlicer with Wayland (EGL) support" OFF)
3842
option(SLIC3R_FHS "Assume PrusaSlicer is to be installed in a FHS directory structure" 0)
3943
option(SLIC3R_PCH "Use precompiled headers" 1)
4044
option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)

deps/+GLEW/GLEW.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ add_cmake_project(
55
SOURCE_SUBDIR build/cmake
66
CMAKE_ARGS
77
-DBUILD_UTILS=OFF
8-
)
8+
-DGLEW_EGL=${SLIC3R_EGL}
9+
)

deps/+wxWidgets/wxWidgets.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ add_cmake_project(wxWidgets
5151
-DwxUSE_EXPAT=sys
5252
-DwxUSE_LIBSDL=OFF
5353
-DwxUSE_XTEST=OFF
54-
-DwxUSE_GLCANVAS_EGL=OFF
54+
-DwxUSE_GLCANVAS_EGL=${SLIC3R_EGL}
5555
-DwxUSE_WEBREQUEST=OFF
5656
${_wx_webview}
5757
${_wx_secretstore}

src/CLI/GuiParams.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ int start_gui_with_params(GUI::GUI_InitParams& params)
107107
#if !defined(_WIN32) && !defined(__APPLE__)
108108
// likely some linux / unix system
109109
const char* display = boost::nowide::getenv("DISPLAY");
110-
// const char *wayland_display = boost::nowide::getenv("WAYLAND_DISPLAY");
111-
//if (! ((display && *display) || (wayland_display && *wayland_display))) {
110+
#ifdef SLIC3R_EGL
111+
const char *wayland_display = boost::nowide::getenv("WAYLAND_DISPLAY");
112+
if (! ((display && *display) || (wayland_display && *wayland_display))) {
113+
#else // SLIC3R_EGL
112114
if (!(display && *display)) {
115+
#endif // SLIC3R_EGL
113116
// DISPLAY not set.
114117
boost::nowide::cerr << "DISPLAY not set, GUI mode not available." << std::endl << std::endl;
115118
print_help(false);
@@ -141,4 +144,4 @@ int start_as_gcode_viewer(GUI::GUI_InitParams& gui_params)
141144
}
142145
#else // SLIC3R_GUI
143146
// If there is no GUI, we shall ignore the parameters. Remove them from the list.
144-
#endif // SLIC3R_GUI
147+
#endif // SLIC3R_GUI

src/CLI/Setup.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,12 @@ static bool setup_common()
212212
save_main_thread_id();
213213

214214
#ifdef __WXGTK__
215-
// On Linux, wxGTK has no support for Wayland, and the app crashes on
216-
// startup if gtk3 is used. This env var has to be set explicitly to
217-
// instruct the window manager to fall back to X server mode.
215+
#ifndef SLIC3R_EGL
216+
// On a lot of Linux distributions, wxWidgets isn't compiled with EGL
217+
// support. In order to avoid crashes force the X11 backend. If Wayland is
218+
// running this will fallback to XWayland.
218219
::setenv("GDK_BACKEND", "x11", /* replace */ true);
220+
#endif // SLIC3R_EGL
219221

220222
// https://github.com/prusa3d/PrusaSlicer/issues/12969
221223
::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "1", /* replace */ false);
@@ -338,4 +340,4 @@ bool setup(Data& cli, int argc, char** argv)
338340
return true;
339341
}
340342

341-
}
343+
}

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ if (NOT WIN32 AND NOT APPLE)
140140
set_target_properties(PrusaSlicer PROPERTIES OUTPUT_NAME "prusa-slicer")
141141
endif ()
142142

143+
if (SLIC3R_EGL)
144+
target_compile_options(PrusaSlicer PRIVATE -DSLIC3R_EGL=1)
145+
endif()
146+
143147

144148
target_link_libraries(PrusaSlicer PRIVATE libslic3r libcereal slic3r-arrange-wrapper libseqarrange stb_image)
145149

0 commit comments

Comments
 (0)