Fix cgal when used from distro package

fix CMake -frounding-math propagation from CGAL.
This commit is contained in:
tamasmeszaros 2020-01-28 14:49:07 +01:00
parent 69549af9ac
commit 04a58e41c4
2 changed files with 20 additions and 13 deletions

View file

@ -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) set(_cgal_defines CGAL_DO_NOT_USE_MPZF)
endif () endif ()
add_library(libslic3r_cgal OBJECT MeshBoolean.cpp MeshBoolean.hpp) add_library(libslic3r_cgal STATIC MeshBoolean.cpp MeshBoolean.hpp)
target_include_directories(libslic3r_cgal PRIVATE target_include_directories(libslic3r_cgal PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
${CMAKE_CURRENT_BINARY_DIR}
$<TARGET_PROPERTY:libigl,INTERFACE_INCLUDE_DIRECTORIES> # Reset compile options of libslic3r_cgal. Despite it being linked privately, CGAL options
$<TARGET_PROPERTY:CGAL::CGAL,INTERFACE_INCLUDE_DIRECTORIES>) # (-frounding-math) still propagate to dependent libs which is not desired.
target_compile_definitions(libslic3r_cgal PRIVATE ${_cgal_defines} get_target_property(_cgal_tgt CGAL::CGAL ALIASED_TARGET)
$<TARGET_PROPERTY:CGAL::CGAL,INTERFACE_COMPILE_DEFINITIONS>) if (NOT TARGET ${_cgal_tgt})
target_compile_options(libslic3r_cgal PRIVATE set (_cgal_tgt CGAL::CGAL)
$<TARGET_PROPERTY:CGAL::CGAL,INTERFACE_COMPILE_OPTIONS>) 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) encoding_check(libslic3r)
@ -268,7 +277,7 @@ target_link_libraries(libslic3r
qhull qhull
semver semver
TBB::tbb TBB::tbb
$<TARGET_PROPERTY:CGAL::CGAL,INTERFACE_LINK_LIBRARIES> libslic3r_cgal
${CMAKE_DL_LIBS} ${CMAKE_DL_LIBS}
) )
@ -287,5 +296,3 @@ endif()
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE)
endif () endif ()
target_sources(libslic3r PRIVATE $<TARGET_OBJECTS:libslic3r_cgal>)

View file

@ -111,7 +111,7 @@ static TriangleMesh cgal_to_triangle_mesh(const _CGALMesh &cgalmesh)
auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face)); auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face));
int i = 0; int i = 0;
Vec3crd trface; Vec3crd trface;
for (auto v : vtc) trface(i++) = int(v.idx()); for (auto v : vtc) trface(i++) = static_cast<unsigned>(v);
facets.emplace_back(trface); facets.emplace_back(trface);
} }