From 04a58e41c437f39d95d52aef0ef161a7c76fbd87 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 28 Jan 2020 14:49:07 +0100 Subject: [PATCH] Fix cgal when used from distro package fix CMake -frounding-math propagation from CGAL. --- src/libslic3r/CMakeLists.txt | 31 +++++++++++++++++++------------ src/libslic3r/MeshBoolean.cpp | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 0bad50abe..0f8f5b2c2 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -238,15 +238,24 @@ if (MSVC AND "${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") # 32 bit MSVC workaround set(_cgal_defines CGAL_DO_NOT_USE_MPZF) endif () -add_library(libslic3r_cgal OBJECT MeshBoolean.cpp MeshBoolean.hpp) -target_include_directories(libslic3r_cgal PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} - $ - $) -target_compile_definitions(libslic3r_cgal PRIVATE ${_cgal_defines} - $) -target_compile_options(libslic3r_cgal PRIVATE - $) +add_library(libslic3r_cgal STATIC MeshBoolean.cpp MeshBoolean.hpp) +target_include_directories(libslic3r_cgal PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +# Reset compile options of libslic3r_cgal. Despite it being linked privately, CGAL options +# (-frounding-math) still propagate to dependent libs which is not desired. +get_target_property(_cgal_tgt CGAL::CGAL ALIASED_TARGET) +if (NOT TARGET ${_cgal_tgt}) + set (_cgal_tgt CGAL::CGAL) +endif () +get_target_property(_opts ${_cgal_tgt} INTERFACE_COMPILE_OPTIONS) +set(_opts_bad "${_opts}") +set(_opts_good "${_opts}") +list(FILTER _opts_bad INCLUDE REGEX frounding-math) +list(FILTER _opts_good EXCLUDE REGEX frounding-math) +set_target_properties(${_cgal_tgt} PROPERTIES INTERFACE_COMPILE_OPTIONS "${_opts_good}") + +target_link_libraries(libslic3r_cgal PRIVATE ${_cgal_tgt} libigl) +target_compile_options(libslic3r_cgal PRIVATE "${_opts_bad}") encoding_check(libslic3r) @@ -268,7 +277,7 @@ target_link_libraries(libslic3r qhull semver TBB::tbb - $ + libslic3r_cgal ${CMAKE_DL_LIBS} ) @@ -287,5 +296,3 @@ endif() if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) endif () - -target_sources(libslic3r PRIVATE $) diff --git a/src/libslic3r/MeshBoolean.cpp b/src/libslic3r/MeshBoolean.cpp index 69db96d3f..025f2f97d 100644 --- a/src/libslic3r/MeshBoolean.cpp +++ b/src/libslic3r/MeshBoolean.cpp @@ -111,7 +111,7 @@ static TriangleMesh cgal_to_triangle_mesh(const _CGALMesh &cgalmesh) auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face)); int i = 0; Vec3crd trface; - for (auto v : vtc) trface(i++) = int(v.idx()); + for (auto v : vtc) trface(i++) = static_cast(v); facets.emplace_back(trface); }