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

[imgui-sfml] Add new package ImGui-SFML #7429

Merged
merged 5 commits into from
Sep 3, 2019

Conversation

tntxtnt
Copy link
Contributor

@tntxtnt tntxtnt commented Jul 25, 2019

  • Static build only to match with imgui.

Copy link

@eliasdaler eliasdaler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the PR. I feel like having ImGui-SFML on vcpkg would be helpful.
However, I feel like some things can be improved and maybe there'll be less patches required if ImGui-SFML fixes some of the problems you've had to work around.

)

+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is C++11 required? ImGui-SFML, ImGui and SFML can build with C++03 just fine.

Copy link
Contributor Author

@tntxtnt tntxtnt Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow in the x64-osx build I got this error:

In file included from /Users/vagrant/azure_agent/_work/3/s/buildtrees/imgui-sfml/src/v2.0.2-d5398dcc0e/imgui-SFML.cpp:2:
/Users/vagrant/azure_agent/_work/3/s/installed/x64-osx/include/imgui.h:192:5: error: delegating constructors are permitted only in C++11
    IM_VEC4_CLASS_EXTRA     // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec4.
    ^~~~~~~~~~~~~~~~~~~
/Users/vagrant/azure_agent/_work/3/s/buildtrees/imgui-sfml/src/v2.0.2-d5398dcc0e/imconfig-SFML.h:22:11: note: expanded from macro 'IM_VEC4_CLASS_EXTRA'
        : ImVec4(c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f) {  \
          ^~~~~~

error: delegating constructors are permitted only in C++11

So I add C++11 to your CMakeLists. It's from imgui.h (?), I don't know why only x64-osx build failed with this. This is a quick and dirty patch to solve this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so in imconfig-SFML.h you use delegating constructors, which is a C++11 feature:

#define IM_VEC4_CLASS_EXTRA                                             \
    ImVec4(const sf::Color & c)                                         \
        : ImVec4(c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f) {  \
    }                                                                   \

Could be (badly 😄) rewritten to:

#define IM_VEC4_CLASS_EXTRA                                             \
    ImVec4(const sf::Color & c)                                         \
        : x(c.r / 255.f), y(c.g / 255.f), z(c.b / 255.f), w(c.a / 255.f) {  \
    }                                                                   \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be fixed in ImGui-SFML - will do!


# For FindImGui.cmake
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is necessary.

Copy link
Contributor Author

@tntxtnt tntxtnt Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to use 1 line of vcpkg's find_package(imgui REQUIRED) and target_link_libraries(... imgui::imgui) to include imgui library, so I disable all of your FindImgui cmake as they are not needed (I guess)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should put a check for osx triplet and enable C++11 for osx build only.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, FindImGui.cmake is not needed, if you use vcpkg's find module, but it won't really change anything, so I think to make patch smaller, this line should not be changed with it.

Also I might put some other useful CMake things in imgui-sfml's "cmake" directory, so this might break some other things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imgui-sfml needs these sources

set(IMGUI_SOURCES
  ${IMGUI_INCLUDE_DIR}/imgui.cpp
  ${IMGUI_INCLUDE_DIR}/imgui_draw.cpp
  ${IMGUI_INCLUDE_DIR}/imgui_widgets.cpp
  ${IMGUI_INCLUDE_DIR}/misc/cpp/imgui_stdlib.cpp
)

set(IMGUI_DEMO_SOURCES
  ${IMGUI_INCLUDE_DIR}/imgui_demo.cpp
)

while vcpkg's imgui CMakeLists.txt has these compiled

set(IMGUI_SOURCES
    imgui.cpp
    imgui_demo.cpp
    imgui_draw.cpp
    imgui_widgets.cpp
)

The only file that is missing is misc/cpp/imgui_stdlib.cpp, which it states that it needs C++11: https://github.com/ocornut/imgui/blob/d057550209d794461744a91c812bf8e9e264f32f/misc/cpp/imgui_stdlib.h#L5

Copy link
Contributor Author

@tntxtnt tntxtnt Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And since vcpkg has those sources already compiled, you won't find these .cpp files, which FindImGui.cmake will create a cmake config error so I don't use it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imgui_stdlib functions don't need C++11 to compile, but they're not guaranteed to work. That's an imporant difference.

As for the sources vs linking to target - yeah. Again, ImGui-SFML needs to add some flags which will allow you to either build ImGui along with ImGui-SFML or link to it in some other way.

- set(IMGUI_DIR "" CACHE PATH "imgui top-level directory")
- message(FATAL_ERROR "ImGui directory not found. Set IMGUI_ROOT to imgui's top-level path (containing 'imgui.h' and other files).\n")
-endif()
+# if(NOT IMGUI_DIR)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does vcpkg set imgui_DIR? Maybe I can just allow users to specify how ImGui should be searched for (e.g. "ImGui" or "imgui"), so we'll have something like this:

if(NOT ${IMGUI_NAME}_DIR)
   ...
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vcpkg imgui doesn't provide version. Someone provided CMakeLists.txt without version: project(imgui CXX)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess checking for version could be disabled in some cases... I'll thunk about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make vcpkg's imgui to export imguiConfigVersion.cmake with write_basic_package_version_file but CMake requires COMPATIBILITY mode which if you choose SameMinorVersion|ExactVersion 1.68 will not be compatible with 1.70, if you choose AnyNewerVersion|SameMajorVersion then 1.00 may be compat with 1.70 which is wrong, as new imgui doesn't guarantee backward compat between minor versions, so SameMinorVersion|ExactVersion should be compat mode here. However that will require imgui-sfml port to change imgui version everytime imgui updates new version, and it doesn't guarantee compatibility with newer verions...

Maybe you should include an exact verison of imgui, i.e. 1.68, in imgui-sfml, and don't depend on system's imgui anymore. Not sure if it's the right thing to do.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImGui is mostly stable in the part that ImGui-SFML uses. ImGui's widgets functions/interfaces can change, but that will break client's ImGui code, not ImGui-SFML's code.
So in my opinion requiring specific version of ImGui doesn't feel right.


# This uses FindImGui.cmake provided in ImGui-SFML repo for now
-find_package(ImGui 1.68 REQUIRED)
+find_package(imgui REQUIRED)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like ${IMGUI_NAME} variable would be useful again. Not sure what to do about the version, maybe vcpkg script for ImGui should set imgui_VERSION and I'll be able to compare it afterwards, not during find_package?

- ${IMGUI_INCLUDE_DIR}/imstb_truetype.h
- ${IMGUI_INCLUDE_DIR}/misc/cpp/imgui_stdlib.h
-)
+# set(IMGUI_PUBLIC_HEADERS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed for patch - yes, it won't be used, but patch should be as minimal as possible, in my opinion.

