CMake cannot find freeglut on windows in Clion

半世苍凉 提交于 2021-02-17 01:54:05

问题


I've been stuck for a while now and I can't figure out how to get freeglut working. I thought I knew what it was asking me to do, so I added that set(prefix_path) line but it didn't do anything. Am I supposed to write my own freeglut-config.cmake or what?

Note: I am using the freeglut for MinGW package from this website

CMake File:

cmake_minimum_required(VERSION 3.7)
project(HW1)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES Triangle.cpp)
set(CMAKE_PREFIX_PATH "C:/freeglut")

find_package(GLEW REQUIRED STATIC)
find_package(FREEGLUT REQUIRED)
find_package(OPENGL REQUIRED)

include_directories(${FREEGLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS})
link_directories(${FREEGLUT_LIBRARY_DIRS} ${GLEW_LIBRARY_DIRS} ${OPENGL_LIBRARY_DIRS})
add_definitions(${FREEGLUT_DEFINITIONS} ${GLEW_DEFINITIONS} ${OPENGL_DEFINITIONS})

add_executable(HW1 ${SOURCE_FILES})
target_link_libraries(HW1 ${FREEGLUT_LIBRARIES} ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})

Full error:

CMake Error at CMakeLists.txt:8 (find_package):
  By not providing "FindFREEGLUT.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "FREEGLUT",
  but CMake did not find one.

  Could not find a package configuration file provided by "FREEGLUT" with any
  of the following names:

    FREEGLUTConfig.cmake
    freeglut-config.cmake

  Add the installation prefix of "FREEGLUT" to CMAKE_PREFIX_PATH or set
  "FREEGLUT_DIR" to a directory containing one of the above files.  If
  "FREEGLUT" provides a separate development package or SDK, be sure it has
  been installed.

回答1:


If your application is GLUT-compatible, that it doesn't use any extension of freeglut, then it is better to search GLUT instead of FREEGLUT:

find_package(GLUT REQUIRED)

"Find" script used by this command is already shipped into CMake distro, and it searches freeglut too.

(Note, that with that command variables for include directories and linking libraries are GLUT_INCLUDE_DIR and GLUT_LIBRARY correspondingly).

If your application requires exactly freeglut (that is, uses some of its extensions incompatible with other GLUT implementations), you need to ship your package with FindFREEGLUT.cmake script and adjust CMAKE_MODULE_PATH variable correspondingly:

# Assuming you have <source-dir>/cmake/FindFREEGLUT.cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
find_package(FREEGLUT REQUIRED)

You may find existing script in the net, or write it by yourself, like here.


In any case, if you have freeglut installed into non-system location, you need to hint CMake about that. E.g., by adjusting CMAKE_PREFIX_PATH.



来源:https://stackoverflow.com/questions/43994489/cmake-cannot-find-freeglut-on-windows-in-clion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!