Compile code based on CGAL

CGAL is an amazing computational geometry library that can make your programming life so much simpler and faster. Once you overcome the weird looking coding style becomes a powerful tool.

Here I’ll describe few modifications that I make on the cgal generated CMakeList.txt that make my life a bit easier, and make the flles more portable.

In short the steps are

1) For each project create a new folder and create a default CMakeList.txt file by running cgal_create_cmake_script

This is going to create a default CMakeList.txt file.

To make the script easier to tranfer between my CGAL projects I’m doing the following changes:



First I remove the default project name which is taken by the folder name.

Then I add a target name for the project and a target source.

Remove one statement create_single_source_cgal_program(…)

Finally at the end of the file I set the project and the executable.

To run cmake you need to create a file with the name ${TARGET}.cpp, in my case test1.cpp. Even an empty file its ok

Then run cmake (don’t forget the space dot) 

If the configuration is succesfull you can run make after you have writen some code into the file ${TARGET}.cpp

Those modifications allow to copy the same CMakeList.txt files to other projects and build them with a single modification just the very first line. In addition with few other modifications that will be subject to another post you can add other libraries like deal.ii and OpenSceneGraph

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.