#if _WIN32
#ifdef IMGUI_SFML_EXPORTS
#define IMGUI_SFML_API __declspec(dllexport)
- #define IMGUI_API __declspec(dllexport)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really affect anything? If ImGui-SFML is compiled statically, then IMGUI_SFML_EXPORTS should not be defined?

#endif
#elif __GNUC__ >= 4
#define IMGUI_SFML_API __attribute__ ((visibility("default")))
- #define IMGUI_API __attribute__ ((visibility("default")))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, maybe I'll need to add #ifndef IMGUI_API before this, but again, I wonder if it really affects anything.

Copy link
Contributor Author

@tntxtnt tntxtnt Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can include them but I think it's kinda weird to define another library's defines when you don't build that library (use vcpkg's imgui) so I removed them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought I should include them since imgui-sfml is imgui's replacement.

@@ -69,31 +69,3 @@ index f66ba20..0f43ce6 100644
-
-#define ImTextureID unsigned int

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line needed? ImTextureID should really be "unsigned int" for ImGui-SFML, not "void*"

Copy link
Contributor Author

@tntxtnt tntxtnt Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It creates a linkage error with static build of vcpkg's imgui. C++ name mangling magic treats imgui static compiled Imgui::Image(... and imgui-sfml Imgui::Image(unsigned int, ... differently so you either have to compile imgui with imgui-sfml (which you can't in this case, vcpkg's static compiled imgui), or don't define it and use imgui's typedef void* ImTextureID;

Maybe include your own version of imgui in imgui-sfml, just need a few files...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Well, I hope that doesn't break something.

Also yeah, it looks like using external 'imgui' package with imgui-sfml is kinda painful... I've thought about adding ImGui as git submodule for ImGui-SFML here: SFML/imgui-sfml#81 ... and maybe it'll make the whole process easier if you don't depend on ImGui's vckpg package.

@dan-shaw
Copy link
Contributor

dan-shaw commented Aug 8, 2019

@tntxtnt @eliasdaler Is this ready to be merged?

@tntxtnt
Copy link
Contributor Author

tntxtnt commented Aug 8, 2019

It's still missing misc/cpp/imgui_stdlib.cpp from imgui port but I think it's ok.

@cenit cenit mentioned this pull request Aug 31, 2019
@dan-shaw dan-shaw merged commit 79b5a9a into microsoft:master Sep 3, 2019
@dan-shaw
Copy link
Contributor

dan-shaw commented Sep 3, 2019

Thanks for the PR! I've merged this, but it may be updated in #8004.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants