diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 572090157..d07c8d1e8 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -84,6 +84,7 @@ if (MSVC) dep_wxwidgets dep_gtest dep_nlopt + dep_qhull dep_zlib # on Windows we still need zlib ) @@ -97,6 +98,7 @@ else() dep_wxwidgets dep_gtest dep_nlopt + dep_qhull ) endif() diff --git a/deps/deps-unix-common.cmake b/deps/deps-unix-common.cmake index 3cf843f73..d6a92efcb 100644 --- a/deps/deps-unix-common.cmake +++ b/deps/deps-unix-common.cmake @@ -32,3 +32,16 @@ ExternalProject_Add(dep_nlopt -DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local ${DEP_CMAKE_OPTS} ) + +find_package(Git REQUIRED) + +ExternalProject_Add(dep_qhull + EXCLUDE_FROM_ALL 1 + URL "https://github.com/qhull/qhull/archive/v7.2.1.tar.gz" + URL_HASH SHA256=6fc251e0b75467e00943bfb7191e986fce0e1f8f6f0251f9c6ce5a843821ea78 + CMAKE_ARGS + -DBUILD_SHARED_LIBS=OFF + -DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local + ${DEP_CMAKE_OPTS} + PATCH_COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/qhull-mods.patch +) diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index b3b31e5f3..df47a0f44 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -199,6 +199,33 @@ if (${DEP_DEBUG}) ) endif () +find_package(Git REQUIRED) + +ExternalProject_Add(dep_qhull + EXCLUDE_FROM_ALL 1 + URL "https://github.com/qhull/qhull/archive/v7.2.1.tar.gz" + URL_HASH SHA256=6fc251e0b75467e00943bfb7191e986fce0e1f8f6f0251f9c6ce5a843821ea78 + CMAKE_GENERATOR "${DEP_MSVC_GEN}" + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local + -DBUILD_SHARED_LIBS=OFF + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_DEBUG_POSTFIX=d + PATCH_COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/qhull-mods.patch + BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj + INSTALL_COMMAND "" +) + +if (${DEP_DEBUG}) + ExternalProject_Get_Property(dep_qhull BINARY_DIR) + ExternalProject_Add_Step(dep_qhull build_debug + DEPENDEES build + DEPENDERS install + COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj + WORKING_DIRECTORY "${BINARY_DIR}" + ) +endif () + if (${DEPS_BITS} EQUAL 32) set(DEP_WXWIDGETS_TARGET "") diff --git a/deps/qhull-mods.patch b/deps/qhull-mods.patch new file mode 100644 index 000000000..b1ea7159b --- /dev/null +++ b/deps/qhull-mods.patch @@ -0,0 +1,85 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 59dff41..20c2ec5 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -61,7 +61,7 @@ + # $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $ + + project(qhull) +-cmake_minimum_required(VERSION 2.6) ++cmake_minimum_required(VERSION 3.0) + + # Define qhull_VERSION in CMakeLists.txt, Makefile, qhull-exports.def, qhull_p-exports.def, qhull_r-exports.def, qhull-warn.pri + set(qhull_VERSION2 "2015.2 2016/01/18") # not used, See global.c, global_r.c, rbox.c, rbox_r.c +@@ -610,10 +610,48 @@ add_test(NAME user_eg3 + # Define install + # --------------------------------------- + +-install(TARGETS ${qhull_TARGETS_INSTALL} ++install(TARGETS ${qhull_TARGETS_INSTALL} EXPORT QhullTargets + RUNTIME DESTINATION ${BIN_INSTALL_DIR} + LIBRARY DESTINATION ${LIB_INSTALL_DIR} +- ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) ++ ARCHIVE DESTINATION ${LIB_INSTALL_DIR} ++ INCLUDES DESTINATION include) ++ ++include(CMakePackageConfigHelpers) ++ ++write_basic_package_version_file( ++ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfigVersion.cmake" ++ VERSION ${qhull_VERSION} ++ COMPATIBILITY AnyNewerVersion ++) ++ ++export(EXPORT QhullTargets ++ FILE "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullTargets.cmake" ++ NAMESPACE Qhull:: ++) ++ ++configure_file(Config.cmake.in ++ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfig.cmake" ++ @ONLY ++) ++ ++set(ConfigPackageLocation lib/cmake/Qhull) ++install(EXPORT QhullTargets ++ FILE ++ QhullTargets.cmake ++ NAMESPACE ++ Qhull:: ++ DESTINATION ++ ${ConfigPackageLocation} ++) ++install( ++ FILES ++ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfig.cmake" ++ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfigVersion.cmake" ++ DESTINATION ++ ${ConfigPackageLocation} ++ COMPONENT ++ Devel ++) + + install(FILES ${libqhull_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/libqhull) + install(FILES ${libqhull_DOC} DESTINATION ${INCLUDE_INSTALL_DIR}/libqhull) +diff --git a/Config.cmake.in b/Config.cmake.in +new file mode 100644 +index 0000000..bc92bfe +--- /dev/null ++++ b/Config.cmake.in +@@ -0,0 +1,2 @@ ++include("${CMAKE_CURRENT_LIST_DIR}/QhullTargets.cmake") ++ +diff --git a/src/libqhull_r/user_r.h b/src/libqhull_r/user_r.h +index fc105b9..7cca65a 100644 +--- a/src/libqhull_r/user_r.h ++++ b/src/libqhull_r/user_r.h +@@ -139,7 +139,7 @@ Code flags -- + REALfloat = 1 all numbers are 'float' type + = 0 all numbers are 'double' type + */ +-#define REALfloat 0 ++#define REALfloat 1 + + #if (REALfloat == 1) + #define realT float diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f6959623..2f2483eca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,9 +17,6 @@ add_subdirectory(semver) set(LIBNEST2D_UNITTESTS ON CACHE BOOL "Force generating unittests for libnest2d") add_subdirectory(libnest2d) -include_directories(${LIBDIR}/qhull/src) -#message(STATUS ${LIBDIR}/qhull/src) - add_subdirectory(libslic3r) if (SLIC3R_GUI) diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 4d35cabca..6581a8320 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -578,7 +578,7 @@ TriangleMesh TriangleMesh::convex_hull_3d() const { // iterate through facet's vertices orgQhull::QhullPoint p = vertices[i].point(); - const float* coords = p.coordinates(); + const auto* coords = p.coordinates(); dst_vertices.emplace_back(coords[0], coords[1], coords[2]); } unsigned int size = (unsigned int)dst_vertices.size(); diff --git a/src/qhull/CMakeLists.txt b/src/qhull/CMakeLists.txt index a3e7da126..262214a5c 100644 --- a/src/qhull/CMakeLists.txt +++ b/src/qhull/CMakeLists.txt @@ -8,6 +8,22 @@ # Created by modification of the original qhull CMakeLists. # Lukas Matena (25.7.2018), lukasmatena@seznam.cz +# see bug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=925540 + +# find_package(Qhull 7.2 QUIET) + +add_library(qhull INTERFACE) + +if(Qhull_FOUND) + +message(STATUS "Using qhull from system.") +if(SLICER_STATIC) + target_link_libraries(qhull INTERFACE Qhull::qhullcpp Qhull::qhullstatic_r) +else() + target_link_libraries(qhull INTERFACE Qhull::qhullcpp Qhull::qhull_r) +endif() + +else(Qhull_FOUND) project(qhull) cmake_minimum_required(VERSION 2.6) @@ -112,7 +128,7 @@ set(libqhull_SOURCES ################################################## # combined library (reentrant qhull and qhullcpp) for Slic3r: -set(qhull_STATIC qhull) +set(qhull_STATIC qhullstatic) add_library(${qhull_STATIC} STATIC ${libqhull_SOURCES}) set_target_properties(${qhull_STATIC} PROPERTIES VERSION ${qhull_VERSION}) @@ -124,3 +140,8 @@ endif(UNIX) # LIBDIR is defined in the main xs CMake file: target_include_directories(${qhull_STATIC} PRIVATE ${LIBDIR}/qhull/src) + +target_link_libraries(qhull INTERFACE ${qhull_STATIC}) +target_include_directories(qhull INTERFACE ${LIBDIR}/qhull/src) + +endif()