Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

pinwhell
Copy link

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.

@pinwhell
Copy link
Author

pinwhell commented Sep 17, 2024

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 imgui root include folder in such a way that includes goes:

#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: Imgui already follows a flat looking convention when referring to includes, for example imgui consistently follows a pattern of prefixing its files with imgui_ thus suggesting that the proper decision would be to simply install the flat imgui includes that comes already namespaced in a way, i believe making the equivalence of having a imgui include folder in the installed include directory, on top of this project using imgui would benefit, by not breaking on a new convention, they will still see the flat convention as usual.

the aim is to have minimum amount of change and maximum amount of consistency.

@pinwhell
Copy link
Author

pinwhell commented Sep 18, 2024

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 imgui modules!

// 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 Freetype etc!)

@pinwhell pinwhell changed the title Add lightweight CMake setup for modular and scalable build configuration Lightweight, Modular CMake Integration for ImGui Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants