From 349e30a39c351fdedd4ec8e216442ccf71c906f1 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 12 Apr 2019 12:16:44 +0200 Subject: [PATCH] WIP: Restoring of the command line only builds (no GUI support). --- CMakeLists.txt | 4 ++++ src/slic3r.cpp | 24 ++++++++++++++++-------- src/slic3r_app_msvc.cpp | 27 ++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e6cf45bd..8adea28c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,10 @@ foreach (_cache_var ${_cache_vars}) endif () endforeach() +if (SLIC3R_GUI) + add_definitions(-DSLIC3R_GUI) +endif () + if (MSVC) if (SLIC3R_MSVC_COMPILE_PARALLEL) add_compile_options(/MP) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 780efea7b..f6a2282bb 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -6,10 +6,12 @@ #define NOMINMAX #include #include - // Let the NVIDIA and AMD know we want to use their graphics card - // on a dual graphics card system. - __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; - __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; + #ifdef SLIC3R_GUI + // Let the NVIDIA and AMD know we want to use their graphics card + // on a dual graphics card system. + __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; + __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; + #endif /* SLIC3R_GUI */ #endif /* WIN32 */ #include @@ -448,7 +450,7 @@ int CLI::run(int argc, char **argv) } if (start_gui) { -#if 1 +#ifdef SLIC3R_GUI // #ifdef USE_WX GUI::GUI_App *gui = new GUI::GUI_App(); // gui->autosave = m_config.opt_string("autosave"); @@ -477,12 +479,12 @@ int CLI::run(int argc, char **argv) gui->mainframe->load_config(m_extra_config); }); return wxEntry(argc, argv); -#else +#else /* SLIC3R_GUI */ // No GUI support. Just print out a help. this->print_help(false); // If started without a parameter, consider it to be OK, otherwise report an error code (no action etc). return (argc == 0) ? 0 : 1; -#endif +#endif /* SLIC3R_GUI */ } return 0; @@ -563,7 +565,13 @@ bool CLI::setup(int argc, char **argv) void CLI::print_help(bool include_print_options, PrinterTechnology printer_technology) const { boost::nowide::cout - << "Slic3r Prusa Edition " << SLIC3R_BUILD << std::endl + << "Slic3r Prusa Edition " << SLIC3R_BUILD +#ifdef SLIC3R_GUI + << " (with GUI support)" +#else /* SLIC3R_GUI */ + << " (without GUI support)" +#endif /* SLIC3R_GUI */ + << std::endl << "https://github.com/prusa3d/Slic3r" << std::endl << std::endl << "Usage: slic3r [ ACTIONS ] [ TRANSFORM ] [ OPTIONS ] [ file.stl ... ]" << std::endl << std::endl diff --git a/src/slic3r_app_msvc.cpp b/src/slic3r_app_msvc.cpp index e2c6013a2..bf72ee136 100644 --- a/src/slic3r_app_msvc.cpp +++ b/src/slic3r_app_msvc.cpp @@ -6,14 +6,20 @@ #include #include #include -// Let the NVIDIA and AMD know we want to use their graphics card -// on a dual graphics card system. -__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; -__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; + +#ifdef SLIC3R_GUI + // Let the NVIDIA and AMD know we want to use their graphics card + // on a dual graphics card system. + __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; + __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; +#endif /* SLIC3R_GUI */ #include #include -#include + +#ifdef SLIC3R_GUI + #include +#endif /* SLIC3R_GUI */ #include #include @@ -23,6 +29,7 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; #include +#ifdef SLIC3R_GUI class OpenGLVersionCheck { public: @@ -188,6 +195,7 @@ protected: }; bool OpenGLVersionCheck::message_pump_exit = false; +#endif /* SLIC3R_GUI */ extern "C" { typedef int (__stdcall *Slic3rMainFunc)(int argc, wchar_t **argv); @@ -206,17 +214,23 @@ int wmain(int argc, wchar_t **argv) std::vector argv_extended; argv_extended.emplace_back(argv[0]); + +#ifdef SLIC3R_GUI // Here one may push some additional parameters based on the wrapper type. bool force_mesa = false; +#endif /* SLIC3R_GUI */ for (int i = 1; i < argc; ++ i) { +#ifdef SLIC3R_GUI if (wcscmp(argv[i], L"--sw-renderer") == 0) force_mesa = true; else if (wcscmp(argv[i], L"--no-sw-renderer") == 0) force_mesa = false; +#endif /* SLIC3R_GUI */ argv_extended.emplace_back(argv[i]); } argv_extended.emplace_back(nullptr); +#ifdef SLIC3R_GUI OpenGLVersionCheck opengl_version_check; bool load_mesa = // Forced from the command line. @@ -226,6 +240,7 @@ int wmain(int argc, wchar_t **argv) ::GetSystemMetrics(SM_REMOTESESSION) || // Try to load the default OpenGL driver and test its context version. ! opengl_version_check.load_opengl_dll() || ! opengl_version_check.is_version_greater_or_equal_to(2, 0); +#endif /* SLIC3R_GUI */ wchar_t path_to_exe[MAX_PATH + 1] = { 0 }; ::GetModuleFileNameW(nullptr, path_to_exe, MAX_PATH); @@ -236,6 +251,7 @@ int wmain(int argc, wchar_t **argv) _wsplitpath(path_to_exe, drive, dir, fname, ext); _wmakepath(path_to_exe, drive, dir, nullptr, nullptr); +#ifdef SLIC3R_GUI // https://wiki.qt.io/Cross_compiling_Mesa_for_Windows // http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/ if (load_mesa) { @@ -260,6 +276,7 @@ int wmain(int argc, wchar_t **argv) printf("slic3r.dll was not loaded\n"); return -1; } +#endif /* SLIC3R_GUI */ // resolve function address here slic3r_main = (Slic3rMainFunc)GetProcAddress(hInstance_Slic3r,