CMake build process - fixes of the previous check-ins to build

cleanly on Windows & Linux. There is still a work on OSX:
The XS module has to be linked without perl.lib and with
the following parameters to produce a bundle: -bundle -undefined dynamic_lookup
This commit is contained in:
bubnikv 2017-08-18 21:09:53 +02:00
parent e2a685b8bb
commit ba1c0b0137
8 changed files with 81 additions and 86 deletions

View File

@ -14,6 +14,7 @@ execute_process(
# Import Perl modules. # Import Perl modules.
use strict; use strict;
use warnings; use warnings;
use Config;
use Text::ParseWords; use Text::ParseWords;
use ExtUtils::CppGuess; use ExtUtils::CppGuess;
@ -45,9 +46,13 @@ sub cmake_set_var {
my @words = shellwords(\$content); my @words = shellwords(\$content);
print \$fh \"set(PerlEmbed_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\"; print \$fh \"set(PerlEmbed_\$varname \\\"\" . join(';', @words) . \"\\\")\\n\";
} }
cmake_set_var('CCFLAGS', \$ccflags); cmake_set_var('CCFLAGS', \$ccflags);
\$ldflags =~ s/ -L/ -LIBPATH:/g if \$msvc; \$ldflags =~ s/ -L/ -LIBPATH:/g if \$msvc;
cmake_set_var('LDFLAGS', \$ldflags); cmake_set_var('LD', \$Config{ld});
cmake_set_var('LDFLAGS', \$ldflags);
cmake_set_var('CCCDLFLAGS', \$Config{cccdlflags});
cmake_set_var('LDDLFLAGS', \$Config{lddlflags});
cmake_set_var('DLEXT', \$Config{dlext});
close \$fh; close \$fh;
") ")
include(${PerlEmbed_TEMP_INCLUDE}) include(${PerlEmbed_TEMP_INCLUDE})
@ -68,7 +73,9 @@ if (PerlEmbed_DEBUG)
message(STATUS " PERL_EXTRA_C_FLAGS = ${PERL_EXTRA_C_FLAGS}") message(STATUS " PERL_EXTRA_C_FLAGS = ${PERL_EXTRA_C_FLAGS}")
# Second show the configuration extracted by this module (FindPerlEmbed): # Second show the configuration extracted by this module (FindPerlEmbed):
message(STATUS " PerlEmbed_CCFLAGS = ${PerlEmbed_CCFLAGS}") message(STATUS " PerlEmbed_CCFLAGS = ${PerlEmbed_CCFLAGS}")
message(STATUS " LD = ${PerlEmbed_LD}")
message(STATUS " PerlEmbed_LDFLAGS = ${PerlEmbed_LDFLAGS}") message(STATUS " PerlEmbed_LDFLAGS = ${PerlEmbed_LDFLAGS}")
message(STATUS " PerlEmbed_LDDLFLAGS = ${PerlEmbed_LDDLFLAGS}")
endif() endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)

View File

@ -180,7 +180,6 @@ if ($have_boost) {
} }
} }
} }
push @cflags, '-DBOOST_LIBS' if $have_boost;
die <<'EOF' if !$have_boost; die <<'EOF' if !$have_boost;
Slic3r requires the Boost libraries. Please make sure they are installed. Slic3r requires the Boost libraries. Please make sure they are installed.

View File

@ -13,9 +13,10 @@ include_directories(${LIBDIR})
include_directories(${LIBDIR}/libslic3r) include_directories(${LIBDIR}/libslic3r)
#set(CMAKE_INCLUDE_CURRENT_DIR ON) #set(CMAKE_INCLUDE_CURRENT_DIR ON)
if (WIN32) if(WIN32)
add_definitions(-D_USE_MATH_DEFINES -D_WIN32) # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking.
endif () add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -DBOOST_ALL_NO_LIB)
endif()
add_library(libslic3r STATIC add_library(libslic3r STATIC
${LIBDIR}/libslic3r/BoundingBox.cpp ${LIBDIR}/libslic3r/BoundingBox.cpp
@ -255,41 +256,42 @@ add_custom_command(
# Generate the Slic3r Perl module (XS) main.xs file. # Generate the Slic3r Perl module (XS) main.xs file.
set(XS_MAIN_XS ${CMAKE_CURRENT_BINARY_DIR}/main.xs) set(XS_MAIN_XS ${CMAKE_CURRENT_BINARY_DIR}/main.xs)
set(XSP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xsp)
#FIXME list the dependecies explicitely, add dependency on the typemap. #FIXME list the dependecies explicitely, add dependency on the typemap.
file(GLOB XS_XSP_FILES set(XS_XSP_FILES
${LIBDIR}/xsp/BoundingBox.xsp ${XSP_DIR}/BoundingBox.xsp
${LIBDIR}/xsp/BridgeDetector.xsp ${XSP_DIR}/BridgeDetector.xsp
${LIBDIR}/xsp/Clipper.xsp ${XSP_DIR}/Clipper.xsp
${LIBDIR}/xsp/Config.xsp ${XSP_DIR}/Config.xsp
${LIBDIR}/xsp/ExPolygon.xsp ${XSP_DIR}/ExPolygon.xsp
${LIBDIR}/xsp/ExPolygonCollection.xsp ${XSP_DIR}/ExPolygonCollection.xsp
${LIBDIR}/xsp/ExtrusionEntityCollection.xsp ${XSP_DIR}/ExtrusionEntityCollection.xsp
${LIBDIR}/xsp/ExtrusionLoop.xsp ${XSP_DIR}/ExtrusionLoop.xsp
${LIBDIR}/xsp/ExtrusionMultiPath.xsp ${XSP_DIR}/ExtrusionMultiPath.xsp
${LIBDIR}/xsp/ExtrusionPath.xsp ${XSP_DIR}/ExtrusionPath.xsp
${LIBDIR}/xsp/ExtrusionSimulator.xsp ${XSP_DIR}/ExtrusionSimulator.xsp
${LIBDIR}/xsp/Filler.xsp ${XSP_DIR}/Filler.xsp
${LIBDIR}/xsp/Flow.xsp ${XSP_DIR}/Flow.xsp
${LIBDIR}/xsp/GCode.xsp ${XSP_DIR}/GCode.xsp
${LIBDIR}/xsp/GCodeSender.xsp ${XSP_DIR}/GCodeSender.xsp
${LIBDIR}/xsp/Geometry.xsp ${XSP_DIR}/Geometry.xsp
${LIBDIR}/xsp/GUI.xsp ${XSP_DIR}/GUI.xsp
${LIBDIR}/xsp/GUI_3DScene.xsp ${XSP_DIR}/GUI_3DScene.xsp
${LIBDIR}/xsp/Layer.xsp ${XSP_DIR}/Layer.xsp
${LIBDIR}/xsp/Line.xsp ${XSP_DIR}/Line.xsp
${LIBDIR}/xsp/Model.xsp ${XSP_DIR}/Model.xsp
${LIBDIR}/xsp/MotionPlanner.xsp ${XSP_DIR}/MotionPlanner.xsp
${LIBDIR}/xsp/PerimeterGenerator.xsp ${XSP_DIR}/PerimeterGenerator.xsp
${LIBDIR}/xsp/PlaceholderParser.xsp ${XSP_DIR}/PlaceholderParser.xsp
${LIBDIR}/xsp/Point.xsp ${XSP_DIR}/Point.xsp
${LIBDIR}/xsp/Polygon.xsp ${XSP_DIR}/Polygon.xsp
${LIBDIR}/xsp/Polyline.xsp ${XSP_DIR}/Polyline.xsp
${LIBDIR}/xsp/PolylineCollection.xsp ${XSP_DIR}/PolylineCollection.xsp
${LIBDIR}/xsp/Print.xsp ${XSP_DIR}/Print.xsp
${LIBDIR}/xsp/Surface.xsp ${XSP_DIR}/Surface.xsp
${LIBDIR}/xsp/SurfaceCollection.xsp ${XSP_DIR}/SurfaceCollection.xsp
${LIBDIR}/xsp/TriangleMesh.xsp ${XSP_DIR}/TriangleMesh.xsp
${LIBDIR}/xsp/XS.xsp ${XSP_DIR}/XS.xsp
) )
foreach (file ${XS_XSP_FILES}) foreach (file ${XS_XSP_FILES})
if (MSVC) if (MSVC)
@ -306,7 +308,7 @@ configure_file(main.xs.in ${XS_MAIN_XS} @ONLY) # Insert INCLUDE_COMMANDS into ma
set(XS_MAIN_CPP ${CMAKE_CURRENT_BINARY_DIR}/XS.cpp) set(XS_MAIN_CPP ${CMAKE_CURRENT_BINARY_DIR}/XS.cpp)
add_custom_command( add_custom_command(
OUTPUT ${XS_MAIN_CPP} OUTPUT ${XS_MAIN_CPP}
DEPENDS ${MyTypemap} ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt DEPENDS ${MyTypemap} ${XS_XSP_FILES} ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt
COMMAND COMMAND xsubpp -typemap typemap -output ${XS_MAIN_CPP} -hiertype ${XS_MAIN_XS} COMMAND COMMAND xsubpp -typemap typemap -output ${XS_MAIN_CPP} -hiertype ${XS_MAIN_XS}
) )
@ -397,21 +399,24 @@ target_link_libraries(XS ${PERL_LIBRARY})
## REQUIRED packages ## REQUIRED packages
# Find and configure boost # Find and configure boost
if (SLIC3R_STATIC) if(SLIC3R_STATIC)
# Use static boost libraries. # Use static boost libraries.
set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_LIBS ON)
# Use boost libraries linked statically to the C++ runtime. # Use boost libraries linked statically to the C++ runtime.
# set(Boost_USE_STATIC_RUNTIME ON) # set(Boost_USE_STATIC_RUNTIME ON)
endif () endif()
find_package(Boost REQUIRED COMPONENTS system filesystem thread log locale) find_package(Boost REQUIRED COMPONENTS system filesystem thread log locale)
if (Boost_FOUND) if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(XS ${Boost_LIBRARIES}) target_link_libraries(XS ${Boost_LIBRARIES})
target_compile_definitions(XS PRIVATE -DBOOST_ASIO_DISABLE_KQUEUE -DBOOST_LIBS -DBOOST_ALL_NO_LIB) if (APPLE)
if (NOT SLIC3R_STATIC) # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339
target_compile_definitions(XS PRIVATE -DBOOST_LOG_DYN_LINK) add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
endif () endif()
endif () if(NOT SLIC3R_STATIC)
add_definitions(-DBOOST_LOG_DYN_LINK)
endif()
endif()
# Find and configure intel-tbb # Find and configure intel-tbb
if(SLIC3R_STATIC) if(SLIC3R_STATIC)
@ -436,12 +441,12 @@ if (SLIC3R_PRUSACONTROL)
include_directories(${AlienWx_INCLUDE_DIRS}) include_directories(${AlienWx_INCLUDE_DIRS})
#add_compile_options(${AlienWx_CXX_FLAGS}) #add_compile_options(${AlienWx_CXX_FLAGS})
add_definitions(${AlienWx_DEFINITIONS}) add_definitions(${AlienWx_DEFINITIONS})
set(wxWidgets_LIBRARIES, ${AlienWx_LIBRARIES}) set(wxWidgets_LIBRARIES ${AlienWx_LIBRARIES})
else () else ()
find_package(wxWidgets REQUIRED COMPONENTS base) find_package(wxWidgets REQUIRED COMPONENTS base)
include(${wxWidgets_USE_FILE}) include(${wxWidgets_USE_FILE})
endif () endif ()
target_compile_definitions(XS PRIVATE -DSLIC3R_GUI -DSLIC3R_PRUS) add_definitions(-DSLIC3R_GUI -DSLIC3R_PRUS)
target_link_libraries(XS ${wxWidgets_LIBRARIES}) target_link_libraries(XS ${wxWidgets_LIBRARIES})
endif() endif()
@ -484,8 +489,7 @@ if (NOT GLEW_FOUND)
set(GLEW_FOUND 1) set(GLEW_FOUND 1)
set(GLEW_INCLUDE_DIRS ${LIBDIR}/glew/include/) set(GLEW_INCLUDE_DIRS ${LIBDIR}/glew/include/)
set(GLEW_LIBRARIES glew) set(GLEW_LIBRARIES glew)
target_compile_definitions(glew PRIVATE -DGLEW_STATIC) add_definitions(-DGLEW_STATIC)
target_compile_definitions(XS PRIVATE -DGLEW_STATIC)
endif () endif ()
include_directories(${GLEW_INCLUDE_DIRS}) include_directories(${GLEW_INCLUDE_DIRS})
target_link_libraries(XS ${GLEW_LIBRARIES}) target_link_libraries(XS ${GLEW_LIBRARIES})
@ -498,10 +502,6 @@ target_link_libraries(slic3r libslic3r libslic3r_gui admesh ${Boost_LIBRARIES} c
if(SLIC3R_DEBUG) if(SLIC3R_DEBUG)
target_link_libraries(Shiny) target_link_libraries(Shiny)
endif() endif()
target_compile_definitions(slic3r PRIVATE -DBOOST_ASIO_DISABLE_KQUEUE -DBOOST_LIBS -DBOOST_ALL_NO_LIB)
if(NOT SLIC3R_STATIC)
target_compile_definitions(slic3r PRIVATE -DBOOST_LOG_DYN_LINK)
endif()
if (APPLE) if (APPLE)
target_link_libraries(slic3r "-framework IOKit" "-framework CoreFoundation" -lc++) target_link_libraries(slic3r "-framework IOKit" "-framework CoreFoundation" -lc++)
elseif (NOT MSVC) elseif (NOT MSVC)

View File

@ -610,7 +610,7 @@ static bool prepare_infill_hatching_segments(
#undef ASSERT_OR_RETURN #undef ASSERT_OR_RETURN
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#endif _MSC_VER #endif /* _MSC_VER */
#ifdef SLIC3R_DEBUG #ifdef SLIC3R_DEBUG
// Paint the segments and finalize the SVG file. // Paint the segments and finalize the SVG file.

View File

@ -344,7 +344,7 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::tool_change(int tool, bool last_in
{ {
// Either it is the last tool unload, // Either it is the last tool unload,
// or there must be a nonzero wipe tower partitions available. // or there must be a nonzero wipe tower partitions available.
assert(tool < 0 || it_layer_tools->wipe_tower_partitions > 0); // assert(tool < 0 || it_layer_tools->wipe_tower_partitions > 0);
if (m_idx_tool_change_in_layer == (unsigned int)(-1)) { if (m_idx_tool_change_in_layer == (unsigned int)(-1)) {
// First layer, prime the extruder. // First layer, prime the extruder.

View File

@ -1,4 +1,3 @@
#ifdef BOOST_LIBS
#include "GCodeSender.hpp" #include "GCodeSender.hpp"
#include <iostream> #include <iostream>
#include <istream> #include <istream>
@ -30,8 +29,6 @@ std::fstream fs;
namespace Slic3r { namespace Slic3r {
namespace asio = boost::asio;
GCodeSender::GCodeSender() GCodeSender::GCodeSender()
: io(), serial(io), can_send(false), sent(0), open(false), error(false), : io(), serial(io), can_send(false), sent(0), open(false), error(false),
connected(false), queue_paused(false) connected(false), queue_paused(false)
@ -50,20 +47,20 @@ GCodeSender::connect(std::string devname, unsigned int baud_rate)
this->set_error_status(false); this->set_error_status(false);
try { try {
this->serial.open(devname); this->serial.open(devname);
} catch (boost::system::system_error &e) { } catch (boost::system::system_error &) {
this->set_error_status(true); this->set_error_status(true);
return false; return false;
} }
this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::odd)); this->serial.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::odd));
this->serial.set_option(asio::serial_port_base::character_size(asio::serial_port_base::character_size(8))); this->serial.set_option(boost::asio::serial_port_base::character_size(boost::asio::serial_port_base::character_size(8)));
this->serial.set_option(asio::serial_port_base::flow_control(asio::serial_port_base::flow_control::none)); this->serial.set_option(boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none));
this->serial.set_option(asio::serial_port_base::stop_bits(asio::serial_port_base::stop_bits::one)); this->serial.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));
this->set_baud_rate(baud_rate); this->set_baud_rate(baud_rate);
this->serial.close(); this->serial.close();
this->serial.open(devname); this->serial.open(devname);
this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::none)); this->serial.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none));
// set baud rate again because set_option overwrote it // set baud rate again because set_option overwrote it
this->set_baud_rate(baud_rate); this->set_baud_rate(baud_rate);
@ -84,7 +81,7 @@ GCodeSender::connect(std::string devname, unsigned int baud_rate)
this->io.post(boost::bind(&GCodeSender::do_read, this)); this->io.post(boost::bind(&GCodeSender::do_read, this));
// start reading in the background thread // start reading in the background thread
boost::thread t(boost::bind(&asio::io_service::run, &this->io)); boost::thread t(boost::bind(&boost::asio::io_service::run, &this->io));
this->background_thread.swap(t); this->background_thread.swap(t);
return true; return true;
@ -95,8 +92,8 @@ GCodeSender::set_baud_rate(unsigned int baud_rate)
{ {
try { try {
// This does not support speeds > 115200 // This does not support speeds > 115200
this->serial.set_option(asio::serial_port_base::baud_rate(baud_rate)); this->serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate));
} catch (boost::system::system_error &e) { } catch (boost::system::system_error &) {
boost::asio::serial_port::native_handle_type handle = this->serial.native_handle(); boost::asio::serial_port::native_handle_type handle = this->serial.native_handle();
#if __APPLE__ #if __APPLE__
@ -276,15 +273,15 @@ void
GCodeSender::do_read() GCodeSender::do_read()
{ {
// read one line // read one line
asio::async_read_until( boost::asio::async_read_until(
this->serial, this->serial,
this->read_buffer, this->read_buffer,
'\n', '\n',
boost::bind( boost::bind(
&GCodeSender::on_read, &GCodeSender::on_read,
this, this,
asio::placeholders::error, boost::asio::placeholders::error,
asio::placeholders::bytes_transferred boost::asio::placeholders::bytes_transferred
) )
); );
} }
@ -483,11 +480,11 @@ GCodeSender::do_send()
if (this->last_sent.size() > KEEP_SENT) if (this->last_sent.size() > KEEP_SENT)
this->last_sent.erase(this->last_sent.begin(), this->last_sent.end() - KEEP_SENT); this->last_sent.erase(this->last_sent.begin(), this->last_sent.end() - KEEP_SENT);
// we can't supply asio::buffer(full_line) to async_write() because full_line is on the // we can't supply boost::asio::buffer(full_line) to async_write() because full_line is on the
// stack and the buffer would lose its underlying storage causing memory corruption // stack and the buffer would lose its underlying storage causing memory corruption
std::ostream os(&this->write_buffer); std::ostream os(&this->write_buffer);
os << full_line; os << full_line;
asio::async_write(this->serial, this->write_buffer, boost::bind(&GCodeSender::on_write, this, boost::asio::placeholders::error, boost::asio::async_write(this->serial, this->write_buffer, boost::bind(&GCodeSender::on_write, this, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)); boost::asio::placeholders::bytes_transferred));
} }
@ -511,7 +508,7 @@ void
GCodeSender::set_DTR(bool on) GCodeSender::set_DTR(bool on)
{ {
#if defined(_WIN32) && !defined(__SYMBIAN32__) #if defined(_WIN32) && !defined(__SYMBIAN32__)
asio::serial_port_service::native_handle_type handle = this->serial.native_handle(); boost::asio::serial_port_service::native_handle_type handle = this->serial.native_handle();
if (on) if (on)
EscapeCommFunction(handle, SETDTR); EscapeCommFunction(handle, SETDTR);
else else
@ -543,6 +540,4 @@ GCodeSender::reset()
} }
} }
} } // namespace Slic3r
#endif

View File

@ -1,6 +1,5 @@
#ifndef slic3r_GCodeSender_hpp_ #ifndef slic3r_GCodeSender_hpp_
#define slic3r_GCodeSender_hpp_ #define slic3r_GCodeSender_hpp_
#ifdef BOOST_LIBS
#include "libslic3r.h" #include "libslic3r.h"
#include <queue> #include <queue>
@ -71,5 +70,4 @@ class GCodeSender : private boost::noncopyable {
} // namespace Slic3r } // namespace Slic3r
#endif /* BOOST_LIBS */
#endif /* slic3r_GCodeSender_hpp_ */ #endif /* slic3r_GCodeSender_hpp_ */

View File

@ -1,7 +1,5 @@
%module{Slic3r::XS}; %module{Slic3r::XS};
#ifdef BOOST_LIBS
%{ %{
#include <xsinit.h> #include <xsinit.h>
#include "libslic3r/GCodeSender.hpp" #include "libslic3r/GCodeSender.hpp"
@ -24,5 +22,3 @@
std::string getT(); std::string getT();
std::string getB(); std::string getB();
}; };
#endif