Version/Branch of Dear ImGui:
Version 1.80 and forward
Back-ends:
All
Compiler, OS:
MSVC, Clang, GCC
Full config/build information:
No response
Details:
Dear ImGui community...
I'm proposing CMake support to Dear ImGui: https://github.com/adembudak/CMakeForImGui
For the last couple of months I've been working on to add CMake support to ImGui. It emerged out of the personal needs, and now it reached to a point that it can build (almost) all of backends and examples. So I thought it would be best to ask feedback from community and maintainers.
It basically works like this:
cmake -DIMGUI_SOURCE_DIR=imgui -Dglfw=ON -Dvulkan=ON -S . -B build # 1
cmake --build build --config Debug # 2
cmake --install build --config Debug # 3
At step 1, client enables backends to use.
Step 2 builds and 3 installs which produce following install tree on install prefix:
.
├── include
│ ├── imconfig.h
│ ├── imgui_impl_glfw.h
│ ├── imgui_impl_vulkan.h
│ ├── imgui_internal.h
│ ├── imgui.h
│ ├── imstb_rectpack.h
│ ├── imstb_textedit.h
│ └── imstb_truetype.h
├── lib
│ ├── cmake
│ │ └── CMakeForImGui
│ │ ├── CMakeForImGuiConfig.cmake
│ │ ├── CMakeForImGuiConfigVersion.cmake
│ │ └── CMakeForImGuiTargets.cmake
│ ├── libimgui_backend_glfw.a
│ ├── libimgui_backend_vulkan.a
│ ├── libimgui_core.a
│ └── libimgui_demo.a
└── share
└── Dear ImGui
├── docs
│ ├── BACKENDS.md
│ ├── CHANGELOG.txt
│ ├── CONTRIBUTING.md
│ ├── EXAMPLES.md
│ ├── FAQ.md
│ ├── FONTS.md
│ ├── README.md
│ └── TODO.txt
└── LICENSE.txt
and installed library can be used, like:
find_package(CMakeForImGui REQUIRED)
add_executable(tgt)
# target_source(tgt ... )
target_link_libraries(tgt
Unofficial::DearImGui::imgui_backend_glfw
Unofficial::DearImGui::imgui_backend_vulkan)
Option and target names can be considered as a placeholder. -Dglfw can be -DIMGUI_BACKEND_GLFW, -DDEAR_IMGUI_BACKEND_GLFW, -DDearImGui_BACKEND_GLFW etc. and something similar applies to Unofficial::DearImGui::imgui_backend_glfw. Feedbacks are welcome :)
This repo shows the how ImGui examples build using it.
One possible downside is, this produces a target per backend and creates an inflation on target names, like another backends creates Unofficial::DearImGui::allegro5 and another Unofficial::DearImGui::glut.
Probably a non-problem because users usually wants a backend and renderer, like Win32+DirectX11. This is on the main branch.
On another branch a single target approach is demonstrated. All the backends and linked into the Unofficial::DearImGui::imgui target. This is what both conan and vcpkg does.
Backends are enabled on configure step like at step 1:
cmake -DIMGUI_SOURCE_DIR=imgui -Dglfw=ON -Dvulkan=ON -S . -B build
Builds and installs and results following install tree:
.
├── include
│ ├── imconfig.h
│ ├── imgui_impl_glfw.h
│ ├── imgui_impl_vulkan.h
│ ├── imgui_internal.h
│ ├── imgui.h
│ ├── imstb_rectpack.h
│ ├── imstb_textedit.h
│ └── imstb_truetype.h
├── lib
│ ├── cmake
│ │ └── CMakeForImGui
│ │ ├── CMakeForImGuiConfig.cmake
│ │ ├── CMakeForImGuiConfigVersion.cmake
│ │ └── CMakeForImGuiTargets.cmake
│ ├── libimgui_demo.a
│ └── libimgui.a
└── share
└── Dear ImGui
├── docs
│ ├── BACKENDS.md
│ ├── CHANGELOG.txt
│ ├── CONTRIBUTING.md
│ ├── EXAMPLES.md
│ ├── FAQ.md
│ ├── FONTS.md
│ ├── README.md
│ └── TODO.txt
└── LICENSE.txt
this time client specifies which components to use:
find_package(CMakeForImGui REQUIRED COMPONENTS glfw vulkan)
# ...
target_link_libraries(tgt Unofficial::DearImGui::imgui)
ImGui examples used with this approach can be seen in here.
This approach also has a downside, some libraries doesn't like the be merged into the same target, specifically SDL2 and SDL3 in my experience, but the client probably will be using either one of them anyway... so it shouldn't be big a concern.
I know it's not the first one to add CMake, there are prominent attempts like this and this and lots of them can be found on quick search and probably some others in there is not public. I can't claim any expertise on CMake and ImGui :) so feedbacks are appreciated and we can pivot into that direction and do the things required. Thanks a lot..!
Screenshots/Video:
No response