0

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.

10
  • 1
    try target_link_directories(imgui PUBLIC SDL3::SDL3) Commented Aug 18 at 16:12
  • @AhmedAEK I had it SDL3::SDL3 before, when I kept getting the error , I tried a few things, and end up leaving SDL3 when I posted this question. Commented Aug 18 at 17:35
  • You may want to enable verbose make with make VERBOSE=1 to see what exact include directories are being used after you fix it back to: target_link_directories(imgui PUBLIC SDL3::SDL3) which is correct. Commented Aug 18 at 19:12
  • @drescherjm I fixed the text back to SDL3::SDL3 and after rebuilding cmake in the build directory, I ran the make VERBOSE=1. I am not sure what I should be looking for. I took a look into the build directory after cmake .. -G "Unix Makefiles" command ,before make, to see if a copy of the SDL.h was made. I found it in build/_deps/sdl3_src/include/SDL3/ path. After entering make command, the process Building CXX object.....imgui_impl_sdl3.cpp.o prior 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? Commented Aug 18 at 21:20
  • I expected it to show the full build command on each file so you could see what parameters are passed to g++ to see if -Ibuild/_deps/sdl3_src/include was added when building your imgui code. Commented Aug 18 at 22:46

1 Answer 1

1

The build system generates the SDL3 library in the build folder, but imgui was not searching in the correct directory due to the command issue. target_link_directories(imgui PUBLIC SDL3) in the vendors/imgui/CMakeLists.txt file, on the last line, needs to be target_link_libraries(imgui PUBLIC SDL3::SDL3).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.