Fix OpenGL vs. GLESv2 linkage, attempt number three

We introduced WrapOpenGL to link against either desktop GL or GLESv2
depending on the GL feature in QtGui. This works "fine", with two
caveats:

    (1) find_package(WrapOpenGL) must be called after
    find_package(Qt5Gui) in order for the feature check in
    FindWrapOpenGL.cmake to work. That's error prone.

    (2) More and more places are popping up, in particular examples,
    where GL linkage is required due to inline functions in Qt that
    forward to GL functions - such as on Android.

    This in particular explains the qmake behavior of making the GL
    linkage (desktop _or_ GLES) a public dependency of QtGui, so only
    Gui linkage is required.

Those two aspects combined are the nail in the coffin of FindWrapOpenGL
and it would seem much easier to simply make the Desktop GL vs. GLES
decision once in Gui's CMakeLists.txt and let Qt5GuiDependencies.cmake
propagate this well. This allows us to get rid of plenty of special
cases as well.

Change-Id: I3a7e8af49537ce5f215f24470e075a4ae9aeb944
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Simon Hausmann 2019-06-05 10:46:16 +02:00
parent 2eeba9f55f
commit 38cd18384f
9 changed files with 12 additions and 50 deletions

View File

@ -1,20 +0,0 @@
# Logic derived from mkspecs/features/unix/opengl.prf: prefer GLESv2 over GL
if(TARGET WrapOpenGL)
set(WrapOpenGL_FOUND ON)
return()
endif()
add_library(WrapOpenGL INTERFACE IMPORTED)
if(QT_FEATURE_opengles2)
find_package(GLESv2)
target_link_libraries(WrapOpenGL INTERFACE GLESv2::GLESv2)
else()
find_package(OpenGL)
target_link_libraries(WrapOpenGL INTERFACE OpenGL::GL)
endif()
set(WrapOpenGL_FOUND ON)
set_property(TARGET WrapOpenGL PROPERTY IMPORTED_GLOBAL TRUE)

View File

@ -1,6 +1,5 @@
# Generated from boxes.pro. # Generated from boxes.pro.
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL) # special case
##################################################################### #####################################################################
## boxes Binary: ## boxes Binary:
##################################################################### #####################################################################
@ -22,7 +21,6 @@ add_qt_executable(boxes
LIBRARIES LIBRARIES
Qt::OpenGL Qt::OpenGL
Qt::Widgets Qt::Widgets
WrapOpenGL
) )
# Resources: # Resources:

View File

