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

[Feature request] SDL2 and SDL3 cannot be built together in the same vcpkg build #11920

Open
Agorath opened this issue Jan 12, 2025 · 6 comments
Assignees
Milestone

Comments

@Agorath
Copy link

Agorath commented Jan 12, 2025

I'm not sure if the following is a feature request per se, but here goes.

With the release of SDL3 approaching, ImGui has already implemented backends for SDL3 in general and the new GPU API.
While trying to update the vcpkg port of ImGui to expose these new backends, one of the vcpkg maintainers encountered the issue of it being impossible to build SDL2 and SDL3 in the same vcpkg build. Many of the variables set in the CMakeLists of SDL2 and SDL3 share the same name, and the build thus fails.
Usually, users won't build SDL2 and SDL3 simultaneously. But, with vcpkg automatically including required dependencies, there are strict rules for ports being able to be built without interfering with each other and, in particular, that features exposed by a port, in this case, ImGui, are not to be mutually exclusive.
See here for the whole discussion: microsoft/vcpkg#42850

Thus, is it feasible to modify the CMake scripts of SDL3 so that it can be built alongside SDL2 in the same build process?

@slouken slouken added this to the 3.2.0 milestone Jan 12, 2025
@slouken
Copy link
Collaborator

slouken commented Jan 12, 2025

@madebr, is there something we can do here?

@madebr
Copy link
Contributor

madebr commented Jan 12, 2025

Is this an issue about incompatible INTERFACE_SDL_VERSION?

SDL/CMakeLists.txt

Lines 3456 to 3459 in 9a83fa0

set_property(TARGET SDL3-shared APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL3_SHARED)
set_property(TARGET SDL3-shared PROPERTY INTERFACE_SDL3_SHARED TRUE)
set_property(TARGET SDL3-shared APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
set_property(TARGET SDL3-shared PROPERTY INTERFACE_SDL_VERSION "SDL${SDL3_VERSION_MAJOR}")

I added this protection to avoid a project linking to SDL2::SDL2 (=shared SDL2 library) and SDL3::SDL3-shared simultaneously. That's 100% UB.

@Agorath
Copy link
Author

Agorath commented Jan 12, 2025

Thanks for your quick replies. 🙂

Is this an issue about incompatible INTERFACE_SDL_VERSION?

I believe that's what's happening. This is the error message from the vcpkg build when trying to build ImGui with both the sdl2 and sdl3 backend features enabled:
CMake Error: The INTERFACE_SDL_VERSION property of "SDL3::SDL3-shared" does not agree with the value of SDL_VERSION already determined for "imgui".

I added this protection to avoid a project linking to SDL2::SDL2 (=shared SDL2 library) and SDL3::SDL3-shared simultaneously. That's 100% UB.

Is there an alternative way to make this work, given that vcpkg requires port features to be non-mutually exclusive?

Otherwise, the only other way I can think of would be to create a separate vcpkg port of ImGui that only provides the SDL3 and SDL3GPU backends. However, I suspect that the vcpkg maintainers wouldn't accept such a more or less hack. 🤔

@slouken
Copy link
Collaborator

slouken commented Jan 12, 2025

Does sdl2-compat help here?

@madebr
Copy link
Contributor

madebr commented Jan 12, 2025

Thanks for your quick replies. 🙂

Is this an issue about incompatible INTERFACE_SDL_VERSION?

I believe that's what's happening. This is the error message from the vcpkg build when trying to build ImGui with both the sdl2 and sdl3 backend features enabled: CMake Error: The INTERFACE_SDL_VERSION property of "SDL3::SDL3-shared" does not agree with the value of SDL_VERSION already determined for "imgui".

Indeed, that message is caused by the COMPATIBLE_INTERFACE_STRING "SDL_VERSION.

Is there an alternative way to make this work, given that vcpkg requires port features to be non-mutually exclusive?

You can't link SDL2 and SDL3 together.
You can however let the imgui cmake script build multiple libraries supporting various backends.
e.g.

add_library(imgui STATIC imgui.cpp imgui.h)
target_include_directories(imgui_sdl2 PUBLIC "include")

add_library(imgui_sdl2 STATIC backends/imgui_sdl2.cpp)
target_link_libraries(imgui_sdl2 PUBLIC imgui SDL2::SDL2)
add_library(imgui_sdl2_renderer STATIC backends/imgui_sdl2_renderer.cpp)
target_link_libraries(imgui_sdl2_renderer PUBLIC imgui_sdl2)

add_library(imgui_sdl3 STATIC backends/imgui_sdl3.cpp)
target_link_libraries(imgui_sdl3 PUBLIC imgui SDL3::SDL3)
add_library(imgui_sdl3_renderer STATIC backends/imgui_sdl3_renderer.cpp)
target_link_libraries(imgui_sdl3_renderer PUBLIC imgui_sdl3)
add_library(imgui_sdl3_gpu STATIC backends/imgui_sdl3_gpu.cpp)
target_link_libraries(imgui_sdl3_gpu PUBLIC imgui_sdl3)

add_library(imgui_glfw3 STATIC backends/imgui_glfw3.cpp)
target_link_libraries(imgui_glfw3 PUBLIC imgui glfw3)

add_library(imgui_allegro5 STATIC backends/imgui_allegro5.cpp)
target_link_libraries(imgui_allegro5 PUBLIC imgui allegro5)

Or a variation on this.

Otherwise, the only other way I can think of would be to create a separate vcpkg port of ImGui that only provides the SDL3 and SDL3GPU backends. However, I suspect that the vcpkg maintainers wouldn't accept such a more or less hack. 🤔

That's a no-go. This does not scale.

@Agorath
Copy link
Author

Agorath commented Jan 12, 2025

You can't link SDL2 and SDL3 together. You can however let the imgui cmake script build multiple libraries supporting various backends. e.g.

add_library(imgui STATIC imgui.cpp imgui.h)
target_include_directories(imgui_sdl2 PUBLIC "include")

add_library(imgui_sdl2 STATIC backends/imgui_sdl2.cpp)
target_link_libraries(imgui_sdl2 PUBLIC imgui SDL2::SDL2)
add_library(imgui_sdl2_renderer STATIC backends/imgui_sdl2_renderer.cpp)
target_link_libraries(imgui_sdl2_renderer PUBLIC imgui_sdl2)

add_library(imgui_sdl3 STATIC backends/imgui_sdl3.cpp)
target_link_libraries(imgui_sdl3 PUBLIC imgui SDL3::SDL3)
add_library(imgui_sdl3_renderer STATIC backends/imgui_sdl3_renderer.cpp)
target_link_libraries(imgui_sdl3_renderer PUBLIC imgui_sdl3)
add_library(imgui_sdl3_gpu STATIC backends/imgui_sdl3_gpucpp)
target_link_libraries(imgui_sdl3_gpu PUBLIC imgui_sdl3)

add_library(imgui_glfw3 STATIC backends/imgui_glfw3.cpp)
target_link_libraries(imgui_glfw3 PUBLIC glfw3)

add_library(imgui_allegro5 STATIC backends/imgui_allegro5.cpp)
target_link_libraries(imgui_allegro5 PUBLIC allegro5)

Or a variation on this.

Thank you! I'll have a look at that.

Otherwise, the only other way I can think of would be to create a separate vcpkg port of ImGui that only provides the SDL3 and SDL3GPU backends. However, I suspect that the vcpkg maintainers wouldn't accept such a more or less hack. 🤔

That's a no-go. This does not scale.

I suspected as much. It was a stupid idea born out of frustration. 😅

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

No branches or pull requests

3 participants