CGAL 5.2 - Manual
How to use CGAL with CMake

This page will explain how to manually create a CMakeLists.txt file to link a custom program with CGAL.

A base can be created using the script cgal_create_CMakeLists. Its usage is detailed in Section Creating a CMake Script for a Program Using CGAL.

Linking with CGAL

To link with the CGAL library, use the following:

find_package(CGAL)
add_executable(my_executable my_source_file.cpp)
target_link_libraries(my_executable CGAL::CGAL)

Other CGAL libraries are linked similarly. For example, with CGAL_Core:

find_package(CGAL REQUIRED COMPONENTS Core)
target_link_libraries(my_executable CGAL::CGAL CGAL::CGAL_Core)

There are also imported targets to link with CGAL dependencies that can be found in the section Essential and Optional Third Party Dependencies.

Note
The CGAL targets define the following compiler flags:
  • -frounding-math with gcc
  • /fp:strict /fp:except- with MSVC

Minimal Example Using Qt5

This section describes a minimal example of a program that uses CGAL and Qt5 for some GUI features.

CMakeLists.txt

draw_surface_mesh.cpp

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/draw_surface_mesh.h>
#include <fstream>
typedef Kernel::Point_3 Point;
int main(int argc, char* argv[])
{
Mesh sm1;
std::ifstream in1((argc>1)?argv[1]:"data/elephant.off");
in1 >> sm1;
CGAL::draw(sm1);
return EXIT_SUCCESS;
}