Hello! I'm attempting to learn CMake and trying to include imgui into a particular project but failing :(
This is my project structure:
- assets
- build
- include
- lib
- engine
- include
- src
- CMakeLists.txt (1)
- gamecore
- include
- src
- CMakeLists.txt (2)
- shaders
- src
- main.cpp
- vendor
- glad
- glm
- imgui
- tinygltf
- CMakeLists.txt (3)
lib/engine's CMake file includes all the 3rd party libraries like GLFW, GLM, etc. Then I expose all the necessary windowing functionality to lib/gamecore and main.cpp by including files from lib/engine
Everything is working fine, but I can't seem to include imgui into lib/engine. I'm getting the following error:
\vendor\imgui\backends\imgui_impl_glfw.cpp(66,10): fatal error C1083: Cannot open include file: 'GLFW/glfw3.h': No such file or directory
Being the CMake newbie that I am, I'm pretty sure I'm doing something wrong. Would anybody have any recommendations? All I want to do is include imgui to lib/engine :(
This is lib/engine's CMake file:
project(engine)
# OpenGL
find_package( OpenGL REQUIRED )
include_directories(${OPENGL_INCLUDE_DIRS})
# GLAD
add_library(glad STATIC ../../vendor/glad/src/glad.c)
target_include_directories(glad PRIVATE ../../vendor/glad/include)
#GLFW
set(GLFW_DIR ../../vendor/glfw)
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
## I'm trying to add it here1
set(IMGUI_DIR ../../vendor/imgui)
add_library(imgui STATIC
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
${IMGUI_DIR}/imgui.cpp
)
target_include_directories(imgui PRIVATE ../../vendor/imgui)
file(GLOB SOURCES
src/*.cpp src/*.c
src/core/*.cpp src/*.c
src/renderer/*.cpp src/*.c
src/math/*.cpp src/*.c
src/geometry/*.cpp src/*.c
src/input/*.cpp src/*.c
)
# TINYGLTF
set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE)
set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE)
add_subdirectory(${GLFW_DIR} "glfw-binaries")
add_library(${PROJECT_NAME} STATIC ${SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${GLFW_DIR}/include)
target_include_directories(${PROJECT_NAME} PUBLIC ../../vendor/glad/include)
target_compile_definitions(${PROJECT_NAME} PRIVATE GLFW_INCLUDE_NONE)
target_include_directories(${PROJECT_NAME} PUBLIC ../../vendor/glm)
target_include_directories(${PROJECT_NAME} PUBLIC ../../vendor/tinygltf)
target_include_directories(${PROJECT_NAME} PUBLIC ${IMGUI_DIR}) # and here...
if(UNIX AND NOT APPLE)
target_link_libraries(engine pthread)
elseif(WIN32)
target_link_libraries(engine glad glfw)
endif()
Oh and if you're interested in checking out the root and Gamecore Cmake files, I've uploaded them here:
Root Cmake: https://pastebin.com/BNnNrUFq
Gamecore: https://pastebin.com/VhVCsQDB