Changeset 290138 in webkit


Ignore:
Timestamp:
Feb 18, 2022, 10:12:06 AM (4 years ago)
Author:
Adrian Perez de Castro
Message:

[CMake] Cannot find OpenGL when system provides opengl.pc instead of gl.pc
https://bugs.webkit.org/show_bug.cgi?id=236592

Reviewed by Michael Catanzaro.

.:

  • Source/cmake/FindOpenGL.cmake: Rewrite to use imported targets, try the "opengl" and "glx"

pkg-config modules first, otherwise keep the existing logic that tried the "gl" pkg-config
module with fallbacks to find_path/find_library.

  • Source/cmake/OptionsGTK.cmake: Check for the presence of the OpenGL::GLX target instead of

te GLX_FOUND variable.

Source/ThirdParty/ANGLE:

  • PlatformGTK.cmake: Use the OpenGL::OpenGL imported target instead of the

OPENGL_LIBRARIES variable.

  • PlatformWPE.cmake: Remove linking againt OpenGL libraries; the WPE port is not

supposed to link to any of them directly.

Source/WebCore:

  • CMakeLists.txt: Use the OpenGL::OpenGL and OpenGL::GLX imported targets instead of variables.
  • platform/graphics/GLContext.cpp: Move here includes for the GL headers.
  • platform/graphics/GLContext.h: Remove includes for the GL headers, none of their

declarations are used here; instead include only the needed EGL headers to get the
definition of EGLNativeWindowType.

Source/WebKit:

  • CMakeLists.txt: Remove usage of the OPENGL_ variables for the WebKit target, which is

