Search code examples
geometryubuntu-18.04computational-geometrycgal

CGAL example on Ubuntu 18.04


I installed CGAL via package manager on ubuntu 18.04 LTS. Then as mentioned on https://doc.cgal.org/latest/Manual/usage.html in order to compile an example program. While I issued:

cmake -DCMAKE_BUILD_TYPE=Release .

to configure the examples, I am getting the following error:

CMake Error at CMakeLists.txt:29 (create_single_source_cgal_program):
  Unknown CMake command "create_single_source_cgal_program".


-- Configuring incomplete, errors occurred!

Kindly help; what should I do?

CmakeLists.txt

# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.


cmake_minimum_required(VERSION 3.1...3.15)
project( Triangulation_2_Examples )


if(NOT POLICY CMP0070 AND POLICY CMP0053)
  # Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning.
  cmake_policy(SET CMP0053 OLD)
endif()

if(POLICY CMP0071)
  cmake_policy(SET CMP0071 NEW)
endif()

find_package(CGAL COMPONENTS Qt5)

if(CGAL_Qt5_FOUND)
  add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
endif()

if ( CGAL_FOUND )

  # create a target per cppfile
  file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
  foreach(cppfile ${cppfiles})
    create_single_source_cgal_program( "${cppfile}" )
  endforeach()

  if(CGAL_Qt5_FOUND)
    target_link_libraries(draw_triangulation_2 PUBLIC CGAL::CGAL_Qt5)
  else()
    message(STATUS "NOTICE: The example draw_triangulation_2 requires Qt and will not be compiled.")
  endif()

else()

    message(STATUS "This program requires the CGAL library, and will not be compiled.")

endif()

Solution

  • It looks like we're supposed to build all the CGAL examples right away during the CGAL installation (using the cmake option -DWITH_examples=ON). There are many examples and sub-examples, so it takes a long time to build all of them.

    However I was able to build these examples selectively one by one (see below). I'm not a CGAL developer, so my approach might be not what they wanted - but anyway I hope it'll be useful for the CGAL community. I'm assuming that the CGAL has been installed without examples.

    Step 1. Create a directory for CGAL examples with any name you want, and enter this directory:

    mkdir CGAL
    cd GGAL
    

    Step 2. Copy the examples directory from the CGAL distribution into this directory, and make sure it's writable:

    cp -r <CGAL distribution>/examples .
    chmod -R u+w examples
    

    Step 3. Run cmake to generate a Makefile. In the case you installed the CGAL into some unusual location you'll need the CMAKE_INSTALL_PREFIX option to tell cmake about this location:

    cmake -DCMAKE_INSTALL_PREFIX=<CGAL location> examples
    

    Step 4. Run make help to see all the possible examples you can make. You can select all the examples, which visualize something:

    make help | grep draw
    

    Step 5. Build one of Triangulation_2 examples:

    make draw_triangulation_2
    

    Step 6. Enter the example directory and run the example:

    cd examples/Triangulation_2
    ./draw_triangulation_2&
    

    By the way, for some reason the first draw_triangulation_2 run shows an empty window on my box, but the second run shows the correct picture.