Search code examples
c++ubuntucmakecomputational-geometrycgal

New to CGAL---Difficulties in Getting Started: CGAL_Qt5 Returns FALSE in CMake


Background

I am relatively new to C++ and CMake and especially new to CGAL. As of now, I am simply trying to get familiar with CGAL so that I can remake an algorithm of mine that was originally built in MATLAB, but due to the inadequacy of their computational geometry libraries, I am moving to C++ and CGAL.

System and Versions Used

OS Kernel: Ubuntu 20.04
CGAL 5.2.1
CMake 3.16.3

Problem

I am currently trying to build the "Minimal Example Using Qt5", found here. At first, I was getting an error saying, CGAL/Qt/Basic_viewer_qt.h: No such file or directory. This seemed to be a simple fix since the Qt folder was missing from the /usr/include/CGAL directory, along with others. Here, CGAL was installed with apt-get. To fix this I simply copied the full include directory from CGAL's github. Now, I still have a problem remaining from CMake, where CGAL_FOUND returns FALSE and when I attempt to build the executable, I get no results or error messages (i.e., no main executable in cgalTest/bin).

Further Details

Project's Folder Structure

cgalTest
-bin
-build
--<CMake stuff>
-CMakeLists.txt
-doc
-include
-lib
-spike
-src
--main.cpp
-test

CMakeLists.txt

cmake_minimum_required(VERSION 3.16.3)
project(cgalTest)

### Link with Libraries ###
# CGAL
find_package(CGAL REQUIRED COMPONENTS Qt5 Core)
if(CGAL_FOUND AND CGAL_Qt5_FOUND)
  #required to use basic_viewer
  add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
  #create the executable of the application
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
  add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
  #link it with the required CGAL libraries
  target_link_libraries(${PROJECT_NAME} CGAL::CGAL CGAL::CGAL_Qt5 CGAL::CGAL_Core)
else()
  if(NOT CGAL_FOUND)
    message("ERROR: this program requires CGAL and will not be compiled.")
  endif()
  if(NOT CGAL_Qt5_FOUND)
    message("ERROR: this program requires CGAL_Qt5 and will not be compiled.")
  endif()
endif()

main.cpp

#include <iostream>
#include <string>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/draw_surface_mesh.h>
#include <fstream>

typedef CGAL::Simple_cartesian<double>                       Kernel;
typedef Kernel::Point_3                                      Point;
typedef CGAL::Surface_mesh<Point>                            Mesh;

using namespace std;
// Main Code
int main()
{
    Mesh sm1;
    std::ifstream in1((argc>1)?argv[1]:"data/elephant.off");
    in1 >> sm1;
    CGAL::draw(sm1);
    return EXIT_SUCCESS;
}

How I am Building the Project

I simply run the following:
cmake --build /home/<user>/Projects/cgalTest/build

CMake Configuration Output

[main] Configuring folder: cgalTest 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H/home/<user>/Projects/cgalTest -B/home/<user>/Projects/cgalTest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Using header-only CGAL
[cmake] -- Targetting Unix Makefiles
[cmake] -- Using /usr/bin/c++ compiler.
[cmake] -- Boost include dirs: /home/linuxbrew/.linuxbrew/include
[cmake] -- Boost libraries:    
[cmake] -- Using gcc version 4 or later. Adding -frounding-math
[cmake] ERROR: this program requires CGAL_Qt5 and will not be compiled.
[cmake] CMake Warning at /home/linuxbrew/.linuxbrew/lib/cmake/CGAL/CGAL_enable_end_of_configuration_hook.cmake:99 (message):
[cmake]   =======================================================================
[cmake] 
[cmake]   CGAL performance notice:
[cmake] 
[cmake]   The variable CMAKE_BUILD_TYPE is set to "Debug".  For performance reasons,
[cmake]   you should set CMAKE_BUILD_TYPE to "Release".
[cmake] 
[cmake]   Set CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE to TRUE if you want to disable
[cmake]   this warning.
[cmake] 
[cmake]   =======================================================================
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:9999 (CGAL_run_at_the_end_of_configuration)
[cmake] 
[cmake] 
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/<user>/Projects/cgalTest/build

Final Thoughts

As I have said, I am still pretty new to this and may need some hand holding during some of this. Thanks again, your help will be appreciated.
Also, do not hesitate to critique anything else you see: folder structure, coding practice, etc


Solution

  • So basically, when I installed qt5 I believe I used
    sudo apt-get libcal-qt5-default
    rather than
    sudo apt-get libcal-qt5-dev.
    This is of course based on my memory of what I think I did during installation, but simply running the installation for the "dev" fixed it (i.e., making CGAL_QT_FOUND to TRUE and then letting me compile).
    Along with this, in main.cpp I was missing the argument definitions for argc and argv.