-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lightweight, Modular CMake Integration for ImGui #7992
base: master
Are you sure you want to change the base?
Conversation
I had a few doubts, i was unsure, what is the more standard expected way when including backends #include <backends/imgui_impl_xxxxx.h> or directly #include<imgui_impl_xxxxx.h> also, what about, when installing imgui includes, is it supposed to be installed within a #include <imgui/imgui.h>
#include <imgui/xxxx/xxxx.h> or direclty install imgui includes to the destination root include path, in such a way that includes looks like: #include <imgui.h>
#include <imgui_xxxxx.h> Note: the aim is to have minimum amount of change and maximum amount of consistency. |
Example: find_package(imgui REQUIRED)
# or
# add_subdirectory(path/to/imgui)
add_executable(foo foo.cpp)
target_link_libraries(myexec
imgui::core # Core Agnostic Imgui Impl, ex imgui.cpp imgui_tables.cpp ... etc etc
imgui::freetype # Imgui FreeType Implementation
...
imgui::win32 # Imgui Windows Backend
# imgui::opengl2 # Imgui Opengl2 Backend Implementation
imgui::opengl3 # Imgui Opengl3 Backend Implementation
...
) As shown above, everything is very decoupled, concerns are very separated, in a way feels like composing your build with // foo.cpp
#include <imgui.h> // From imgui::core
#include <imgui_impl_win32.h> // From imgui::win32
//#include <imgui_impl_opengl2.h> // From imgui::opengl2
#include <imgui_impl_opengl3.h> // From imgui::opengl3
#include <imgui_freetype.h> // From imgui::freetype
int main()
{
Imgui:: .... ();
} Note: Each component shown above is automatically being linked statically! (including |
Hi, Here are some feedbacks. First, you should purely and solely ignore irrelevant backends for the target system: win32 can be ignored on unices, but it have to be build when cross-compiling for win32. From memory, the target system name is in Next, why not having all options set to Having messages to tell which backends are enabled/disabled would be helpful too. Fixing the indentation for all The files As I'm not used to the logic behind the files xxx-target.cmake, does it permit to set wanted components when calling My CMake files used to look like: find_package(Qt5 COMPONENTS Core Gui Wigets REQUIRED)
...
add_executable(MyProgram ...)
target_link_libraries(MyProgram PUBLIC Qt5::Core Qt5::Gui Qt5::Wigets) In case of imgui as a subproject, I would expect to write something like: add_subdirectory(subprojects/imgui)
...
find_package(imgui COMPONENTS sdl2 vulkan REQUIRED)
...
add_executable(MyAmazingProgram ...)
target_link_libraries(MyAmazingProgram PUBLIC imgui::core imgui::sdl2 imgui::vulkan) To make it work, your main CMakeLists.txt could have some code like: ...
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# in main project mode
include(GNUInstallDirs)
set(IMGUI_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(IMGUI_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
else()
# in subproject mode
set(imgui_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
set(IMGUI_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(IMGUI_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
# generate the cmake script with IMGUI_LIB_DIR, IMGUI_INC_DIR and many other variables
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/imgui-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/imgui-config.cmake")
... The trick is the line About the includes, I would say the 2 are expected (depending on the circumstances):
And I also think mes 2¢ |
This commit introduces a minimal and clean
CMake
setup aimed at maintaining the simplicity of the project. The goal is to provide a foundation for modular build configurations, allowing for future additions (e.g.,backend implementations
,examples
) without introducing bloat.