From 89018b6e02e9d3fda30602cb4cf48f7750ace7b5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 14 Mar 2021 18:45:53 -0500 Subject: [PATCH] Backwards-compatible Boost 1.73 (#4996) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make boost::Placeholders::_1 visible Fixes https://github.com/slic3r/Slic3r/issues/4967 * Use boost/nowide/cstdlib.hpp instead of boost/nowide/cenv.hpp * Do not undefine __STRICT_ANSI__ The `__STRICT_ANSI__` macro is defined by the compiler and it's undefined to undefine or redefine it. Using `-U__STRICT_ANSI__ -std=c++11` is just silly. If you don't want strict mode, don't ask for strict mode. Certainly don't ask for strict mode and then undefined the macro that is defined by strict mode. The correct solution is `-std=gnu++11` which doesn't define the macro in the first place. * Help Slic3r::_Log out by adding methods to cover const char* and const wchar_t* (so our tests pass and things don't break when passed string literals). * calculation of COG in Slic3r (#4970) Implement center of gravity (COG) calculation and gcode output in Slic3r. * Comment out cpp travis osx until it's sorted * Fix misc. typos (#4857) * Fix misc. typos Found via `codespell -q 3 -S *.po,./t,./xs/t,./xs/xsp -L ot,uin` * Follow-up typo fixes * set progress on deploy script to avoid timeouts * cpp porting: TransformationMatrix class tests (#4906) * cpp porting: transformation class testing * reword some tests * remove obsolete include * change equality threshold implementation * semicolons help in C++ * Stop defining _GLIBCXX_USE_C99 (#4981) This is an internal macro defined by libstdc++ to record the result of configure checks done when GCC was built. Defining (or undefining or redefining) the macro yourself results in undefined behaviour. If the system's C library doesn't expose support for C99 or 'long long' then telling libstdc++ that it does isn't going to work. It will just mean libstdc++ tries to use features that don't actually exist in the C library. In any case, systems that don't support C99 are probably not relevant to anybody nowadays. Fixes #4975 * fix-cmake-boost-1-70+ (#4980) * Use boost/nowide/cstdlib.hpp instead of boost/nowide/cenv.hpp * Patch build to work on Boost 1.73 and older versions as well. * Add missing usage of boost::placeholders. * Add a using for boost versions > 1.73 Co-authored-by: Jonathan Wakely Co-authored-by: Jonathan Wakely Co-authored-by: Roman Dvořák Co-authored-by: luzpaz Co-authored-by: Michael Kirsch --- src/CMakeLists.txt | 25 +++++++++++++++---------- xs/Build.PL | 9 +++++++++ xs/src/exprtk/exprtk.hpp | 4 ++-- xs/src/libslic3r/ConfigBase.cpp | 5 +++++ xs/src/libslic3r/GCodeSender.hpp | 11 +++++++++++ xs/src/libslic3r/GCodeTimeEstimator.cpp | 10 +++++++++- xs/src/libslic3r/PrintObject.cpp | 8 ++++++++ xs/src/libslic3r/SLAPrint.cpp | 8 ++++++++ xs/src/libslic3r/SupportMaterial.cpp | 5 +++++ xs/src/libslic3r/TriangleMesh.cpp | 9 +++++++++ 10 files changed, 81 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d288999c1b..800d80cf17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,7 +115,7 @@ endif(NOT GIT_VERSION STREQUAL "") find_package(Threads REQUIRED) set(Boost_NO_BOOST_CMAKE ON) -find_package(Boost REQUIRED COMPONENTS system thread filesystem) +find_package(Boost REQUIRED COMPONENTS system thread filesystem OPTIONAL_COMPONENTS nowide) set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/) set(GUI_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/GUI/) @@ -231,6 +231,9 @@ add_library(libslic3r STATIC target_compile_features(libslic3r PUBLIC cxx_std_11) target_include_directories(libslic3r SYSTEM PUBLIC ${SLIC3R_INCLUDES}) target_include_directories(libslic3r PUBLIC ${LIBSLIC3R_INCLUDES}) +if (BOOST_NOWIDE_FOUND) + target_compile_options(libslic3r -DBOOST_INCLUDE_NOWIDE) +endif() add_library(BSpline STATIC ${LIBDIR}/BSpline/BSpline.cpp @@ -499,15 +502,17 @@ endif() # Windows needs a compiled component for Boost.nowide IF (WIN32) - add_library(boost-nowide STATIC - ${LIBDIR}/boost/nowide/iostream.cpp - ) - if(MSVC) - # Tell boost pragmas to not rename nowide as we are building it - add_definitions(-DBOOST_NOWIDE_NO_LIB) - endif() - target_link_libraries(slic3r boost-nowide) - target_include_directories(boost-nowide PUBLIC ${COMMON_INCLUDES}) + if (NOT BOOST_NOWIDE_FOUND) + add_library(boost-nowide STATIC + ${LIBDIR}/boost/nowide/iostream.cpp + ) + if(MSVC) + # Tell boost pragmas to not rename nowide as we are building it + add_definitions(-DBOOST_NOWIDE_NO_LIB) + endif() + target_link_libraries(slic3r boost-nowide) + target_include_directories(boost-nowide PUBLIC ${COMMON_INCLUDES}) + endif() # MinGW apparently has some multiple definitions of UUID-related items # deal with it. diff --git a/xs/Build.PL b/xs/Build.PL index 35356b8733..0655b7c12d 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -151,18 +151,27 @@ if (defined $ENV{BOOST_LIBRARYPATH}) { } # In order to generate the -l switches we need to know how Boost libraries are named my $have_boost = 0; +my $have_boost_optional = 0; my @boost_libraries = qw(system thread filesystem); # we need these +my @boost_optional_libraries = qw(nowide); # we need these, but if they aren't present we can deal # check without explicit lib path (works on Linux) if (! $mswin) { $have_boost = 1 if check_lib( lib => [ map "boost_${_}", @boost_libraries ], ); + $have_boost_optional = 1 + if check_lib( + lib => [ map "boost_${_}", @boost_optional_libraries ], + ); } if (!$ENV{SLIC3R_STATIC} && $have_boost) { # The boost library was detected by check_lib on Linux. push @LIBS, map "-lboost_${_}", @boost_libraries; + if (!$ENV{SLIC3R_STATIC} && $have_boost_optional) { + push @LIBS, map "-lboost_${_}", @boost_optional_libraries; + } } else { # Either static linking, or check_lib could not be used to find the boost libraries. my $lib_prefix = 'libboost_'; diff --git a/xs/src/exprtk/exprtk.hpp b/xs/src/exprtk/exprtk.hpp index cb65b5ff4f..c34063046a 100644 --- a/xs/src/exprtk/exprtk.hpp +++ b/xs/src/exprtk/exprtk.hpp @@ -11710,7 +11710,7 @@ namespace exprtk { public: - // Function of N paramters. + // Function of N parameters. typedef expression_node* expression_ptr; typedef std::pair branch_t; typedef IFunction ifunction; @@ -21226,7 +21226,7 @@ namespace exprtk if (index < error_list_.size()) return error_list_[index]; else - throw std::invalid_argument("parser::get_error() - Invalid error index specificed"); + throw std::invalid_argument("parser::get_error() - Invalid error index specified"); } inline std::string error() const diff --git a/xs/src/libslic3r/ConfigBase.cpp b/xs/src/libslic3r/ConfigBase.cpp index db2497af8e..975ac3710f 100644 --- a/xs/src/libslic3r/ConfigBase.cpp +++ b/xs/src/libslic3r/ConfigBase.cpp @@ -7,6 +7,7 @@ #include #include // std::runtime_error #include +#include #include #include #include @@ -16,7 +17,11 @@ #include #include #include +#ifdef BOOST_NOWIDE_FOUND +#include +#else #include +#endif #include #include #include diff --git a/xs/src/libslic3r/GCodeSender.hpp b/xs/src/libslic3r/GCodeSender.hpp index 0f39f5a3d1..4285025f42 100644 --- a/xs/src/libslic3r/GCodeSender.hpp +++ b/xs/src/libslic3r/GCodeSender.hpp @@ -7,7 +7,13 @@ #include #include #include + +#include +#if BOOST_VERSION >= 107300 +#include +#else #include +#endif #include #include @@ -15,6 +21,11 @@ namespace Slic3r { namespace asio = boost::asio; +#if BOOST_VERSION >= 107300 +using boost::placeholders::_1; +using boost::placeholders::_2; +#endif + class GCodeSender : private boost::noncopyable { public: GCodeSender(); diff --git a/xs/src/libslic3r/GCodeTimeEstimator.cpp b/xs/src/libslic3r/GCodeTimeEstimator.cpp index 818896bc16..f72b4762d4 100644 --- a/xs/src/libslic3r/GCodeTimeEstimator.cpp +++ b/xs/src/libslic3r/GCodeTimeEstimator.cpp @@ -1,9 +1,17 @@ #include "GCodeTimeEstimator.hpp" -#include #include +#include +#if BOOST_VERSION >= 107300 +#include +#endif namespace Slic3r { +#if BOOST_VERSION >= 107300 +using boost::placeholders::_1; +using boost::placeholders::_2; +#endif + void GCodeTimeEstimator::parse(const std::string &gcode) { diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index d9226c9913..79d0b22b4c 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -4,12 +4,20 @@ #include "Geometry.hpp" #include "Log.hpp" #include "TransformationMatrix.hpp" +#include +#if BOOST_VERSION >= 107300 +#include +#endif #include #include #include namespace Slic3r { +#if BOOST_VERSION >= 107300 +using boost::placeholders::_1; +#endif + PrintObject::PrintObject(Print* print, ModelObject* model_object, const BoundingBoxf3 &modobj_bbox) : layer_height_spline(model_object->layer_height_spline), typed_slices(false), diff --git a/xs/src/libslic3r/SLAPrint.cpp b/xs/src/libslic3r/SLAPrint.cpp index 84ce3568f8..0b5e5c528f 100644 --- a/xs/src/libslic3r/SLAPrint.cpp +++ b/xs/src/libslic3r/SLAPrint.cpp @@ -7,9 +7,17 @@ #include #include #include +#include +#if BOOST_VERSION >= 107300 +#include +#endif namespace Slic3r { +#if BOOST_VERSION >= 107300 +using boost::placeholders::_1; +#endif + void SLAPrint::slice() { diff --git a/xs/src/libslic3r/SupportMaterial.cpp b/xs/src/libslic3r/SupportMaterial.cpp index 83d5ca002f..ce9ac952c1 100644 --- a/xs/src/libslic3r/SupportMaterial.cpp +++ b/xs/src/libslic3r/SupportMaterial.cpp @@ -1,9 +1,14 @@ #include "SupportMaterial.hpp" #include "Log.hpp" + namespace Slic3r { +#if BOOST_VERSION >= 107300 +using boost::placeholders::_1; +#endif + PolylineCollection _fill_surface(Fill *fill, Surface *surface) { PolylineCollection ps; diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 692fce8453..c13802c1d6 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -13,8 +13,12 @@ #include #include #include +#include #include #include +#if BOOST_VERSION >= 107300 +#include +#endif #ifdef SLIC3R_DEBUG #include "SVG.hpp" @@ -22,6 +26,11 @@ namespace Slic3r { + +#if BOOST_VERSION >= 107300 +using boost::placeholders::_1; +#endif + TriangleMesh::TriangleMesh() : repaired(false) {