I am trying to learn imgui by first create a project using its library. But, first I wanted to run one of the examples found in the github repository. I am not using an IDE, only my mac terminal. Therefore, I am using cmake to build the project. Here is my project directory structure:
imgui_project
|____build
|____CMakeLists.txt
|____src
| |__CMakeLists.txt
| |__main.cpp
|____Vendors
|___CMakeLists.txt
|___Imgui
| |____CMakeLists.txt
|___sdl
|____CMakeLists.txt
The content in the files:
imgui_project/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(imgui_app)
add_subdirectory(vendors)
add_subdirectory(src)
src/CMakeLists.txt
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE SDL3 imgui)
src/main.cpp
{the entire content of example_sdl3_renderer3 main.cpp file from the imgui github repository.}
Vendors/CMakeLists.txt
add_subdirectory(sdl)
add_subdirectory(imgui)
Vendors/imgui/CMakeLists.txt
include(FetchContent)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG docking
)
FetchContent_MakeAvailable(imgui)
add_library(imgui)
target_include_directories(
imgui
PUBLIC
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
)
target_sources(
imgui
PUBLIC
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp
)
target_link_directories(imgui PUBLIC SDL3)
Vendors/sdl/CMakeLists.txt
include(FetchContent)
FetchContent_Declare(
SDL3
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-3.2.20
)
FetchContent_MakeAvailable(SDL3)
I build the project in the build directory using the command: cmake .. -G "Unix Makefiles"
When I run make, the error I am getting:
.../imgui_project/build/_deps/imgui-src/backends/imgui_impl_sdl3.cpp:83:10: fatal error: 'SDL3/SDl.h' file not found
83 | #include <SDL3/SDL.h>
In the SDL3 github repository, 3.2.20 release, in the include/SDl3/ directory, SDL.h is there. I thought having the FetchContent_MakeAvailable(SDL3) would make the library available in the build after fetching it.
So, I am not sure why it is not able to find the SDL.h file. That is the only error I am currently getting.
target_link_directories(imgui PUBLIC SDL3::SDL3)SDL3::SDL3before, when I kept getting the error , I tried a few things, and end up leavingSDL3when I posted this question.make VERBOSE=1to see what exact include directories are being used after you fix it back to:target_link_directories(imgui PUBLIC SDL3::SDL3)which is correct.SDL3::SDL3and after rebuilding cmake in the build directory, I ran themake VERBOSE=1. I am not sure what I should be looking for. I took a look into the build directory aftercmake .. -G "Unix Makefiles"command ,beforemake, to see if a copy of theSDL.hwas made. I found it inbuild/_deps/sdl3_src/include/SDL3/path. After enteringmakecommand, the processBuilding CXX object.....imgui_impl_sdl3.cpp.oprior to the error doesn't refer to that path at all, in any of the verbose output text provided. What should I be looking for exactly?g++to see if-Ibuild/_deps/sdl3_src/includewas added when building your imgui code.