Opengl with cmake and glew glfw3 and glm libraries

19,642

I know this is a "little" late. But if someone else has run into this problem. This is what I did.

I copied this file https://github.com/Groovounet/glm-deprecated/blob/master/util/FindGLM.cmake in my computer i.e /home/user/Libs/cmake/FindGLM.cmake

Then I added this line to my CMakeLists.txt:

set(CMAKE_MODULE_PATH /home/user/Libs/cmake)

So my first 3 lines of my file are:

cmake_minimum_required (VERSION 2.6)
project (test)
set(CMAKE_MODULE_PATH /home/user/Libs/cmake)

Then I run cmake and make and I had no errors.

Share:
19,642
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a problem compiling this example on Ubuntu 12.04 LTS:

    #include <stdio.h>
    #include <stdlib.h>
    #include <GL/glew.h>
    #include <GL/glfw3.h>
    #include <glm/glm.hpp>
    
    using namespace glm;
    
    int main(){
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }
    
    glfwWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
    glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.3
    glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
    
    // Open a window and create its OpenGL context
    GLFWwindow* window; // (In the accompanying source code, this variable is global)
    window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
    if( window == NULL ){
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    
    // Initialize GLEW
    glewExperimental=true; // Needed in core profile
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }
    
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
    
    do{
        // Draw nothing, see you in tutorial 2 !
    
        // Swap buffers
        glfwSwapBuffers(window);
        glfwPollEvents();
    
    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
    glfwWindowShouldClose(window) == 0 );
    
    return 0;
    }
    

    I tried to compile it using a single line in terminal with the proper flags, but always finding errors. In several forums i found that is better to use cmake to find, link and compile using the libraries i need, so using this example i tried to program my own cmake lists, obtaining this code:

    cmake_minimum_required(VERSION 2.8)
    
    
    #Encontrando y linkeando GLEW
    find_package(GLEW REQUIRED)
    include_directories(${GLEW_INCLUDE_DIRS})
    link_directories(${GLEW_LIBRARY_DIRS})
    add_definitions(${GLEW_DEFINITIONS})
    if(NOT GLEW_FOUND)
     message(Error " GLEW not found")
    endif(NOT GLEW_FOUND)
    
    #Encontrando y linkeando glfw3
    find_package(GLFW REQUIRED)
    include_directories(${GLFW_INCLUDE_DIRS})
    link_directories(${GLFW_LIBRARY_DIRS})
    add_definitions(${GLFW_DEFINITIONS})
    
    if(NOT GLFW_FOUND)
            message(Error "GLFW not found")
    endif(NOT GLFW_FOUND)
    
    #Encontrando y linkeando glm
    
    find_package(GLM REQUIRED)
    include_directories(${GLM_INCLUDE_DIRS})
    link_directories(${GLM_LIBRARY_DIRS})
    add_definitions(${GLM_DEFINITIONS})
    
    if(NOT GLM_FOUND)
            message(Error "GLM not found")
    endif(NOT GLM_FOUND)
    
    find_package(OpenGL REQUIRED)
    include_directories(${OpenGL_INCLUDE_DIRS})
    link_directories(${OpenGL_LIBRARY_DIRS})
    add_definitions(${OpenGL_DEFINITIONS})
    
    if(NOT OpenGL_FOUND)
            message(Error "OpenGL not found")
    endif(NOT OpenGL_FOUND)
    
    #Incluir archivos
    
    add_executable(abrir main.cpp)
    
    target_link_libraries(abrir ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW_LIBRARIES} ${GLM_LIBRARIES})
    

    But I get these errors:

    Could not find module FindGLEW.cmake or a configuration file for package GLEW.
    
    Adjust CMAKE_MODULE_PATH to find FindGLEW.cmake or set GLEW_DIR to the
    directory containing a CMake configuration file for GLEW.  The file will
    have one of the following names:
    
    GLEWConfig.cmake
    glew-config.cmake
    
    
    
    Error GLEW not found
    CMake Error at CMakeLists.txt:14 (find_package):
    Could not find module FindGLFW.cmake or a configuration file for package
    GLFW.
    
    Adjust CMAKE_MODULE_PATH to find FindGLFW.cmake or set GLFW_DIR to the
    directory containing a CMake configuration file for GLFW.  The file will
    have one of the following names:
    
    GLFWConfig.cmake
    glfw-config.cmake
    
    
    
    ErrorGLFW not found
    CMake Error at CMakeLists.txt:25 (find_package):
    Could not find module FindGLM.cmake or a configuration file for package
    GLM.
    
    Adjust CMAKE_MODULE_PATH to find FindGLM.cmake or set GLM_DIR to the
    directory containing a CMake configuration file for GLM.  The file will
    have one of the following names:
    
    GLMConfig.cmake
    glm-config.cmake
    

    How can I fix these errors? Or is there an easier way to solve the problem?

  • Jeremy Hajek
    Jeremy Hajek over 5 years
    This works for those trying to compile the Arrayfire library and receiving glm CMake errors