diff --git a/.gitignore b/.gitignore index e3a9db477..a14504ea1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ local-lib build-linux/* deps/build-linux/* **/.DS_Store +resources/plugins diff --git a/CMakeLists.txt b/CMakeLists.txt index e749fb28c..449f7539d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ 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) option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) +option(SLIC3R_ENABLE_FORMAT_STEP "Enable compilation of STEP file support" 1) # If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable. CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ea8eaa04..b75dcaa2f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,7 +17,10 @@ add_subdirectory(hints) add_subdirectory(qoi) add_subdirectory(libnest2d) add_subdirectory(libslic3r) -add_subdirectory(occt_wrapper) + +if (SLIC3R_ENABLE_FORMAT_STEP) + add_subdirectory(occt_wrapper) +endif () if (SLIC3R_GUI) add_subdirectory(imgui) diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index bd99d073a..7730b835a 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -3,6 +3,9 @@ #include "libslic3r/Model.hpp" #include "libslic3r/TriangleMesh.hpp" +#include "libslic3r/Utils.hpp" + +#include #include #include @@ -24,8 +27,10 @@ LoadStepFn get_load_step_fn() constexpr const char* fn_name = "load_step_internal"; if (!load_step_fn) { + auto libpath = boost::filesystem::path(resources_dir()) / "plugins"; #ifdef _WIN32 - HMODULE module = LoadLibraryW(L"OCCTWrapper.dll"); + libpath /= "OCCTWrapper.dll"; + HMODULE module = LoadLibraryW(libpath.wstring().c_str()); if (module == NULL) throw Slic3r::RuntimeError("Cannot load OCCTWrapper.dll"); @@ -42,18 +47,17 @@ LoadStepFn get_load_step_fn() throw; } #else - void *plugin_ptr = dlopen("OCCTWrapper.so", RTLD_NOW | RTLD_GLOBAL); + libpath /= "OCCTWrapper.so"; + void *plugin_ptr = dlopen(libpath.c_str(), RTLD_NOW | RTLD_GLOBAL); if (plugin_ptr) { - load_step_fn = reinterpret_cast(dlsym(plugin_ptr, "load_step_internal")); + load_step_fn = reinterpret_cast(dlsym(plugin_ptr, fn_name)); if (!load_step_fn) { dlclose(plugin_ptr); - throw Slic3r::RuntimeError("Cannot load function from OCCTWrapper.so"); + BOOST_LOG_TRIVIAL(error) << dlerror(); } } else { - throw Slic3r::RuntimeError( - std::string("Cannot load function from OCCTWrapper.dll: ") + - fn_name + "\n\nError code: " + dlerror()); + BOOST_LOG_TRIVIAL(error) << dlerror(); } #endif } diff --git a/src/occt_wrapper/CMakeLists.txt b/src/occt_wrapper/CMakeLists.txt index ccdfb14a8..4e78b83eb 100644 --- a/src/occt_wrapper/CMakeLists.txt +++ b/src/occt_wrapper/CMakeLists.txt @@ -5,8 +5,8 @@ add_library(OCCTWrapper MODULE OCCTWrapper.cpp) set_target_properties(OCCTWrapper PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/src" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/src" + LIBRARY_OUTPUT_DIRECTORY "${SLIC3R_RESOURCES_DIR}/plugins" + RUNTIME_OUTPUT_DIRECTORY "${SLIC3R_RESOURCES_DIR}/plugins" PREFIX "" )