CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Add CMake project #1713
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
base: master
Are you sure you want to change the base?
Add CMake project #1713
Conversation
Note that i’ve been refactoring examples as part of the default branch, and will probably end up providing both premake and cmake files for the examples/ bits. |
@franciscod, thanks for links. Now I have some ground to think about. |
956884f
to
57e2612
Compare
Hi @ocornut, I implement idea to share |
@podgorskiy I understand why cmake is used. I personally think it's unnecessary for imgui as the point of the library is that you can register the .cpp file in your application and I encourage you to do so (you can add imgui cpp files from your main app cmake file). Surely registering a few cpp files in your project shouldn't be harder than maintaining and registering a separate cmake file from your project?
It is a little harmful as it prevents people from configuring ImGui for their application via That said, to provide the example applications I will maintain premake/cmake, but I won't tackle that until the examples are refactored in a later version. Your cmake references will be useful here. Thank you! Also note that your PR also mix and matches multiple unrelated changes in a single commit so it's hard to review or pull. |
GLboolean imgui_GL_ENABLE_BIT_was_enabled = glIsEnabled(GL_ENABLE_BIT); | ||
GLboolean imgui_GL_COLOR_BUFFER_BIT_was_enabled = glIsEnabled(GL_COLOR_BUFFER_BIT); | ||
GLboolean imgui_GL_TRANSFORM_BIT_was_enabled = glIsEnabled(GL_TRANSFORM_BIT); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The emscripten changes are unrelated to the title and intended purpose of the PR. They are useful are a reference because I would like to support emscripten more easily (also see #336).
However note that your replacement code for glPushAttrib()
is incorrect.
glPushAttrib(GL_ENABLE_BIT)
alone with old style GL saves a lot more thing.
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glPushAttrib.xml
I would recommend using another breed of OpenGL for the Emscripten examples, or just skipping this push/pop for now.
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED)) | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be justified more thoroughly, the and code can be written with a single point of interference.
e.g.
#ifndef __EMSCRIPTEN__
const bool focused = glfwGetWindowAttrib(g_Window, GLFW_FOCUSED);
#else
const bool focused = true;
#endif
if (focused)
...
examples/opengl2_example/main.cpp
Outdated
|
||
// Main loop | ||
#ifdef __EMSCRIPTEN__ | ||
emscripten_set_main_loop(step, 0, 1); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little annoying but I understand this is how emscripten works. I took a note to consider changing the examples to accommodate for this a little more easily.
FYI I made some comments but don't worry about reworking or splitting the PR. Since the examples are being refactored in the viewport branch, I won't be able take this PR soon. But I will pull the cmake/emscripten information from it so it is useful. Thanks again! |
Just to play an advocate, I hate hate hate pulling in dependency code directly into my projects as it pollutes my repositories with code that is not mine to maintain. As for ease of use, with cmake when I want to bring in a dependency then I'll add something like this in my CMake file (I'm using boost compiled libraries as an example as those are generally fairly painful otherwise, this shows the ease of use): hunter_add_package(Boost COMPONENTS system filesystem) At this point all the files needed for the system and filesystem parts of boost are downloaded and compiled at the default version in my linked repo (latest stable, others are available, and I can specify a version on the above line if you want a specific version that is older than the one in the dep lock file). I then use it like any other library: find_package(Boost CONFIG REQUIRED system filesystem)
target_link_libraries(my_project Boost::system Boost::filesystem) And that's it. To specify a lock file I just do: HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.16.15.tar.gz"
SHA1 "6974c2150fc0d3b09de3ad1efcbf15d360647ffa"
) And I can use multiple lock files if I so wish, which are combined in order as specified (so, just as an example, imgui could have it's own lock files of it's own versions if it didn't want to be listed in the main 'main' hunter dependency repository). If imgui could be built as a bog-standard cmake system then it could be added to such a repository system with trivial ease. There can be many versions of imgui there-of in the dependency system, for different branches, different actual versions, could be broken up into component parts or not, and the user doesn't have to worry about the API ever changing until they actually update HunterGate call's and/or change the version listed, it is very reproducible builds all while keeping third-party code out of your own code repository. |
@@ -129,12 +136,30 @@ void ImGui_ImplGlfwGL2_RenderDrawData(ImDrawData* draw_data) | |||
glDisableClientState(GL_COLOR_ARRAY); | |||
glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||
glDisableClientState(GL_VERTEX_ARRAY); | |||
#ifdef __EMSCRIPTEN__ | |||
if(last_texture) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ocornut pay attention to this too. Without this check I have problem to draw custom scene.
@ocornut, I review changes in It's okay that my changes can not be applied right now. We live in an era of change and this is normal. I am glad that there is a discussion on an interesting topic for me and that the results can be useful for everyone. I also think that I need to take into account the experience of @tamaskenez. |
By the way, about the changes: what about moving the Demo functions in a separate header (for example, |
Rebase on Dear @ocornut, please review again and merge if possible. Now possible install ImGui like:
Then copy example directory (for example example_glfw_opengl2) and use it as base for custom project. |
Rebase on Dear @ocornut, please review again and merge if possible. Now implemented: Export targets:
Import targets from:
Examples:
|
Sorry I don't know when I can look at this in great details yet, but this looks solid. Thanks!
|
Short ansver for |
Ok. I will rename |
Technically I can implement everything in one file, but it will be difficult to understand. |
Hi all! You are all right! It's hard for me to please everyone all at once. I am a supporter of incremental improvements. Let's say the Christmas miracle happens and basic CMake support is added, then the community can improve it. Let's... :-) |
I don’t think those efforta are going to waste. The cmake pr and repos exist for this purpose. I am not against helping to make this more visible somehow. Compiling/Linking with core Dear ImGui (without backends) is trivial. The problem is compiling/linking with dependencies required by backends. In principle if you have your own app running, you should ALREADY have a way to use those dependencies. It is tremendously difficult to provide a cmake that will nicely overlap with the myriad of ways those dependencies can be used and obtained. It is a problem for the Windows ecosystem mostly. If only Linux/osx existed providing those cmakefiles would likely be easier. Third-party cmakefiles have the advantage that if they don’t work with your setup you are more likely to sidestep the problem. I think most people complaining about the lack of an official cmakefile are misunderstanding this difficulty and the constraints they would add. @eliasdaler also wanted to make this happen at some point and ended up thinking it wasn’t easy to solve. |
Yeah, I've tried here but eventually gave up. But for Dear ImGui itself - not really, it just has so many "manual" configuration tweaks that expressing it in CMake build script would be a huge burden to maintain. I had quite a lot of problems maintaining my own ImGui-SFML's CMake build... now imagine maintaining 5+ builds at once. |
FYI in 1b27ac9 i have renamed imgui_impl_sdl.cpp to imgui_impl_sdl2.cpp as SDL3 is down the road (and we have a backend for SDL3 now). I wouldn't suggest bothering with the SDL3 part of building as the library is not going to be out for a while, but applying the renaming of the SDL2 backend will be needed. |
Thanks for mentioning it here. I'll keep that in mind for the next update. |
I have rebased this branch on latest:
I didn't push intermediary names e.g. Again, apologize for leaving that dangling. It's unlikely that I can devote full energy to this soon but one day I will. In the meanwhile it's nice having that cherry pickable commit for some people I suppose. |
Rebased on latest release 1.91.7 |
I don't know why this PR can't be merged so long? |
The The |
Rebased on latest release v1.91.8. |
Rebased on latest release v1.91.9. Updated examples live preview. |
Rebased on latest release v1.91.9b. Updated examples live preview. |
Export Dear ImGui as CMake's ImGui package. Options: - ImGui_USER_CONFIG; - ImGui_EXAMPLES; - ImGui_BACKENDS; - ImGui_MISC; - ImGui_3RDPARTY; - ImGui_OPENGL_LOADER; - ImGui_FREETYPE; - ImGui_TOOLS; - ImGui_PACKAGE. Export targets: - ImGui::Core; - ImGui::ImplGLUT; - ImGui::ImplSDL2; - ImGui::ImplSDLRenderer2; - ImGui::ImplSDL3; - ImGui::ImplSDLRenderer3; - ImGui::ImplGlfw; - ImGui::ImplOpenGL2; - ImGui::ImplOpenGL3; - ImGui::ImplVulkan; - ImGui::FreeType; - ImGui::StdLib; - ImGui::BinaryToCompressedC. Import targets from: - build directory; - installed package. Examples: - example_null; - example_glut_opengl2 - example_sdl2_sdlrenderer2; - example_sdl2_opengl2; - example_sdl2_opengl3; - example_sdl2_vulkan; - example_sdl3_sdlrenderer3; - example_sdl3_opengl3; - example_sdl3_vulkan; - example_glfw_opengl2; - example_glfw_opengl3; - example_glfw_vulkan. Presets: - vcpkg (require $env{VCPKG_ROOT}); - emscripten (inherits vcpkg and require $env{EMSCRIPTEN_ROOT}).
Rebased on latest release v1.92.0. Bump minimum required CMake version to 3.5. Updated examples live preview. |
If author won't accept this, we might able to release this in another unofficial repo which only have this changes? |
I don't know what's best personally. |
External repo could fetch Dear ImGui code through ExternalProject (without build step) and implement build as necessary. No complicated rebases necessary. |
Just to be clear:
The problem on my end is that presently if I accepted this into master, it would mean people would increasingly rely on it, and support/maintenance of all building issues would fall on me. And my opinion this is opening a pandora box of problems. This has been corroborated by some discussions on X/BlueSky with other OSS maintainers suggesting that the experience of merging a CMakefile only increased the amount of building problems submitted by users. That said I am obviously in favor of making things easier for users, and it is great that this exist. But I sincerely don't know what is the best way to move forward. If Konstantin wants to maintain an I don't know what cmake allows in term of package "fetching" but the core problem is that we want to make it flexible how/where people acquire their packages. Things are easy if you are e.g. 100% in vcpkg land. But some may want to use SDL3 binaries, some may want to fetch from git/web and build it from sources, some may want to vendor it and build it, some get it from I am also generally not well equipped because I have little experience in CMake languages and idioms. I am not ruling out that I will eventually get on that board (especially if I try to spend more time in MacOS land). |
Add CMake project
Now implemented:
Export Dear ImGui as CMake's ImGui package.
Options:
Export targets:
Import targets from:
Examples:
[NEW] Presets:
Users can easy link ImGui::XXX or ImGui::ImplXXX libraries and use example binding
implementation ore other misc features in custom projects.
Tested with MinGW-w64, MSVC, Emscripten.
Live Preview