As the titles says I can\'t seem to build the project with OpenGL and Glut.
I get Undefined reference errors for OpenGL functions.
I tried doing :
In recent versions of CMake (3.10+) there is a new way to use OpenGL using a so-called IMPORTED target:
cmake_minimum_required(VERSION 3.10)
project(testas)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
find_package(GLUT REQUIRED)
add_dependencies(testas OpenGL::OpenGL)
include_directories(${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas OpenGL::OpenGL ${GLUT_LIBRARY} )
At the moment the only practical difference seems to be on Linux (where GLVND is used if available), but presumably this solution should be more future-proof, as CMake has more information about your intentions and other tools parsing your CMakeFiles will better understand the dependency tree.