编译CGAL

抛弃CMake
长期以来,我一直以为编译CGAL是一项十分艰巨的任务。直到有一天,我决定彻底抛弃繁复的CMake,转而使用简简单单的QMake。这才发现,编译CGAL是如此简单的一个事儿。

注:本文所指的CGAL是指CGAL4.14及之后的版本。

理解CGAL编译依赖
CGAL百分之九十九都是头文件,无需编译,只有1%的内容需要编译。而使用C++17编译时,CGAL只依赖Boost头文件。没错,只需要Boost文件,不需要编译Boost。而那些什么GMP啦,什么MPFR啦,什么Qt啦,编译CGAL的时候是不需要的,只有当使用CGAL的时候才需要。

读者只需要下载并解压缩CGAL源代码到一个不包含空格和非ASCII码的目录,我们姑且叫它[CGAL_ROOT];

在[CGAL_ROOT]目录下建立一个目录,比如叫做“CGAL_CONFIG/CGAL”;

建立文件“CGAL_CONFIG/CGAL/version.h”并键入内容:

#ifndef CGAL_VERSION_H
#define CGAL_VERSION_H

#define CGAL_VERSION 4.14-I-900
#define CGAL_VERSION_NR 1041400900
#define CGAL_SVN_REVISION 99999

#define CGAL_RELEASE_DATE 20190701

#include <CGAL/version_macros.h>

#endif

建立文件“CGAL_CONFIG/CGAL/compiler_config.h”并键入内容:

#if defined(_MSC_VER)
    #define CGAL_CFG_FPU_ROUNDING_MODE_UNWINDING_VC_BUG 1
    #define CGAL_CFG_MATCHING_BUG_6 1
#endif

#define CGAL_USE_GMP 1
#define CGAL_USE_MPFR 1
#define CGAL_BUILD_SHARED_LIBS 1

新建一个文件“[CGAL_ROOT]/build_all.cpp”并键入内容:

#include "Geomview/src/CGAL/Geomview_stream.cpp"
#include "Intersections_2/src/CGAL/Bbox_2_intersections.cpp"
#include "Kernel_23/src/CGAL/kernel.cpp"
#include "Number_types/src/CGAL/Interval_arithmetic.cpp"
#include "Number_types/src/CGAL/test_FPU_rounding_mode.cpp"
#include "Profiling_tools/src/CGAL/Real_timer.cpp"
#include "Profiling_tools/src/CGAL/Timer.cpp"
#include "Random_numbers/src/CGAL/Random.cpp"
#include "STL_Extension/src/CGAL/assertions.cpp"
#include "Stream_support/src/CGAL/Color.cpp"
#include "Stream_support/src/CGAL/File_header_OFF.cpp"
#include "Stream_support/src/CGAL/File_header_extended_OFF.cpp"
#include "Stream_support/src/CGAL/File_scanner_OFF.cpp"
#include "Stream_support/src/CGAL/File_writer_OFF.cpp"
#include "Stream_support/src/CGAL/File_writer_VRML_2.cpp"
#include "Stream_support/src/CGAL/File_writer_inventor.cpp"
#include "Stream_support/src/CGAL/File_writer_wavefront.cpp"
#include "Stream_support/src/CGAL/io.cpp"

没错,只需要编译“build_all.cpp”这么一个文件就行了,编译时顺便多定义一个宏“CGAL_EXPORTS”。其它根本什么都不需要。

比如,读者建立一个文件“[CGAL_ROOT]/build_cgal.pro”并键入内容:

TEMPLATE = lib
TARGET   = mycgal
 
DEFINES      *= CGAL_EXPORTS
INCLUDEPATH += $$PWD/CGAL_CONFIG
INCLUDEPATH += C:/boost/boost_1_70_0
SOURCES     += $$PWD/build_all.cpp
 
