CMake can't find freeglut-3.0.0
Asked Answered
A

1

9

Freeglut-3.0.0 is build with cmake (MinGW makefiles) and mingw and then successfully installed with mingw32-make install to C:/Program Files (x86)/freeglut.

My CMakeLists.txt is:

    cmake_minimum_required(VERSION 3.7)

    project(math_tests)

    set(TESTS_SOURCES tests.cpp gl_core_3_3.c)
    set(CMAKE_CXX_STANDARD 11)

    # GLUT
    find_package(GLUT REQUIRED)
    include_directories(${GLUT_INCLUDE_DIR})
    if(NOT GLUT_FOUND)
        message(ERROR "GLUT not found!")
    endif(NOT GLUT_FOUND)

    # OpenGL
    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)

    add_executable(tests ${TESTS_SOURCES})
    target_link_libraries(tests math ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES})

Now CMake prints error: Could NOT find GLUT (missing: GLUT_glut_LIBRARY).

I can't figure out what I am doing wrong.

Achromatous answered 2/6, 2017 at 18:49 Comment(0)
I
8

Your CMakeLists.txt file statement

find_package(GLUT REQUIRED)

is going to execute this code from FindGLUT.cmake

find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
    PATHS
    ${OPENGL_LIBRARY_DIR}
    ${GLUT_ROOT_PATH}/Release
    )

and find_library is in your scenario unable to find any of glut glut32 freeglut libraries, because it doesn't know where they are (which for you are under C:/Program Files (x86)/freeglut).

In your case you could set ${OPENGL_LIBRARY_DIR} to the right directory, that is the one containing the freeglut.dll file, for e.g.:

set(OPENGL_LIBRARY_DIR "C:/Program Files (x86)/freeglut/lib")

given the file is under C:/Program Files (x86)/freeglut/lib directory.

Irremissible answered 2/6, 2017 at 19:9 Comment(3)
Thanks! That worked. But how user will specify this path (since FindGLUT will require its variables instead of OPENG_LIBRARY_DIR in case it will not find GLUT)? Also, I'm building for Linux too, and CmakeLists.txt should work on both platforms. Currently it sets OPENGL_LIBRARY_DIR in if (WIN32) statement.Achromatous
for multiplatform's sake, better to set CMAKE_PREFIX_PATH to a the parent of "lib/<freeglutlibrary>", such as "c:/program files (x86)/freeglut" in your specific scenario. Best to avoid any specific SET in your cmake, but let the end user set proper prefix with -DCMAKE_PREFIX_PATH=<your path> at configuration time. Perhaps using OPTIONS to let enduser set a specific path to freeglut would be sensible too (and the option's value would be appended to CMAKE_PREFIX_PATH by your script)Irremissible
forgot to say that for Linux you do not need to set anything for the discovery of freeglut library, it should just work with no additional settingsIrremissible

© 2022 - 2024 — McMap. All rights reserved.