uneeded because it links to WebCore, which transitively pulls the needed libraries now
that imported targets are being used.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r290002 r290138  
     12022-02-18  Adrian Perez de Castro  <aperez@igalia.com>
     2
     3        [CMake] Cannot find OpenGL when system provides opengl.pc instead of gl.pc
     4        https://bugs.webkit.org/show_bug.cgi?id=236592
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * Source/cmake/FindOpenGL.cmake: Rewrite to use imported targets, try the "opengl" and "glx"
     9        pkg-config modules first, otherwise keep the existing logic that tried the "gl" pkg-config
     10        module with fallbacks to find_path/find_library.
     11        * Source/cmake/OptionsGTK.cmake: Check for the presence of the OpenGL::GLX target instead of
     12        te GLX_FOUND variable.
     13
    1142022-02-17  Commit Queue  <commit-queue@webkit.org>
    215
  • trunk/Source/ThirdParty/ANGLE/ChangeLog

    r290118 r290138  
     12022-02-18  Adrian Perez de Castro  <aperez@igalia.com>
     2
     3        [CMake] Cannot find OpenGL when system provides opengl.pc instead of gl.pc
     4        https://bugs.webkit.org/show_bug.cgi?id=236592
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * PlatformGTK.cmake: Use the OpenGL::OpenGL imported target instead of the
     9        OPENGL_LIBRARIES variable.
     10        * PlatformWPE.cmake: Remove linking againt OpenGL libraries; the WPE port is not
     11        supposed to link to any of them directly.
     12
    1132022-02-18  Zan Dobersek  <zdobersek@igalia.com>
    214
  • trunk/Source/ThirdParty/ANGLE/PlatformGTK.cmake

    r290118 r290138  
    3434
    3535    if (USE_OPENGL)
    36         list(APPEND ANGLEGLESv2_LIBRARIES ${OPENGL_LIBRARIES})
     36        list(APPEND ANGLEGLESv2_LIBRARIES OpenGL::OpenGL)
    3737    else ()
    3838        list(APPEND ANGLEGLESv2_LIBRARIES OpenGL::GLES)
  • trunk/Source/ThirdParty/ANGLE/PlatformWPE.cmake

    r290118 r290138  
    3333        Threads::Threads
    3434    )
    35 
    36     if (USE_OPENGL)
    37         list(APPEND ANGLEGLESv2_LIBRARIES ${OPENGL_LIBRARIES})
    38     else ()
    39         list(APPEND ANGLEGLESv2_LIBRARIES ${OPENGLES_LIBRARIES})
    40     endif ()
    4135endif ()
  • trunk/Source/WebCore/CMakeLists.txt

    r290129 r290138  
    17051705else ()
    17061706    if (USE_OPENGL)
    1707         list(APPEND WebCore_SYSTEM_INCLUDE_DIRECTORIES
    1708             ${OPENGL_INCLUDE_DIRS}
    1709         )
    1710         list(APPEND WebCore_LIBRARIES
    1711             ${OPENGL_LIBRARIES}
    1712         )
    1713         add_definitions(${OPENGL_DEFINITIONS})
     1707        list(APPEND WebCore_LIBRARIES OpenGL::OpenGL)
     1708        if (TARGET OpenGL::GLX)
     1709            list(APPEND WebCore_LIBRARIES OpenGL::GLX)
     1710        endif ()
    17141711    elseif (USE_OPENGL_ES)
    17151712        list(APPEND WebCore_LIBRARIES OpenGL::GLES)
  • trunk/Source/WebCore/ChangeLog

    r290133 r290138  
     12022-02-18  Adrian Perez de Castro  <aperez@igalia.com>
     2
     3        [CMake] Cannot find OpenGL when system provides opengl.pc instead of gl.pc
     4        https://bugs.webkit.org/show_bug.cgi?id=236592
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * CMakeLists.txt: Use the OpenGL::OpenGL and OpenGL::GLX imported targets instead of variables.
     9        * platform/graphics/GLContext.cpp: Move here includes for the GL headers.
     10        * platform/graphics/GLContext.h: Remove includes for the GL headers, none of their
     11        declarations are used here; instead include only the needed EGL headers to get the
     12        definition of EGLNativeWindowType.
     13
    1142022-02-18  Peng Liu  <peng.liu6@apple.com>
    215
  • trunk/Source/WebCore/platform/graphics/GLContext.cpp

    r290002 r290138  
    2626#include <wtf/text/StringToIntegerConversion.h>
    2727
     28#if USE(LIBEPOXY)
     29#include <epoxy/gl.h>
     30#elif USE(OPENGL_ES)
     31#include <GLES2/gl2.h>
     32#else
     33#include "OpenGLShims.h"
     34#endif
     35
    2836#if USE(EGL)
    2937#include "GLContextEGL.h"
  • trunk/Source/WebCore/platform/graphics/GLContext.h

    r290002 r290138  
    2525#include <wtf/Noncopyable.h>
    2626
     27#if USE(EGL) && !PLATFORM(GTK)
     28// FIXME: For now default to the GBM EGL platform, but this should really be
     29// somehow deducible from the build configuration. This is needed with libepoxy
     30// as it could have been configured with X11 support enabled, resulting in
     31// transitive inclusions of headers with definitions that clash with WebCore.
     32#define __GBM__ 1
    2733#if USE(LIBEPOXY)
    28 #include <epoxy/gl.h>
    29 #elif USE(OPENGL_ES)
    30 #include <GLES2/gl2.h>
    31 #else
    32 #include "OpenGLShims.h"
    33 #endif
    34 
    35 #if USE(EGL) && !PLATFORM(GTK)
    36 #if PLATFORM(WPE)
    37 // FIXME: For now default to the GBM EGL platform, but this should really be
    38 // somehow deducible from the build configuration.
    39 #define __GBM__ 1
    40 #endif // PLATFORM(WPE)
     34#include <epoxy/egl.h>
     35#else // !USE(LIBEPOXY)
    4136#include <EGL/eglplatform.h>
     37#endif // USE(LIBEPOXY)
    4238typedef EGLNativeWindowType GLNativeWindowType;
    4339#else // !USE(EGL) || PLATFORM(GTK)
    4440typedef uint64_t GLNativeWindowType;
    45 #endif
     41#endif // USE(EGL) && !PLATFORM(GTK)
    4642
    4743#if USE(CAIRO)
  • trunk/Source/WebKit/CMakeLists.txt

    r290002 r290138  
    374374    )
    375375else ()
    376     if (USE_OPENGL)
    377         list(APPEND WebKit_SYSTEM_INCLUDE_DIRECTORIES
    378             ${OPENGL_INCLUDE_DIRS}
    379         )
    380         list(APPEND WebKit_PRIVATE_LIBRARIES
    381             ${OPENGL_LIBRARIES}
    382         )
    383         add_definitions(${OPENGL_DEFINITIONS})
    384     elseif (USE_OPENGL_ES)
    385         list(APPEND WebKit_PRIVATE_LIBRARIES OpenGL::GLES)
    386     endif ()
    387 
    388376    if (USE_EGL)
    389377        list(APPEND WebKit_SYSTEM_INCLUDE_DIRECTORIES
  • trunk/Source/WebKit/ChangeLog

    r290128 r290138  
     12022-02-18  Adrian Perez de Castro  <aperez@igalia.com>
     2
     3        [CMake] Cannot find OpenGL when system provides opengl.pc instead of gl.pc
     4        https://bugs.webkit.org/show_bug.cgi?id=236592
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * CMakeLists.txt: Remove usage of the OPENGL_ variables for the WebKit target, which is
     9        uneeded because it links to WebCore, which transitively pulls the needed libraries now
     10        that imported targets are being used.
     11
    1122022-02-18  Tyler Wilcock  <tyler_w@apple.com>
    213
  • trunk/Source/cmake/FindOpenGL.cmake

    r290002 r290138  
    1 # - Try to Find OpenGL
    2 # Once done, this will define
    3 #
    4 #  OPENGL_FOUND - system has OpenGL installed.
    5 #  OPENGL_INCLUDE_DIRS - directories which contain the OpenGL headers.
    6 #  OPENGL_LIBRARIES - libraries required to link against OpenGL.
    7 #  OPENGL_DEFINITIONS - Compiler switches required for using OpenGL.
    8 #
    9 # Copyright (C) 2015 Igalia S.L.
     1# Copyright (C) 2015, 2022 Igalia S.L.
    102#
    113# Redistribution and use in source and binary forms, with or without
     
    2921# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    3022# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23#
     24#[=======================================================================[.rst:
     25FindOpenGL
     26----------
     27
     28Find OpenGL headers and libraries.
     29
     30Imported Targets
     31^^^^^^^^^^^^^^^^
     32
     33``OpenGL::OpenGL``
     34  The main OpenGL library, if found. It must *not* be assumed that this
     35  library provides symbols other than the base OpenGL set.
     36``OpenGL::GLX``
     37  The library containing the GL extension for the X11 windowing system,
     38  if found.
     39
     40Result Variables
     41^^^^^^^^^^^^^^^^
     42
     43This will define the following variables in your project:
     44
     45``OpenGL_FOUND``
     46  True if the OpenGL library is available.
     47``OpenGL_VERSION``
     48  The version of the found OpenGL library, if possible to determine it at
     49  build configuration time. The variable may be undefined.
     50
     51#]=======================================================================]
     52
     53# TODO:
     54#  - Make GLX an optional component of the find-module.
     55#  - Make EGL an optional component here, remove FindEGL.cmake.
     56#  - Consider whether FindGLES2.cmake could be moved here as well.
    3157
    3258find_package(PkgConfig QUIET)
     59pkg_check_modules(PC_OPENGL IMPORTED_TARGET opengl)
    3360
    34 pkg_check_modules(PC_OPENGL gl)
     61if (PC_OPENGL_FOUND AND TARGET PkgConfig::PC_OPENGL)
     62    #
     63    # If the "opengl" module exists, it should be preferred; and the library
     64    # name will typically be libOpenGL.so; in this case if GLX support is
     65    # available a "glx" module will *also* be available. This is a modern
     66    # Unix-ish convention and expected to be always provided by pkg-config
     67    # modules, so there is no need to fall-back to manually using find_path()
     68    # and find_library().
     69    #
     70    if (NOT TARGET OpenGL::OpenGL)
     71        add_library(OpenGL::OpenGL INTERFACE IMPORTED GLOBAL)
     72        set_property(TARGET OpenGL::OpenGL PROPERTY
     73            INTERFACE_LINK_LIBRARIES PkgConfig::PC_OPENGL
     74        )
     75    endif ()
    3576
    36 if (PC_OPENGL_FOUND)
    37     set(OPENGL_DEFINITIONS ${PC_OPENGL_CFLAGS_OTHER})
     77    get_target_property(OpenGL_LIBRARY PkgConfig::PC_OPENGL INTERFACE_LINK_LIBRARIES)
     78
     79    pkg_check_modules(PC_GLX IMPORTED_TARGET glx)
     80    if (TARGET PkgConfig::PC_GLX AND NOT TARGET OpenGL::GLX)
     81        add_library(OpenGL::GLX INTERFACE IMPORTED GLOBAL)
     82        set_property(TARGET OpenGL::GLX PROPERTY
     83            INTERFACE_LINK_LIBRARIES PkgConfig::PC_GLX
     84        )
     85    endif ()
     86else ()
     87    # Otherwise, if an "opengl" pkg-config module does not exist, check for
     88    # the "gl" one, which may or may not be present.
     89    #
     90    pkg_check_modules(PC_OPENGL gl)
     91    find_path(OpenGL_INCLUDE_DIR
     92        NAMES GL/gl.h
     93        HINTS ${PC_OPENGL_INCLUDEDIR} ${PC_OPENGL_INCLUDE_DIRS}
     94    )
     95
     96    find_library(OpenGL_LIBRARY
     97        NAMES ${OpenGL_NAMES} gl GL
     98        HINTS ${PC_OPENGL_LIBDIR} ${PC_OPENGL_LIBRARY_DIRS}
     99    )
     100
     101    if (OpenGL_LIBRARY AND NOT TARGET OpenGL::OpenGL)
     102        add_library(OpenGL::OpenGL UNKNOWN IMPORTED GLOBAL)
     103        set_target_properties(OpenGL::OpenGL PROPERTIES
     104            IMPORTED_LOCATION "${OpenGL_LIBRARY}"
     105            INTERFACE_COMPILE_OPTIONS "${PC_OPENGL_CFLAGS_OTHER}"
     106            INTERFACE_INCLUDE_DIRECTORIES "${OpenGL_INCLUDE_DIR}"
     107        )
     108    endif ()
     109
     110    if (TARGET OpenGL::OpenGL)
     111        # We don't use find_package for GLX because it is part of -lGL, unlike EGL. We need to
     112        # have OPENGL_INCLUDE_DIRS as part of the directories check_include_files() looks for in
     113        # case OpenGL is installed into a non-standard location.
     114        include(CMakePushCheckState)
     115        CMAKE_PUSH_CHECK_STATE()
     116        set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OpenGL_INCLUDE_DIR})
     117        include(CheckIncludeFiles)
     118        check_include_files("GL/glx.h" OpenGL_GLX_FOUND)
     119        CMAKE_POP_CHECK_STATE()
     120
     121        if (OpenGL_GLX_FOUND)
     122            # XXX: Should this actually check that the OpenGL library contains the GLX symbols?
     123            add_library(OpenGL::GLX INTERFACE IMPORTED GLOBAL)
     124            set_property(TARGET OpenGL::GLX PROPERTY
     125                INTERFACE_LINK_LIBRARIES OpenGL::OpenGL
     126            )
     127        endif ()
     128    endif ()
    38129endif ()
    39130
    40 find_path(OPENGL_INCLUDE_DIRS NAMES GL/gl.h
    41     HINTS ${PC_OPENGL_INCLUDEDIR} ${PC_OPENGL_INCLUDE_DIRS}
     131set(OpenGL_VERSION "${PC_OPENGL_VERSION}")
     132
     133include(FindPackageHandleStandardArgs)
     134find_package_handle_standard_args(OpenGL
     135    REQUIRED_VARS OpenGL_LIBRARY
     136    FOUND_VAR OpenGL_FOUND
    42137)
    43138
    44 set(OPENGL_NAMES ${OPENGL_NAMES} gl GL)
    45 find_library(OPENGL_LIBRARIES NAMES ${OPENGL_NAMES}
    46     HINTS ${PC_OPENGL_LIBDIR} ${PC_OPENGL_LIBRARY_DIRS}
    47 )
     139mark_as_advanced(OpenGL_INCLUDE_DIR OpenGL_LIBRARY)
    48140
    49 include(FindPackageHandleStandardArgs)
    50 find_package_handle_standard_args(OpenGL REQUIRED_VARS OPENGL_INCLUDE_DIRS OPENGL_LIBRARIES
    51                                   FOUND_VAR OPENGL_FOUND)
    52 
    53 mark_as_advanced(OPENGL_INCLUDE_DIRS OPENGL_LIBRARIES)
    54 
    55 if (OPENGL_FOUND)
    56     # We don't use find_package for GLX because it is part of -lGL, unlike EGL. We need to
    57     # have OPENGL_INCLUDE_DIRS as part of the directories check_include_files() looks for in
    58     # case OpenGL is installed into a non-standard location.
    59     include(CMakePushCheckState)
    60     CMAKE_PUSH_CHECK_STATE()
    61     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENGL_INCLUDE_DIRS})
    62     include(CheckIncludeFiles)
    63     check_include_files("GL/glx.h" GLX_FOUND)
    64     CMAKE_POP_CHECK_STATE()
     141if (OpenGL_FOUND)
     142    set(OpenGL_LIBRARIES ${OpenGL_LIBRARY})
     143    set(OpenGL_INCLUDE_DIRS ${OpenGL_INCLUDE_DIR})
    65144endif ()
  • trunk/Source/cmake/OptionsGTK.cmake

    r290002 r290138  
    366366    endif ()
    367367
    368     if (NOT EGL_FOUND AND (NOT ENABLE_X11_TARGET OR NOT GLX_FOUND))
     368    if (NOT EGL_FOUND AND (NOT ENABLE_X11_TARGET OR NOT TARGET OpenGL::GLX))
    369369        message(FATAL_ERROR "Either GLX or EGL is needed.")
    370370    endif ()
     
    374374    SET_AND_EXPOSE_TO_BUILD(USE_EGL ${EGL_FOUND})
    375375
    376     if (ENABLE_X11_TARGET AND GLX_FOUND AND USE_OPENGL)
     376    if (ENABLE_X11_TARGET AND USE_OPENGL AND TARGET OpenGL::GLX)
    377377        SET_AND_EXPOSE_TO_BUILD(USE_GLX TRUE)
    378378    endif ()
Note: See TracChangeset for help on using the changeset viewer.