From 8bc8dfaba4abdb88e64379bbb4d3527d87a5ac82 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Fri, 4 Jan 2019 12:06:25 +0100 Subject: [PATCH] Build: Fix install targets, add SLIC3R_FHS, check resource dir on GUI_App init Fix #1515 --- CMakeLists.txt | 24 ++++++++++++++++++------ src/CMakeLists.txt | 13 +++++++++++++ src/platform/unix/fhs.hpp.in | 2 ++ src/slic3r.cpp | 6 ++++++ src/slic3r/GUI/GUI_App.cpp | 7 ++++++- 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/platform/unix/fhs.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 781dbd01a..fad1af6f3 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/src/CMakeLists.txt b/src/CMakeLists.txt index 31c801379..fa043cf9e 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/platform/unix/fhs.hpp.in b/src/platform/unix/fhs.hpp.in new file mode 100644 index 000000000..8d03d4107 --- /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 59b23c133..6cd16889b 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/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 091071e16..ce7ea8bac 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