@ -336,12 +336,20 @@ extend_target(Gui CONDITION QT_FEATURE_standarditemmodel
# special case begin # special case begin
# With qmake, gui's opengl.pri used CONFIG += opengl, where opengl.prf # With qmake, gui's opengl.pri used CONFIG += opengl, where opengl.prf
# acted like WrapOpenGL: direct linkage against either libGLESv2 or # used direct public linkage against either libGLESv2 or libGL, depending
# libGL, depending on the opengl _feature_. This is done by hand now # on the opengl _feature_. This is done by hand now here (where the
# here (where the feature is available). # feature is available).
# DO NOT MOVE THIS TO THE BEGINNING OF THE FILE, the feature variables are not # DO NOT MOVE THIS TO THE BEGINNING OF THE FILE, the feature variables are not
# available until the add_qt_module call. # available until the add_qt_module call.
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL) if(QT_FEATURE_opengl)
if(QT_FEATURE_opengles2)
find_package(GLESv2)
target_link_libraries(Gui PUBLIC GLESv2::GLESv2)
else()
find_package(OpenGL)
target_link_libraries(Gui PUBLIC OpenGL::GL)
endif()
endif()
# special case end # special case end
extend_target(Gui CONDITION QT_FEATURE_opengl extend_target(Gui CONDITION QT_FEATURE_opengl
@ -376,20 +384,8 @@ extend_target(Gui CONDITION QT_FEATURE_opengl
opengl/qopenglversionfunctions.cpp opengl/qopenglversionfunctions.h opengl/qopenglversionfunctions.cpp opengl/qopenglversionfunctions.h
opengl/qopenglversionfunctionsfactory.cpp opengl/qopenglversionfunctionsfactory_p.h opengl/qopenglversionfunctionsfactory.cpp opengl/qopenglversionfunctionsfactory_p.h
opengl/qopenglvertexarrayobject.cpp opengl/qopenglvertexarrayobject.h opengl/qopenglvertexarrayobject.cpp opengl/qopenglvertexarrayobject.h
LIBRARIES # special case
WrapOpenGL # special case
) )
# special case begin
# qopenglfunctions.h on Android does not use the function
# table indirection for calls but calls ::glFoo in inline functions
# directly. That means the GL library is a public dependency.
extend_target(Gui CONDITION QT_FEATURE_opengl AND ANDROID
PUBLIC_LIBRARIES
WrapOpenGL
)
# special case end
#### Keys ignored in scope 2:.:.:gui.pro:QT_FEATURE_opengl: #### Keys ignored in scope 2:.:.:gui.pro:QT_FEATURE_opengl:
# MODULE_CONFIG = "opengl" # MODULE_CONFIG = "opengl"

View File

@ -30,7 +30,6 @@ add_qt_module(OpenGL
Qt::CorePrivate Qt::CorePrivate
Qt::GuiPrivate Qt::GuiPrivate
Qt::WidgetsPrivate Qt::WidgetsPrivate
WrapOpenGL # special case
PUBLIC_LIBRARIES PUBLIC_LIBRARIES
Qt::Core Qt::Core
Qt::Gui Qt::Gui

View File

@ -1,7 +1,6 @@
# Generated from glxconvenience.pro. # Generated from glxconvenience.pro.
qt_find_package(X11) # special case qt_find_package(X11) # special case
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL) # special case
##################################################################### #####################################################################
## GlxSupport Module: ## GlxSupport Module:
@ -14,7 +13,6 @@ add_qt_module(GlxSupport
DEFINES DEFINES
QT_NO_CAST_FROM_ASCII QT_NO_CAST_FROM_ASCII
LIBRARIES LIBRARIES
WrapOpenGL # special case
Qt::CorePrivate Qt::CorePrivate
Qt::GuiPrivate Qt::GuiPrivate
X11::X11 # special case X11::X11 # special case

View File

@ -2,7 +2,6 @@
# special case: # special case:
qt_find_package(Cups PROVIDED_TARGETS Cups::Cups) qt_find_package(Cups PROVIDED_TARGETS Cups::Cups)
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL)
##################################################################### #####################################################################
## qcocoa Plugin: ## qcocoa Plugin:
@ -92,8 +91,6 @@ add_qt_resource(qcocoa "qcocoaresources" PREFIX "/qt-project.org/mac/cursors" FI
extend_target(qcocoa CONDITION QT_FEATURE_opengl # special case extend_target(qcocoa CONDITION QT_FEATURE_opengl # special case
SOURCES SOURCES
qcocoaglcontext.h qcocoaglcontext.mm qcocoaglcontext.h qcocoaglcontext.mm
LIBRARIES
WrapOpenGL # special case
) )
extend_target(qcocoa CONDITION QT_FEATURE_vulkan extend_target(qcocoa CONDITION QT_FEATURE_vulkan

View File

@ -1,5 +1,4 @@
qt_find_package(EGL) # special case qt_find_package(EGL) # special case
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL) # special case
##################################################################### #####################################################################
## EglFSDeviceIntegration Module: ## EglFSDeviceIntegration Module:
@ -30,7 +29,6 @@ add_qt_module(EglFSDeviceIntegration
Qt::ServiceSupportPrivate Qt::ServiceSupportPrivate
Qt::ThemeSupportPrivate Qt::ThemeSupportPrivate
EGL::EGL # special case EGL::EGL # special case
WrapOpenGL # special case
) )
#### Keys ignored in scope 2:.:./eglfsdeviceintegration.pro:<NONE>: #### Keys ignored in scope 2:.:./eglfsdeviceintegration.pro:<NONE>:

View File

@ -1,7 +1,5 @@
# Generated from minimalegl.pro. # Generated from minimalegl.pro.
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL) # special case
##################################################################### #####################################################################
## qminimalegl Plugin: ## qminimalegl Plugin:
##################################################################### #####################################################################
@ -21,7 +19,6 @@ add_qt_plugin(qminimalegl
Qt::EventDispatcherSupportPrivate Qt::EventDispatcherSupportPrivate
Qt::FontDatabaseSupportPrivate Qt::FontDatabaseSupportPrivate
Qt::EglSupportPrivate Qt::EglSupportPrivate
WrapOpenGL
# CONFIG = "egl" # CONFIG = "egl"
# OTHER_FILES = "minimalegl.json" # OTHER_FILES = "minimalegl.json"
# PLUGIN_CLASS_NAME = "QMinimalEglIntegrationPlugin" # PLUGIN_CLASS_NAME = "QMinimalEglIntegrationPlugin"

View File

@ -9,7 +9,6 @@ if(NOT TARGET Qt::Test)
# Find a few packages that are usually found in configure.cmake, # Find a few packages that are usually found in configure.cmake,
# because a few tests link directly against those libraries. # because a few tests link directly against those libraries.
qt_find_package(WrapDBus1 PROVIDED_TARGETS dbus-1) qt_find_package(WrapDBus1 PROVIDED_TARGETS dbus-1)
qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL)
endif() endif()
# special case end # special case end