Skip to content

Instantly share code, notes, and snippets.

@JPenuchot
Last active October 2, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPenuchot/92f381d972a1a6331b33e25789abf320 to your computer and use it in GitHub Desktop.
Save JPenuchot/92f381d972a1a6331b33e25789abf320 to your computer and use it in GitHub Desktop.
CMakeLists.tkt for Christian Jacquemin's OpenGL course at https://perso.limsi.fr/jacquemi/OGL/, tested on Arch Linux (Previous versions were tested on Solus and MacOS, you might want to try them if this one doesn't work on your system)
cmake_minimum_required(VERSION 2.8.9)
project(prog)
find_package(PkgConfig REQUIRED)
# Adding compiler optimizations
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -march=native")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
# Prefer vendor OpenGL over legacy version
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenCV REQUIRED)
find_package(GLEW REQUIRED)
find_package(OpenGL REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
# Adding includes
include_directories(
"include/"
${OPENGL_INCLUDE_DIR}
${GLFW_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
)
# Linking libraries
link_libraries(
${OpenCV_LIBRARIES}
${OPENGL_LIBRARIES}
${GLFW_LIBRARIES}
${GLEW_LIBRARIES}
)
# Adding sources
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
@JPenuchot
Copy link
Author

JPenuchot commented Mar 22, 2017

Updated on 29/03/2017

Requirements

  • GLFW 3
  • OpenCV

Both can be installed using Brew on MacOS or any decent package manager on *nix distros.

OpenGL compatibility - Required for MacOS users

Add these lines after the glfwInit() if statement at the beginning of the main() to enable OpenGL Core profile to enable support for recent OpenGL versions :

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Only on MacOS but shouldn't break your program on other devices
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
Source : http://www.opengl-tutorial.org/

After this you might want to change #version 130 in your shaders to #version 410 to enable a newer version of GLSL.

This was tested on a MacBook Air and a Dell XPS 13 (6560U, Iris Graphics 540) running Solus Project (Linux) and should work on any other device.

Usage

First put the CMakeLists.txt in the main folder where the src folder is

cmake .
make

This will output the program as 'prog'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment