1

I'm working on a class project in C++ using CLION which requires the CGAL library, and I'm having trouble getting the library to work with my project.

We're trying to get the library working in it's header-only configuration for simplicity, however the documentation for CGAL is a bit thin on details when it comes to this way of doing things. In this part of the installation documentation we're told to extract the CGAL library data somewhere and reference it in a variable in our cmake file. However we can't seem to reference any of CGAL's headers in our project - none of the directories or files can be found at all.

We've tried to fix this ourselves for a while but we don't really know where to look or what the problem is, and the documentation for CGAL isn't being of much help. Below I've attached our CMakeLists file contents, have we done something really wrong or is it as it should be?

cmake_minimum_required(VERSION 3.9)
project(remeshing_project)
set(CMAKE_CXX_STANDARD 17)

if(MINGW OR CYGWIN)
    add_definitions(-O3)
endif()

set(ENV{CGAL_DIR} S:/dev/cgal)

add_definitions(-DCGAL_DIR=$(CGAL_DIR))
#add_definitions(-DCGAL_LINKED_WITH_TBB)
#add_definitions(-DCGAL_USE_GMP)
#add_definitions(-DCGAL_USE_MPFR)
#add_definitions(-DCGAL_USE_ZLIB)

link_libraries(../external/glew_2_1_0/lib/Release/Win32/glew32s)
link_libraries(../external/glfw/lib-vc2015/glfw3)
link_libraries(../external/openGL/OPENGL32)
link_libraries(../external/openGL/glut32)
link_libraries(../external/openGL/glu32)


#Header Locations
set(HEADER_DIRS external/tinyply
        external/libigl/include/
        external/glfw/include/
        external/eigen-git-mirror/
        external/glew_2_1_0/include/
        external/nanoflann/
        external/spectra/
        external/halfedge/
        external/
        $(CGAL_DIR)/)

add_executable(Remesher src/main.cpp external/halfedge/trimesh.cpp src/meshMetrics.cpp src/meshMetrics.h src/remeshingTools.cpp src/remeshingTools.h src/dataStructures.h)
target_include_directories(Remesher PRIVATE ${HEADER_DIRS})

Any help would be hugely appreciated, we've been banging our head against this for a while and are at a loss. Thanks in advance!

2 Answers2

0

My guess is that you are simply missing

find_package( CGAL)
if ( CGAL_FOUND )
  include( ${CGAL_USE_FILE} )

After that you should check that the CMAKE variable CGAL_DIR points to your extracted directory of CGAL and you should be fine.

mgimeno
  • 726
  • 1
  • 4
  • 7
0

You need:

find_package(CGAL QUIET COMPONENTS Core )    
if(CGAL_FOUND)
  #Don't let CGAL override flags
  set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags")
  include(${CGAL_USE_FILE})
  include(CGAL_CreateSingleSourceCGALProgram)
endif()

And:

add_executable(Remesher src/main.cpp external/halfedge/trimesh.cpp src/meshMetrics.cpp src/meshMetrics.h src/remeshingTools.cpp src/remeshingTools.h src/dataStructures.h)
target_link_libraries(Remesher PRIVATE ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}

CGAL also typically requires things like Eigen and MPFR. A full working example is here:

https://github.com/acgetchell/CDT-plusplus/releases/tag/0.1.8

I didn't link directly to my CMakeLists.txt because I'm in the process of converting to using the Conan package manager, so it will be quite different soon.

Adam Getchell
  • 437
  • 4
  • 7