Search code examples
openglcmakeglfwglm-mathshading

Error in compiling the examples of OpenGL 4 Shading Language Cookbook, 3rd Edition


I downloaded the source code of OpenGL 4 Shading Language Cookbook, 3rd Edition from PacktPublishing github

I have downloaded the glm source code version glm-0.9.9.3 and I have downloaded the glfw source code version glfw-3.2.1. I successfully compiled, built and installed both glm and glfw using the "cmake ."

To find the GLFW installation, I executed the below command in the src (examples) folder

cmake -D CMAKE_PREFIX_PATH=e:\mysrcpath\glfw-3.2.1\src .

I am getting the below error

-- Selecting Windows SDK version  to target Windows 10.0.17134.
CMake Error at E:/glfw-3.2.1/src/glfw3Config.cmake:1 (include):
include could not find load file:

E:/glfw-3.2.1/src/glfw3Targets.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (find_package)

-- Found OpenGL: opengl32
-- Configuring incomplete, errors occurred!

The glfw3Config.cmake is having the code

include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake")

The "CMAKE_CURRENT_LIST_DIR" is

E:/glfw-3.2.1/src/

But the glfw3Targets.cmake is located in

E:/glfw-3.2.1/CMakeFiles/Export/lib/cmake/glfw3/

The 'cmake' build is not able to find the glfw3Targets.cmake in the correct path.

How to fix this issue?


Solution

  • It seem like GLFW version 3.2.1 does not support using it directly from the build tree. You should install GLFW instead and add the directory to the cmake prefix paths.

    in the glfw directory:

    mkdir build && cd build
    cmake -DCMAKE_INSTALL_PREFIX=c:/local/ ..
    cmake --build . --target install
    

    Then when invoking cmake for your projects:

    cmake -D CMAKE_PREFIX_PATH=c:/local/