I am trying to write an OpenGL application with GLFW. The file structure is as follows
-USG
-build
-include
-glfw-3.3
-src
-CMakeLists.txt
-main.cpp
-CMakeLists.txt
The CMake in the USG
file is as follows.
cmake_minimum_required(VERSION 3.0)
project(USG)
#--------------------------------------------------------------------
# Set GLFW variables
#--------------------------------------------------------------------
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
#--------------------------------------------------------------------
# Add subdirectories
#--------------------------------------------------------------------
add_subdirectory(include/glfw-3.3)
add_subdirectory(src)
And the CMakeLists in the src
file is as follows
add_executable(usg main.cpp)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
target_include_directories(usg PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(usg ${OPENGL_gl_LIBRARY})
endif()
target_link_libraries(usg glfw)
I run cmake ../
followed by make
in the build folder. Running cmake runs as expected. Running make builds glfw fine but when it gets to main.cpp it fails at #include <GLFW\glfw3.h>
telling me GLFW\glfw3.h: No such file or directory
. It seems to me like the cmake isn't properly linking the header file to the main.cpp file, but I don't know enough about cmake to get that to work. I've tried looking through the examples provided in the glfw-3.3 example folder but I couldn't make enough sense of it to solve my problem. I've tried drawing what knowledge I could from the many similar problems on stack overflow but none of them could help.
I'm following this tutorial here. I want the OpenGL application to be relatively portable, which is why I'm compiling glfw from source rather than using a binary. I'm building on Linux, if that matters.
Try #include <GLFW/glfw3.h>
instead of #include <GLFW\glfw3.h>
Backslashes in include paths are a bad (Windows)-practice and do not work with GCC.