编译CGAL

2023-07-08 14:36:28 浏览数 (2)

抛弃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”并键入内容:

代码语言:javascript复制
#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”并键入内容:

代码语言:javascript复制
#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”并键入内容:

代码语言:javascript复制
#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”并键入内容:

代码语言:javascript复制
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”,即可。好了,给个例子吧。

代码语言:javascript复制
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 人点赞