INCLUDEPATH += $$PWD/AABB_tree/include
INCLUDEPATH += $$PWD/AABB_tree/include
INCLUDEPATH += $$PWD/Advancing_front_surface_reconstruction/include
INCLUDEPATH += $$PWD/Algebraic_foundations/include
INCLUDEPATH += $$PWD/Algebraic_kernel_d/include
INCLUDEPATH += $$PWD/Algebraic_kernel_for_circles/include
INCLUDEPATH += $$PWD/Algebraic_kernel_for_spheres/include
INCLUDEPATH += $$PWD/Alpha_shapes_2/include
INCLUDEPATH += $$PWD/Alpha_shapes_3/include
INCLUDEPATH += $$PWD/Apollonius_graph_2/include
INCLUDEPATH += $$PWD/Arithmetic_kernel/include
INCLUDEPATH += $$PWD/Arrangement_on_surface_2/include
INCLUDEPATH += $$PWD/Barycentric_coordinates_2/include
INCLUDEPATH += $$PWD/BGL/include
INCLUDEPATH += $$PWD/Boolean_set_operations_2/include
INCLUDEPATH += $$PWD/Bounding_volumes/include
INCLUDEPATH += $$PWD/Box_intersection_d/include
INCLUDEPATH += $$PWD/Cartesian_kernel/include
INCLUDEPATH += $$PWD/CGAL_Core/include
INCLUDEPATH += $$PWD/CGAL_ImageIO/include
INCLUDEPATH += $$PWD/CGAL_ipelets/include
INCLUDEPATH += $$PWD/Circular_kernel_2/include
INCLUDEPATH += $$PWD/Circular_kernel_3/include
INCLUDEPATH += $$PWD/Circulator/include
INCLUDEPATH += $$PWD/Classification/include
INCLUDEPATH += $$PWD/Combinatorial_map/include
INCLUDEPATH += $$PWD/Cone_spanners_2/include
INCLUDEPATH += $$PWD/Convex_decomposition_3/include
INCLUDEPATH += $$PWD/Convex_hull_2/include
INCLUDEPATH += $$PWD/Convex_hull_3/include
INCLUDEPATH += $$PWD/Convex_hull_d/include
INCLUDEPATH += $$PWD/Distance_2/include
INCLUDEPATH += $$PWD/Distance_3/include
INCLUDEPATH += $$PWD/Envelope_2/include
INCLUDEPATH += $$PWD/Envelope_3/include
INCLUDEPATH += $$PWD/Filtered_kernel/include
INCLUDEPATH += $$PWD/Generalized_map/include
INCLUDEPATH += $$PWD/Generator/include
INCLUDEPATH += $$PWD/Geomview/include
INCLUDEPATH += $$PWD/GraphicsView/include
INCLUDEPATH += $$PWD/HalfedgeDS/include
INCLUDEPATH += $$PWD/Hash_map/include
INCLUDEPATH += $$PWD/Heat_method_3/include
INCLUDEPATH += $$PWD/Homogeneous_kernel/include
INCLUDEPATH += $$PWD/Hyperbolic_triangulation_2/include
INCLUDEPATH += $$PWD/Inscribed_areas/include
INCLUDEPATH += $$PWD/Installation/include
INCLUDEPATH += $$PWD/Interpolation/include
INCLUDEPATH += $$PWD/Intersections_2/include
INCLUDEPATH += $$PWD/Intersections_3/include
INCLUDEPATH += $$PWD/Interval_skip_list/include
INCLUDEPATH += $$PWD/Interval_support/include
INCLUDEPATH += $$PWD/Inventor/include
INCLUDEPATH += $$PWD/Jet_fitting_3/include
INCLUDEPATH += $$PWD/Kernel_23/include
INCLUDEPATH += $$PWD/Kernel_d/include
INCLUDEPATH += $$PWD/LEDA/include
INCLUDEPATH += $$PWD/Linear_cell_complex/include
INCLUDEPATH += $$PWD/Matrix_search/include
INCLUDEPATH += $$PWD/Mesher_level/include
INCLUDEPATH += $$PWD/Mesh_2/include
INCLUDEPATH += $$PWD/Mesh_3/include
INCLUDEPATH += $$PWD/Minkowski_sum_2/include
INCLUDEPATH += $$PWD/Minkowski_sum_3/include
INCLUDEPATH += $$PWD/Modifier/include
INCLUDEPATH += $$PWD/Modular_arithmetic/include
INCLUDEPATH += $$PWD/Nef_2/include
INCLUDEPATH += $$PWD/Nef_3/include
INCLUDEPATH += $$PWD/Nef_S2/include
INCLUDEPATH += $$PWD/NewKernel_d/include
INCLUDEPATH += $$PWD/Number_types/include
INCLUDEPATH += $$PWD/OpenNL/include
INCLUDEPATH += $$PWD/Optimal_transportation_reconstruction_2/include
INCLUDEPATH += $$PWD/Optimisation_basic/include
INCLUDEPATH += $$PWD/Partition_2/include
INCLUDEPATH += $$PWD/Periodic_2_triangulation_2/include
INCLUDEPATH += $$PWD/Periodic_3_mesh_3/include
INCLUDEPATH += $$PWD/Periodic_3_triangulation_3/include
INCLUDEPATH += $$PWD/Periodic_4_hyperbolic_triangulation_2/include
INCLUDEPATH += $$PWD/Point_set_2/include
INCLUDEPATH += $$PWD/Point_set_3/include
INCLUDEPATH += $$PWD/Point_set_processing_3/include
INCLUDEPATH += $$PWD/Point_set_shape_detection_3/include
INCLUDEPATH += $$PWD/Poisson_surface_reconstruction_3/include
INCLUDEPATH += $$PWD/Polygon/include
INCLUDEPATH += $$PWD/Polygon_mesh_processing/include
INCLUDEPATH += $$PWD/Polyhedron/include
INCLUDEPATH += $$PWD/Polyhedron_IO/include
INCLUDEPATH += $$PWD/Polyline_simplification_2/include
INCLUDEPATH += $$PWD/Polynomial/include
INCLUDEPATH += $$PWD/Polytope_distance_d/include
INCLUDEPATH += $$PWD/Principal_component_analysis/include
INCLUDEPATH += $$PWD/Principal_component_analysis_LGPL/include
INCLUDEPATH += $$PWD/Profiling_tools/include
INCLUDEPATH += $$PWD/Property_map/include
INCLUDEPATH += $$PWD/QP_solver/include
INCLUDEPATH += $$PWD/Random_numbers/include
INCLUDEPATH += $$PWD/Ridges_3/include
INCLUDEPATH += $$PWD/Scale_space_reconstruction_3/include
INCLUDEPATH += $$PWD/SearchStructures/include
INCLUDEPATH += $$PWD/Segment_Delaunay_graph_2/include
INCLUDEPATH += $$PWD/Segment_Delaunay_graph_Linf_2/include
INCLUDEPATH += $$PWD/Set_movable_separability_2/include
INCLUDEPATH += $$PWD/Skin_surface_3/include
INCLUDEPATH += $$PWD/Snap_rounding_2/include
INCLUDEPATH += $$PWD/Solver_interface/include
INCLUDEPATH += $$PWD/Spatial_searching/include
INCLUDEPATH += $$PWD/Spatial_sorting/include
INCLUDEPATH += $$PWD/STL_Extension/include
INCLUDEPATH += $$PWD/Straight_skeleton_2/include
INCLUDEPATH += $$PWD/Stream_lines_2/include
INCLUDEPATH += $$PWD/Stream_support/include
INCLUDEPATH += $$PWD/Subdivision_method_3/include
INCLUDEPATH += $$PWD/Surface_mesh/include
INCLUDEPATH += $$PWD/Surface_mesher/include
INCLUDEPATH += $$PWD/Surface_mesh_approximation/include
INCLUDEPATH += $$PWD/Surface_mesh_deformation/include
INCLUDEPATH += $$PWD/Surface_mesh_parameterization/include
INCLUDEPATH += $$PWD/Surface_mesh_segmentation/include
INCLUDEPATH += $$PWD/Surface_mesh_shortest_path/include
INCLUDEPATH += $$PWD/Surface_mesh_simplification/include
INCLUDEPATH += $$PWD/Surface_mesh_skeletonization/include
INCLUDEPATH += $$PWD/Surface_sweep_2/include
INCLUDEPATH += $$PWD/TDS_2/include
INCLUDEPATH += $$PWD/TDS_3/include
INCLUDEPATH += $$PWD/Testsuite/include
INCLUDEPATH += $$PWD/Three/include
INCLUDEPATH += $$PWD/Triangulation/include
INCLUDEPATH += $$PWD/Triangulation_2/include
INCLUDEPATH += $$PWD/Triangulation_3/include
INCLUDEPATH += $$PWD/Union_find/include
INCLUDEPATH += $$PWD/Visibility_2/include
INCLUDEPATH += $$PWD/Voronoi_diagram_2/include

然后,读者用QtCreator打开并编译,CGAL就编译完成。

使用CGAL
使用CGAL只需要多定义一个宏“CGAL_NO_AUTOLINK”,去掉编译期的宏“CGAL_EXPORTS”,即可。好了,给个例子吧。

TEMPLATE = app
TARGET   = test_cgal

LIBS += -L"<MYCGAL PATH>" -lmycgal
LIBS += -L"<GMP PATH>" -lgmp
LIBS += -L"<MPFR PATH>" -lmpfr
LIBS += -L"<BOOST PATH>" –lboost_thread
LIBS += -L"<BOOST PATH>" –lboost_system

SOURCES     += $$PWD/test_main.cpp

DEFINES      *= CGAL_NO_AUTOLINK
INCLUDEPATH += $$PWD/CGAL_CONFIG
INCLUDEPATH += C:/boost/boost_1_70_0

INCLUDEPATH += $$PWD/AABB_tree/include

……
虽然例子里面要求导入GMP,MPFR以及Boost Thread和Boost System。但实际上对于C++17来说Boost Thread以及Boost System几乎是不需要的。而对于一些简单的无需高精度数字的算法,GMP和MPFR也是不需要的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lst0426

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值