diff --git a/CMakeLists.txt b/CMakeLists.txt index 781dbd01ae..fad1af6f3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ project(Slic3r) cmake_minimum_required(VERSION 3.2) include("version.inc") +include(GNUInstallDirs) + set(SLIC3R_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") file(TO_NATIVE_PATH "${SLIC3R_RESOURCES_DIR}" SLIC3R_RESOURCES_DIR_WIN) @@ -22,6 +24,7 @@ endif() option(SLIC3R_STATIC "Compile Slic3r with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL}) option(SLIC3R_GUI "Compile Slic3r with GUI components (OpenGL, wxWidgets)" 1) +option(SLIC3R_FHS "Assume Slic3r is to be installed in a FHS directory structure" 0) option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0) option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) @@ -61,6 +64,8 @@ foreach (DIR ${PREFIX_PATH_CHECK}) endif () endforeach () +message(STATUS "SLIC3R_FHS: ${SLIC3R_FHS}") + # Add our own cmake module path. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/) @@ -146,12 +151,14 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STRE endif() # Where all the bundled libraries reside? -set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/) +set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src) +set(LIBDIR_BIN ${CMAKE_CURRENT_BINARY_DIR}/src) # For the bundled boost libraries (boost::nowide) include_directories(${LIBDIR}) +# For generated header files +include_directories(${LIBDIR_BIN}/platform) # For libslic3r.h include_directories(${LIBDIR}/clipper ${LIBDIR}/polypartition) -#set(CMAKE_INCLUDE_CURRENT_DIR ON) if(WIN32) # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking. @@ -215,7 +222,6 @@ endif() # The Intel TBB library will use the std::exception_ptr feature of C++11. add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0) -#set(CURL_DEBUG 1) find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIRS}) @@ -280,7 +286,6 @@ include_directories(${GLEW_INCLUDE_DIRS}) # l10n set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization") add_custom_target(pot - # FIXME: file list stale COMMAND xgettext --keyword=L --from-code=UTF-8 --debug -f "${L10N_DIR}/list.txt" -o "${L10N_DIR}/Slic3rPE.pot" @@ -307,5 +312,12 @@ if(SLIC3R_BUILD_TESTS) add_subdirectory(tests) endif() -file(GLOB MyVar var/*.png) -install(FILES ${MyVar} DESTINATION share/slic3r-prusa3d) + +# Resources install target, configure fhs.hpp on UNIX +if (WIN32) + install(DIRECTORY "${SLIC3R_RESOURCES_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/resources") +else () + set(SLIC3R_FHS_RESOURCES "${CMAKE_INSTALL_FULL_DATAROOTDIR}/slic3r-prusa3d") + install(DIRECTORY "${SLIC3R_RESOURCES_DIR}/" DESTINATION "${SLIC3R_FHS_RESOURCES}") +endif () +configure_file(${LIBDIR}/platform/unix/fhs.hpp.in ${LIBDIR_BIN}/platform/unix/fhs.hpp) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 8f98e0bdaa..1b23c58648 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -6,6 +6,7 @@ # All the dependencies are installed in a `destdir` directory in the root of the build directory, # in a traditional Unix-style prefix structure. The destdir can be used directly by CMake # when building Slic3r - to do this, set the CMAKE_PREFIX_PATH to ${destdir}/usr/local. +# Warning: On UNIX/Linux, you also need to set -DSLIC3R_STATIC=1 when building Slic3r. # # For better clarity of console output, it's recommended to _not_ use a parallelized build # for the top-level command, ie. use `make -j 1` or `ninja -j 1` to force single-threaded top-level diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index d49434ecb1..17dfae8bd1 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -121,7 +121,8 @@ ExternalProject_Add(dep_zlib URL_HASH SHA256=4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066 CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_ARGS - "-DINSTALL_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}\\fallout" # I found no better way of preventing zlib creating & installing DLLs :-/ + -DSKIP_INSTALL_FILES=ON # Prevent installation of man pages et al. + "-DINSTALL_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}\\fallout" # I found no better way of preventing zlib from creating & installing DLLs :-/ -DCMAKE_POSITION_INDEPENDENT_CODE=ON "-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local" BUILD_COMMAND msbuild /P:Configuration=Release INSTALL.vcxproj @@ -136,6 +137,19 @@ if (${DEP_DEBUG}) WORKING_DIRECTORY "${BINARY_DIR}" ) endif () +# The following steps are unfortunately needed to remove the _static suffix on libraries +ExternalProject_Add_Step(dep_zlib fix_static + DEPENDEES install + COMMAND "${CMAKE_COMMAND}" -E rename zlibstatic.lib zlib.lib + WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" +) +if (${DEP_DEBUG}) + ExternalProject_Add_Step(dep_zlib fix_static_debug + DEPENDEES install + COMMAND "${CMAKE_COMMAND}" -E rename zlibstaticd.lib zlibd.lib + WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" + ) +endif () ExternalProject_Add(dep_libpng @@ -147,6 +161,7 @@ ExternalProject_Add(dep_libpng CMAKE_ARGS -DPNG_SHARED=OFF -DPNG_TESTS=OFF + -DSKIP_INSTALL_FILES=ON # Prevent installation of man pages et al. -DCMAKE_POSITION_INDEPENDENT_CODE=ON "-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local" BUILD_COMMAND msbuild /P:Configuration=Release INSTALL.vcxproj @@ -161,6 +176,20 @@ if (${DEP_DEBUG}) WORKING_DIRECTORY "${BINARY_DIR}" ) endif () +# The following steps are unfortunately needed to remove the _static suffix on libraries +# (And also overwrite the dynamic .lib) +ExternalProject_Add_Step(dep_libpng fix_static + DEPENDEES install + COMMAND "${CMAKE_COMMAND}" -E rename libpng16_static.lib libpng16.lib + WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" +) +if (${DEP_DEBUG}) + ExternalProject_Add_Step(dep_libpng fix_static_debug + DEPENDEES install + COMMAND "${CMAKE_COMMAND}" -E rename libpng16_staticd.lib libpng16d.lib + WORKING_DIRECTORY "${DESTDIR}\\usr\\local\\lib\\" + ) +endif () if (${DEPS_BITS} EQUAL 32) diff --git a/doc/How to build - Linux et al.md b/doc/How to build - Linux et al.md new file mode 100644 index 0000000000..e665cd14cd --- /dev/null +++ b/doc/How to build - Linux et al.md @@ -0,0 +1,66 @@ + +# Building Slic3r PE on UNIX/Linux + +Slic3r PE uses the CMake build system and requires several dependencies. +The dependencies can be listed in `deps/deps-linux.cmake`, although they don't necessarily need to be as recent +as the versions listed - generally versions available on conservative Linux distros such as Debian stable or CentOS should suffice. + +Perl is not required any more. + +In a typical situaction, one would open a command line, go to the Slic3r sources, create a directory called `build` or similar, +`cd` into it and call: + + cmake .. + make -jN + +where `N` is the number of CPU cores available. + +Additional CMake flags may be applicable as explained below. + +### Dependenciy resolution + +By default Slic3r looks for dependencies the default way CMake looks for them, ie. in default system locations. +On Linux this will typically make Slic3r depend on dynamically loaded libraries from the system, however, Slic3r can be told +to specifically look for static libraries with the `SLIC3R_STATIC` flag passed to cmake: + + cmake .. -DSLIC3R_STATIC=1 + +Additionally, Slic3r can be built in a static manner mostly independent of the system libraries with a dependencies bundle +created using CMake script in the `deps` directory (these are not interconnected with the rest of the CMake scripts). + +Note: We say _mostly independent_ because it's still expected the system will provide some transitive dependencies, such as GTK for wxWidgets. + +To do this, go to the `deps` directory, create a `build` subdirectory (or the like) and use: + + cmake .. -DDESTDIR= + +where the target destdir is a directory of your choosing where the dependencies will be installed. +You can also omit the `DESTDIR` option to use the default, in that case the `destdir` will be created inside the `build` directory where `cmake` is run. + +To pass the destdir path to the top-level Slic3r CMake script, use the `CMAKE_PREFIX_PATH` option along with turning on `SLIC3R_STATIC`: + + cmake .. -DSLIC3R_STATIC=1 -DCMAKE_PREFIX_PATH=/usr/local + +Note that `/usr/local` needs to be appended to the destdir path and also the prefix path should be absolute. + +**Warning**: Once the dependency bundle is installed in a destdir, the destdir cannot be moved elsewhere. +This is because wxWidgets hardcode the installation path. + +### Build variant + +By default Scli3r builds the release variant. +To create a debug build, use the following CMake flag: + + -DCMAKE_BUILD_TYPE=Debug + +### Installation + +In runtime, Slic3r needs a way to access its resource files. By default, it looks for a `resources` directory relative to its binary. + +If you instead wnat Slic3r installed in a structure according to the Filesystem Hierarchy Standard, use the `SLIC3R_FHS` flag + + cmake .. -DSLIC3R_FHS=1 + +This will make Slic3r look for a fixed-location `share/slic3r-prusa3d` directory instead (note that the location becomes hardcoded). + +You can then use the `make install` target to install Slic3r. diff --git a/doc/How to build - Mac OS.md b/doc/How to build - Mac OS.md new file mode 100644 index 0000000000..a2d7cf7fe0 --- /dev/null +++ b/doc/How to build - Mac OS.md @@ -0,0 +1,62 @@ + +# Building Slic3r PE on Mac OS + +To build Slic3r PE on Mac OS, you will need to install XCode and an appropriate SDK. +You will also need [CMake](https://cmake.org/) installed (available on Brew) and possibly git. + +Currently Slic3r PE is built against the Mac OS X SDK version 10.9. +Building against older SDKs is unsupported. Building against newer SDKs might work, +but there may be subtle issues, such as dark mode not working very well on Mojave or other GUI problems. + +You can obtain the SDK 10.9 for example [in this repository](https://github.com/phracker/MacOSX-SDKs). +If you don't already have the 10.9 version as part of your Mac OS installation, please download it +and place it into a reachable location. + +The default location for Mac OS SDKs is: + + /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ + +Wherever the 10.9 SDK is, please note down its location, it will be required to build Slic3r. + +On my system, for example, the path to the SDK is + + /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk + +### Dependencies + +Slic3r comes with a set of CMake scripts to build its dependencies, it lives in the `deps` directory. +Open a terminal window and navigate to Slic3r sources directory and then to `deps`. +Use the following commands to build the dependencies: + + mkdir build + cd build + cmake .. -DDEPS_OSX_SYSROOT= + +This will create a dependencies bundle inside the `build/destdir` directory. +You can also customize the bundle output path using the `-DDESTDIR=` option passed to `cmake`. + +### Building Slic3r + +If dependencies built without an error, you can proceed to build Slic3r itself. +Go back to top level Slic3r sources directory and use these commands: + + mkdir build + cd build + cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_SYSROOT= + +The `CMAKE_PREFIX_PATH` is the path to the dependencies bundle but with `/usr/local` appended - if you set a custom path +using the `DESTDIR` option, you will need to change this accordingly. **Warning:** the `CMAKE_PREFIX_PATH` needs to be an absolute path. + +The CMake command above prepares Slic3r for building from the command line. +To start the build, use + + make -jN + +where `N` is the number of CPU cores, so, for example `make -j4` for a 4-core machine. + +Alternatively, if you would like to use XCode GUI, modify the `cmake` command to include the `-GXcode` option: + + cmake .. -GXcode -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_SYSROOT= + +and then open the `Slic3r.xcodeproj` file. +This should open up XCode where you can perform build using the GUI or perform other tasks. diff --git a/doc/How to build - Windows.md b/doc/How to build - Windows.md index 5c8e7ef3cc..898c830d09 100644 --- a/doc/How to build - Windows.md +++ b/doc/How to build - Windows.md @@ -1,99 +1,98 @@ -### NOTE: This document is currently outdated wrt. the new post-Perl Slic3rPE. A new build process and the description thereof is a work in progress and is comming soon. Please stay tuned. - --- - - # Building Slic3r PE on Microsoft Windows -The currently supported way of building Slic3r PE on Windows is with CMake and MS Visual Studio 2013 -using our Perl binary distribution (compiled from official Perl sources). +The currently supported way of building Slic3r PE on Windows is with CMake and MS Visual Studio 2013. You can use the free [Visual Studio 2013 Community Edition](https://www.visualstudio.com/vs/older-downloads/). CMake installer can be downloaded from [the official website](https://cmake.org/download/). -Other setups (such as mingw + Strawberry Perl) _may_ work, but we cannot guarantee this will work -and cannot provide guidance. +Building with newer versions of MSVS (2015, 2017) may work too as reported by some of our users. +_Note:_ Thanks to **@supermerill** for testing and inspiration on this guide. -### Geting the dependencies +### Dependencies -First, download and upnack our Perl + wxWidgets binary distribution: +On Windows Slic3r is built against statically built libraries. +We provide a prebuilt package of all the needed dependencies. +The package comes in a several variants: - - 32 bit, release mode: [wperl32-5.24.0-2018-03-02.7z](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=wperl32-5.24.0-2018-03-02.7z) - - 64 bit, release mode: [wperl64-5.24.0-2018-03-02.7z](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=wperl64-5.24.0-2018-03-02.7z) - - 64 bit, release mode + debug symbols: [wperl64d-5.24.0-2018-03-02.7z](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=wperl64d-5.24.0-2018-03-02.7z) + - [64 bit, Release mode only](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=destdir-64.7z) (41 MB, 578 MB unpacked) + - [64 bit, Release and Debug mode](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=destdir-64-dev.7z) (88 MB, 1.3 GB unpacked) + - [32 bit, Release mode only](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=destdir-32.7z) (38 MB, 520 MB unpacked) + - [32 bit, Release and Debug mode](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=destdir-32-dev.7z) (74 MB, 1.1 GB unpacked) -It is recommended to unpack this package into `C:\`. +When unsure, use the _Release mode only_ variant, the _Release and Debug_ variant is only needed for debugging & developement. -Apart from wxWidgets and Perl, you will also need additional dependencies: +If you're unsure where to unpack the package, unpack it into `C:\local\` (but it can really be anywhere). - - Boost - - Intel TBB - - libcurl +Alternatively you can also compile the dependencies yourself, see below. -We have prepared a binary package of the listed libraries: +### Building Slic3r PE with Visual Studio - - 32 bit: [slic3r-destdir-32.7z](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=2%2Fslic3r-destdir-32.7z) - - 64 bit: [slic3r-destdir-64.7z](https://bintray.com/vojtechkral/Slic3r-PE/download_file?file_path=2%2Fslic3r-destdir-64.7z) +First obtain the Slic3 PE sources via either git or by extracting the source archive. -It is recommended you unpack this package into `C:\local\` as the environment -setup script expects it there. +Then you will need to note down the so-called 'prefix path' to the dependencies, this is the location of the dependencies packages + `\usr\local` appended. +For example on 64 bits this would be `C:\local\destdir-64\usr\local`. The prefix path will need to be passed to CMake. -Alternatively you can also compile the additional dependencies yourself. -There is a [powershell script](./deps-build/windows/slic3r-makedeps.ps1) which automates this process. +When ready, open the relevant Visual Studio command line and `cd` into the directory with Slic3r sources. +Use these commands to prepare Visual Studio solution file: -### Building Slic3r PE - -Once the dependencies are set up in their respective locations, -go to the `wperl*` directory extracted earlier and launch the `cmdline.lnk` file -which opens a command line prompt with appropriate environment variables set up. - -In this command line, `cd` into the directory with Slic3r sources -and use these commands to build the Slic3r from the command line: - - perl Build.PL - perl Build.PL --gui mkdir build cd build - cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release - nmake - cd .. - perl slic3r.pl + cmake .. -G "Visual Studio 12 Win64" -DCMAKE_PREFIX_PATH="" -The above commands use `nmake` Makefiles. -You may also build Slic3r PE with other build tools: +Note that if you're building a 32-bit variant, you will need to change the `"Visual Studio 12 Win64"` to just `"Visual Studio 12"`. +Conversely, if you're using Visual Studio version other than 2013, the version number will need to be changed accordingly. -### Building with Visual Studio +If `cmake` has finished without errors, go to the build directory and open the `Slic3r.sln` solution file in Visual Studio. +Before building, make sure you're building the right project (use one of those starting with `slic3r_app_...`) and that you're building +with the right configuration, ie. _Release_ vs. _Debug_. When unsure, choose _Release_. +Note that you won't be able to build a _Debug_ variant against a _Release_-only dependencies package. -To build and debug Slic3r PE with Visual Studio (64 bits), replace the `cmake` command with: +#### Installing using the `INSTALL` project - cmake .. -G "Visual Studio 12 Win64" -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo +Slic3r PE can be run from the Visual Studio or from Visual Studio's build directory (`src\Release` or `src\Debug`), +but for longer-term usage you migth want to install somewhere using the `INSTALL` project. +By default, this installs into `C:\Program Files\Slic3r`. +To customize the install path, use the `-DCMAKE_INSTALL_PREFIX=` when invoking `cmake`. -For the 32-bit variant, use: +### Building from the command line - cmake .. -G "Visual Studio 12" -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo +There are several options for building from the command line: -After `cmake` has finished, go to the build directory and open the `Slic3r.sln` solution file. -This should open Visual Studio and load the Slic3r solution containing all the projects. -Make sure you use Visual Studio 2013 to open the solution. +- [msbuild](https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-reference?view=vs-2017&viewFallbackFrom=vs-2013) +- [Ninja](https://ninja-build.org/) +- [nmake](https://docs.microsoft.com/en-us/cpp/build/nmake-reference?view=vs-2017) -You can then use the usual Visual Studio controls to build Slic3r (Hit `F5` to build and run with debugger). -If you want to run or debug Slic3r from within Visual Studio, make sure the `XS` project is activated. -It should be set as the Startup project by CMake by default, but you might want to check anyway. -There are multiple projects in the Slic3r solution, but only the `XS` project is configured with the right -commands to run and debug Slic3r. +To build with msbuild, use the same CMake command as in previous paragraph and then build using -The above cmake commands generate Visual Studio project files with the `RelWithDebInfo` configuration only. -If you also want to use the `Release` configuration, you can generate Visual Studio projects with: + msbuild /P:Configuration=Release ALL_BUILD.vcxproj - -DCMAKE_CONFIGURATION_TYPES=Release;RelWithDebInfo +To build with Ninja or nmake, replace the `-G` option in the CMake call with `-G Ninja` or `-G "NMake Makefiles"` , respectively. +Then use either `ninja` or `nmake` to start the build. -(The `Debug` configuration is not supported as of now.) +To install, use `msbuild /P:Configuration=Release INSTALL.vcxproj` , `ninja install` , or `nmake install` . -### Building with ninja +### Building the dependencies package yourself -To use [Ninja](https://ninja-build.org/), replace the `cmake` and `nmake` commands with: +The dependencies package is built using CMake scripts inside the `deps` subdirectory of Slic3r PE sources. +(This is intentionally not interconnected with the CMake scripts in the rest of the sources.) - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release - ninja +Open the preferred Visual Studio command line (64 or 32 bit variant) and `cd` into the directory with Slic3r sources. +Then `cd` into the `deps` directory and use these commands to build: + + mkdir build + cd build + cmake .. -G "Visual Studio 12 Win64" -DDESTDIR="C:\local\destdir-custom" + msbuild ALL_BUILD.vcxproj + +You can also use the Visual Studio GUI or other generators as mentioned above. + +The `DESTDIR` option is the location where the bundle will be installed. +This may be customized. If you leave it empty, the `DESTDIR` will be places inside the same `build` directory. + +Note that the build variant that you may choose using Visual Studio (ie. _Release_ or _Debug_ etc.) when building the dependency package is **not relevant**. +The dependency build will by default build _both_ the _Release_ and _Debug_ variants regardless of what you choose in Visual Studio. +You can disable building of the debug variant by passing the `-DDEP_DEBUG=OFF` option to CMake, this will only produce a _Release_ build. + +Refer to the CMake scripts inside the `deps` directory to see which dependencies are built in what versions and how this is done. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31c8013796..fa043cf9ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,7 @@ if(PNG_FOUND AND NOT RASTERIZER_FORCE_BUILTIN_LIBPNG) else() set(ZLIB_LIBRARY "") message(WARNING "Using builtin libpng. This can cause crashes on some platforms.") + set(SKIP_INSTALL_ALL 1) # Prevent png+zlib from creating install targets add_subdirectory(png/zlib) set(ZLIB_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/png/zlib ${CMAKE_CURRENT_BINARY_DIR}/png/zlib) include_directories(${ZLIB_INCLUDE_DIR}) @@ -188,3 +189,15 @@ else () VERBATIM ) endif() + +# Slic3r binary install target +if (WIN32) + install(TARGETS slic3r RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}") + if (MSVC) + install(TARGETS slic3r_app_gui RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}") + install(TARGETS slic3r_app_console RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}") + install(TARGETS slic3r_app_noconsole RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}") + endif () +else () + install(TARGETS slic3r RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif () diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 7f826109a4..e0544b1534 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -218,7 +218,7 @@ public: const T& get_at(size_t i) const { return const_cast*>(this)->get_at(i); } - // Resize this vector by duplicating the last value. + // Resize this vector by duplicating the /*last*/first value. // If the current vector is empty, the default value is used instead. void resize(size_t n, const ConfigOption *opt_default = nullptr) override { @@ -238,7 +238,7 @@ public: this->values.resize(n, static_cast*>(opt_default)->values.front()); } else { // Resize by duplicating the last value. - this->values.resize(n, this->values.back()); + this->values.resize(n, this->values./*back*/front()); } } } diff --git a/src/platform/unix/fhs.hpp.in b/src/platform/unix/fhs.hpp.in new file mode 100644 index 0000000000..8d03d4107d --- /dev/null +++ b/src/platform/unix/fhs.hpp.in @@ -0,0 +1,2 @@ +#cmakedefine SLIC3R_FHS @SLIC3R_FHS@ +#define SLIC3R_FHS_RESOURCES "@SLIC3R_FHS_RESOURCES@" diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 59b23c133e..6cd16889b4 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -22,6 +22,8 @@ #include #include +#include "unix/fhs.hpp" // Generated by CMake from ../platform/unix/fhs.hpp.in + #include "libslic3r/libslic3r.h" #include "libslic3r/Config.hpp" #include "libslic3r/Geometry.hpp" @@ -77,6 +79,10 @@ int main(int argc, char **argv) // The resources are packed to 'resources' // Path from Slic3r binary to resources: boost::filesystem::path path_resources = path_to_binary.parent_path() / "resources"; +#elif defined SLIC3R_FHS + // The application is packaged according to the Linux Filesystem Hierarchy Standard + // Resources are set to the 'Architecture-independent (shared) data', typically /usr/share or /usr/local/share + boost::filesystem::path path_resources = SLIC3R_FHS_RESOURCES; #else // The application is packed in the .tar.bz archive (or in AppImage) as 'bin/slic3r', // The resources are packed to 'resources' diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 928a6236ef..91052570d0 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -474,6 +474,7 @@ void Choice::BUILD() { if (temp->GetWindowStyle() != wxCB_READONLY) { temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { e.Skip(); + if (m_opt.type == coStrings) return; double old_val = !m_value.empty() ? boost::any_cast(m_value) : -99999; if (is_defined_input_value(window, m_opt.type)) { if (fabs(old_val - boost::any_cast(get_value())) <= 0.0001) @@ -692,7 +693,7 @@ boost::any& Choice::get_value() } else if (m_opt.gui_type == "f_enum_open") { const int ret_enum = static_cast(window)->GetSelection(); - if (ret_enum < 0 || m_opt.enum_values.empty()) + if (ret_enum < 0 || m_opt.enum_values.empty() || m_opt.type == coStrings) get_value_by_opt_type(ret_str); else m_value = atof(m_opt.enum_values[ret_enum].c_str()); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 8cd80ad7de..a6d0f4e9d5 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3979,6 +3979,12 @@ BoundingBoxf3 GLCanvas3D::scene_bounding_box() const { BoundingBoxf3 bb = volumes_bounding_box(); bb.merge(m_bed.get_bounding_box()); + if (m_config != nullptr) + { + double h = m_config->opt_float("max_print_height"); + bb.min(2) = std::min(bb.min(2), -h); + bb.max(2) = std::max(bb.max(2), h); + } return bb; } @@ -4939,8 +4945,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (evt.Entering()) { -#if defined(__WXMSW__) || defined(__linux__) - // On Windows and Linux needs focus in order to catch key events +//#if defined(__WXMSW__) || defined(__linux__) +// // On Windows and Linux needs focus in order to catch key events + // Set focus in order to remove it from sidebar fields if (m_canvas != nullptr) { // Only set focus, if the top level window of this canvas is active. auto p = dynamic_cast(evt.GetEventObject()); @@ -4952,7 +4959,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } m_mouse.set_start_position_2D_as_invalid(); -#endif +//#endif } else if (evt.Leaving()) { diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index df5c1d4076..0a27af9fa7 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -154,13 +154,15 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt } else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0) { std::string str = boost::any_cast(value); - if (str.back() == ';') str.pop_back(); - // Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. - // Currently used for the post_process config value only. - std::vector values; - boost::split(values, str, boost::is_any_of(";")); - if (values.size() == 1 && values[0] == "") - values.resize(0);//break; + std::vector values {}; + if (!str.empty()) { + if (str.back() == ';') str.pop_back(); + // Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. + // Currently used for the post_process config value only. + boost::split(values, str, boost::is_any_of(";")); + if (values.size() == 1 && values[0] == "") + values.resize(0); + } config.option(opt_key)->values = values; } else{ diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 091071e16f..ce7ea8bac9 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" @@ -83,6 +83,11 @@ GUI_App::GUI_App() bool GUI_App::OnInit() { + // Verify resources path + const wxString resources_dir = from_u8(Slic3r::resources_dir()); + wxCHECK_MSG(wxDirExists(resources_dir), false, + wxString::Format("Resources path does not exist or is not a directory: %s", resources_dir)); + #if ENABLE_IMGUI wxCHECK_MSG(m_imgui->init(), false, "Failed to initialize ImGui"); #endif // ENABLE_IMGUI diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 1848ddda74..f763cc5a12 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -244,15 +244,13 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele if ((0 <= obj_idx) && (obj_idx < (int)wxGetApp().model_objects()->size())) { bool changed_box = false; - if ((m_cache.object_idx != obj_idx) || (m_cache.instance_idx != instance_idx)) + if (!m_cache.instance.matches_object(obj_idx)) { - m_cache.object_idx = obj_idx; - m_cache.instance_idx = instance_idx; - m_cache.instance_box_size = (*wxGetApp().model_objects())[obj_idx]->raw_mesh().bounding_box().size(); + m_cache.instance.set(obj_idx, instance_idx, (*wxGetApp().model_objects())[obj_idx]->raw_mesh().bounding_box().size()); changed_box = true; } - if (changed_box || !m_cache.scale.isApprox(100.0 * m_new_scale) || !m_cache.rotation.isApprox(m_new_rotation)) - m_new_size = volume->get_instance_transformation().get_matrix(true, true) * m_cache.instance_box_size; + if (changed_box || !m_cache.instance.matches_instance(instance_idx) || !m_cache.scale.isApprox(100.0 * m_new_scale)) + m_new_size = volume->get_instance_transformation().get_matrix(true, true) * m_cache.instance.box_size; } else // this should never happen @@ -270,8 +268,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele else if (selection.is_single_full_object()) { #if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION - m_cache.object_idx = -1; - m_cache.instance_idx = -1; + m_cache.instance.reset(); #endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION const BoundingBoxf3& box = selection.get_bounding_box(); @@ -286,8 +283,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele else if (selection.is_single_modifier() || selection.is_single_volume()) { #if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION - m_cache.object_idx = -1; - m_cache.instance_idx = -1; + m_cache.instance.reset(); #endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION // the selection contains a single volume @@ -433,8 +429,7 @@ void ObjectManipulation::reset_settings_value() m_new_size = Vec3d::Zero(); m_new_enabled = false; #if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION - m_cache.object_idx = -1; - m_cache.instance_idx = -1; + m_cache.instance.reset(); #endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION #if !ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION m_dirty = true; @@ -514,6 +509,9 @@ void ObjectManipulation::change_scale_value(const Vec3d& scale) canvas->do_scale(); #if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION + if (!m_cache.scale.isApprox(scale)) + m_cache.instance.instance_idx = -1; + m_cache.scale = scale; #endif // ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION } diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index ee768510ab..97cd2b6390 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -26,16 +26,25 @@ class ObjectManipulation : public OG_Settings std::string rotate_label_string; std::string scale_label_string; - int object_idx; - int instance_idx; + struct Instance + { + int object_idx; + int instance_idx; + Vec3d box_size; - Vec3d instance_box_size; + Instance() { reset(); } + void reset() { this->object_idx = -1; this->instance_idx = -1; this->box_size = Vec3d::Zero(); } + void set(int object_idx, int instance_idx, const Vec3d& box_size) { this->object_idx = object_idx; this->instance_idx = instance_idx; this->box_size = box_size; } + bool matches(int object_idx, int instance_idx) const { return (this->object_idx == object_idx) && (this->instance_idx == instance_idx); } + bool matches_object(int object_idx) const { return (this->object_idx == object_idx); } + bool matches_instance(int instance_idx) const { return (this->instance_idx == instance_idx); } + }; + + Instance instance; Cache() : position(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX)) , rotation(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX)) , scale(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX)) , size(Vec3d(DBL_MAX, DBL_MAX, DBL_MAX)) , move_label_string("") , rotate_label_string("") , scale_label_string("") - , object_idx(-1) - , instance_idx(-1) { } }; diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 0a2f984145..14ddaad493 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -1053,7 +1053,7 @@ std::vector PresetCollection::dirty_options(const Preset *edited, c std::vector changed; if (edited != nullptr && reference != nullptr) { changed = deep_compare ? - deep_diff(reference->config, edited->config) : + deep_diff(edited->config, reference->config) : reference->config.diff(edited->config); // The "compatible_printers" option key is handled differently from the others: // It is not mandatory. If the key is missing, it means it is compatible with any printer.