Skip to content

Commit

Permalink
Backwards-compatible Boost 1.73 (slic3r#4996)
Browse files Browse the repository at this point in the history
* Make boost::Placeholders::_1 visible

Fixes slic3r#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 (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 (slic3r#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 (slic3r#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 (slic3r#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 slic3r#4975

* fix-cmake-boost-1-70+ (slic3r#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 <[email protected]>
Co-authored-by: Jonathan Wakely <[email protected]>
Co-authored-by: Roman Dvořák <[email protected]>
Co-authored-by: luzpaz <[email protected]>
Co-authored-by: Michael Kirsch <[email protected]>
  • Loading branch information
6 people committed Mar 14, 2021
1 parent 72436ab commit 89018b6
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 13 deletions.
25 changes: 15 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions xs/Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -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_';
Expand Down
4 changes: 2 additions & 2 deletions xs/src/exprtk/exprtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11710,7 +11710,7 @@ namespace exprtk
{
public:

// Function of N paramters.
// Function of N parameters.
typedef expression_node<T>* expression_ptr;
typedef std::pair<expression_ptr,bool> branch_t;
typedef IFunction ifunction;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions xs/src/libslic3r/ConfigBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sstream>
#include <exception> // std::runtime_error
#include <set>
#include <boost/version.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/erase.hpp>
Expand All @@ -16,7 +17,11 @@
#include <boost/config.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#ifdef BOOST_NOWIDE_FOUND
#include <boost/nowide/cstdlib.hpp>
#else
#include <boost/nowide/cenv.hpp>
#endif
#include <boost/nowide/fstream.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>
Expand Down
11 changes: 11 additions & 0 deletions xs/src/libslic3r/GCodeSender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
#include <string>
#include <vector>
#include <boost/asio.hpp>

#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <boost/bind/bind.hpp>
#else
#include <boost/bind.hpp>
#endif
#include <boost/thread.hpp>
#include <boost/core/noncopyable.hpp>

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();
Expand Down
10 changes: 9 additions & 1 deletion xs/src/libslic3r/GCodeTimeEstimator.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include "GCodeTimeEstimator.hpp"
#include <boost/bind.hpp>
#include <cmath>
#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <boost/bind/bind.hpp>
#endif

namespace Slic3r {

#if BOOST_VERSION >= 107300
using boost::placeholders::_1;
using boost::placeholders::_2;
#endif

void
GCodeTimeEstimator::parse(const std::string &gcode)
{
Expand Down
8 changes: 8 additions & 0 deletions xs/src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
#include "Geometry.hpp"
#include "Log.hpp"
#include "TransformationMatrix.hpp"
#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <boost/bind/bind.hpp>
#endif
#include <algorithm>
#include <vector>
#include <limits>

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),
Expand Down
8 changes: 8 additions & 0 deletions xs/src/libslic3r/SLAPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
#include <iostream>
#include <complex>
#include <cstdio>
#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <boost/bind/bind.hpp>
#endif

namespace Slic3r {

#if BOOST_VERSION >= 107300
using boost::placeholders::_1;
#endif

void
SLAPrint::slice()
{
Expand Down
5 changes: 5 additions & 0 deletions xs/src/libslic3r/SupportMaterial.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 9 additions & 0 deletions xs/src/libslic3r/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@
#include <math.h>
#include <assert.h>
#include <stdexcept>
#include <boost/version.hpp>
#include <boost/config.hpp>
#include <boost/nowide/convert.hpp>
#if BOOST_VERSION >= 107300
#include <boost/bind/bind.hpp>
#endif

#ifdef SLIC3R_DEBUG
#include "SVG.hpp"
#endif

namespace Slic3r {


#if BOOST_VERSION >= 107300
using boost::placeholders::_1;
#endif

TriangleMesh::TriangleMesh()
: repaired(false)
{
Expand Down

0 comments on commit 89018b6

Please sign in to comment.