From 8ba63fb0eae159d6d0cefe073a1619d8d234d1de Mon Sep 17 00:00:00 2001 From: MicroBlock <66859419+std-microblock@users.noreply.github.com> Date: Sun, 13 Oct 2024 03:59:27 +0800 Subject: [PATCH] Remove OpenGL::GL dependency for GL3 backends (#684) Co-authored-by: Michael Ragazzon --- Backends/CMakeLists.txt | 10 +++++++--- CMake/DependenciesForBackends.cmake | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Backends/CMakeLists.txt b/Backends/CMakeLists.txt index 49d6469ad..22c2c70e5 100644 --- a/Backends/CMakeLists.txt +++ b/Backends/CMakeLists.txt @@ -70,12 +70,16 @@ target_sources(rmlui_backend_SDL_GL3 INTERFACE "${CMAKE_CURRENT_LIST_DIR}/RmlUi_Renderer_GL3.h" "${CMAKE_CURRENT_LIST_DIR}/RmlUi_Include_GL3.h" ) -target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE rmlui_backend_common_headers OpenGL::GL SDL2::SDL2 SDL2_image::SDL2_image) +target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE rmlui_backend_common_headers SDL2::SDL2 SDL2_image::SDL2_image) if(UNIX) # The OpenGL 3 renderer implementation uses dlopen/dlclose # This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE ${CMAKE_DL_LIBS}) endif() +if(EMSCRIPTEN) + # Only Emscripten requires linking to OpenGL::GL, for other platforms we use 'glad' as an OpenGL loader. + target_link_libraries(rmlui_backend_SDL_GL3 INTERFACE OpenGL::GL) +endif() add_library(rmlui_backend_SDL_VK INTERFACE) target_sources(rmlui_backend_SDL_VK INTERFACE @@ -135,7 +139,7 @@ target_sources(rmlui_backend_GLFW_GL3 INTERFACE "${CMAKE_CURRENT_LIST_DIR}/RmlUi_Renderer_GL3.h" "${CMAKE_CURRENT_LIST_DIR}/RmlUi_Include_GL3.h" ) -target_link_libraries(rmlui_backend_GLFW_GL3 INTERFACE rmlui_backend_common_headers OpenGL::GL glfw) +target_link_libraries(rmlui_backend_GLFW_GL3 INTERFACE rmlui_backend_common_headers glfw) if(UNIX) # The OpenGL 3 renderer implementation uses dlopen/dlclose # This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime @@ -177,7 +181,7 @@ target_sources(rmlui_backend_BackwardCompatible_GLFW_GL3 INTERFACE "${CMAKE_CURRENT_LIST_DIR}/RmlUi_BackwardCompatible/RmlUi_Renderer_BackwardCompatible_GL3.h" "${CMAKE_CURRENT_LIST_DIR}/RmlUi_BackwardCompatible/RmlUi_Backend_BackwardCompatible_GLFW_GL3.cpp" ) -target_link_libraries(rmlui_backend_BackwardCompatible_GLFW_GL3 INTERFACE rmlui_backend_common_headers OpenGL::GL glfw) +target_link_libraries(rmlui_backend_BackwardCompatible_GLFW_GL3 INTERFACE rmlui_backend_common_headers glfw) if(UNIX) # The OpenGL 3 renderer implementation uses dlopen/dlclose # This is required in some UNIX and UNIX-like operating systems to load shared object files at runtime diff --git a/CMake/DependenciesForBackends.cmake b/CMake/DependenciesForBackends.cmake index 934c02b54..37386349e 100644 --- a/CMake/DependenciesForBackends.cmake +++ b/CMake/DependenciesForBackends.cmake @@ -163,7 +163,9 @@ if(RMLUI_BACKEND MATCHES "GL2$") report_dependency_found_or_error("OpenGL" OpenGL::GL) endif() -if(RMLUI_BACKEND MATCHES "GL3$") +# We use 'glad' as an OpenGL loader for GL3 backends, thus we don't normally need to link to OpenGL::GL. The exception +# is for Emscripten, where we use a custom find module to provide OpenGL support. +if(EMSCRIPTEN AND RMLUI_BACKEND MATCHES "GL3$") find_package("OpenGL" "3") report_dependency_found_or_error("OpenGL" OpenGL::GL) endif()