the last few days i was messing with CMake, and everything worked fine, except that i can't find a way to link ImGUI with GLFW
Everything is build from source
Here is the error :
Consolidate compiler generated dependencies of target glad
[ 2%] Built target glad
Consolidate compiler generated dependencies of target stb
[ 5%] Built target stb
Consolidate compiler generated dependencies of target glfw
[ 29%] Built target glfw
Consolidate compiler generated dependencies of target imgui
[ 30%] Building CXX object CMakeFiles/imgui.dir/lib/imgui/imgui.cpp.o
[ 31%] Building CXX object CMakeFiles/imgui.dir/lib/imgui/imgui_demo.cpp.o
[ 33%] Building CXX object CMakeFiles/imgui.dir/lib/imgui/imgui_draw.cpp.o
[ 34%] Building CXX object CMakeFiles/imgui.dir/lib/imgui/imgui_tables.cpp.o
[ 36%] Building CXX object CMakeFiles/imgui.dir/lib/imgui/imgui_widgets.cpp.o
[ 37%] Building CXX object CMakeFiles/imgui.dir/lib/imgui/imgui_impl_glfw.cpp.o
/home/erik/Workspace/LearnOpenGL/lib/imgui/imgui_impl_glfw.cpp:45:10: fatal error: GLFW/glfw3.h: No such file or directory
45 | #include <GLFW/glfw3.h>
| ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/imgui.dir/build.make:146: CMakeFiles/imgui.dir/lib/imgui/imgui_impl_glfw.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:228: CMakeFiles/imgui.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
And here is my CMakeLists.txt :
cmake_minimum_required(VERSION 3.1)
project(LearnOpenGL)
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source")
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(SOURCES "${SRC_DIR}/Main.cpp"
)
add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE "${SRC_DIR}")
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
# GLFW
set(GLFW_DIR "${LIB_DIR}/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")
add_subdirectory("${GLFW_DIR}")
target_link_libraries(${PROJECT_NAME} "glfw" "${GLFW_LIBRARIES}")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLFW_DIR}/include")
target_compile_definitions(${PROJECT_NAME} PRIVATE "GLFW_INCLUDE_NONE")
# Glad
set(GLAD_DIR "${LIB_DIR}/glad")
add_library("glad" "${GLAD_DIR}/src/glad.c")
target_include_directories("glad" PRIVATE "${GLAD_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLAD_DIR}/include")
target_link_libraries(${PROJECT_NAME} "glad" "${CMAKE_DL_LIBS}")
# GLM
set(GLM_DIR "${LIB_DIR}/glm")
add_subdirectory(${GLM_DIR})
target_link_libraries(${PROJECT_NAME} "glm")
# STB
set(STB_DIR "${LIB_DIR}/stb")
add_library("stb" "${STB_DIR}/src/stb_image.cpp")
target_include_directories("stb" PRIVATE "${STB_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${STB_DIR}/include")
target_link_libraries(${PROJECT_NAME} "stb" "${CMAKE_DL_LIBS}")
# Freetype
set(FREETYPE_DIR "${LIB_DIR}/freetype")
add_subdirectory("${FREETYPE_DIR}")
target_link_libraries(${PROJECT_NAME} "${FREETYPE_LIBRARIES}")
target_include_directories(${PROJECT_NAME} PRIVATE "${FREETYPE_DIR}/include")
# ImGUI
set(IMGUI_DIR "${LIB_DIR}/imgui")
add_library("imgui" "${IMGUI_DIR}/imgui.cpp"
"${IMGUI_DIR}/imgui_demo.cpp"
"${IMGUI_DIR}/imgui_draw.cpp"
"${IMGUI_DIR}/imgui_tables.cpp"
"${IMGUI_DIR}/imgui_widgets.cpp"
"${IMGUI_DIR}/imgui_impl_glfw.cpp"
"${IMGUI_DIR}/imgui_impl_opengl3.cpp")
target_include_directories("imgui" PRIVATE "${IMGUI_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "${IMGUI_DIR}")
target_link_libraries(${PROJECT_NAME} "imgui" "${CMAKE_DL_LIBS}")
And here is my folder construction
1. build
2. lib
- freetype
- glad
- glfw
- glm
- imgui
- stb
3. source
- Main.cpp
4. CMakeLists.txt
Here is my question : How i can tell imgui that glfw is already here and he can use it?
Thanks in advance
find_package
to manage dependencies in CMake. – Gnawingadd_subdirectory
will not setFREETYPE_LIBRARIES
. I think you've confused this withfind_package
. It looks like you're writing your own mini build systems for STB, Glad, and ImGUI. Maybe don't do that? – Gnawing