Bug 145408 - [CMake][GTK] Improve detection and usage of GL/GLES/EGL libraries.
Summary: [CMake][GTK] Improve detection and usage of GL/GLES/EGL libraries.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Carlos Alberto Lopez Perez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-27 08:18 PDT by Carlos Alberto Lopez Perez
Modified: 2017-08-06 14:51 PDT (History)
9 users (show)

See Also:


Attachments
Patch (16.28 KB, patch)
2015-05-27 10:34 PDT, Carlos Alberto Lopez Perez
no flags Details | Formatted Diff | Diff
Patch (16.27 KB, patch)
2015-05-27 15:30 PDT, Carlos Alberto Lopez Perez
no flags Details | Formatted Diff | Diff
Patch (16.21 KB, patch)
2015-05-27 19:38 PDT, Carlos Alberto Lopez Perez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Alberto Lopez Perez 2015-05-27 08:18:07 PDT
I have observed some problems when building WebKitGTK+ on some embedded devices:

1) When building WebKitGTK+ on a freescale board, the build fails because the EGL headers of Vivante expect some variables to be defined.

$ pkg-config --cflags  egl
-DLINUX -I/usr/include/libdrm 

Our current CMake logic don't passes "-DLINUX" to the build, so when we include the Vivante headers it aborts because that headers need -DLINUX to be defined.

2) When building WebKitGTK+ on any board with any GLESv2 library that don't defines an include path (because it uses the standard system one), we fail to detect the GLES libraries because the way we handle the logic in findgles.cmake (we expect pkg-config to define an include path (-I/somepath) to set gles_found to true instead of using find_path() to find the path for the include headers. pkg-config will not define an include path when the headers are on the default system include path)

$ pkg-config --cflags --libs glesv2
-lGLESv2 


3) Not a problem but an improvement: we should be able to automatically switch to building with GLES when we don't detect OpenGL, but we detect OpenGLESv2.
Comment 1 Martin Robinson 2015-05-27 08:29:39 PDT
(In reply to comment #0)
> 3) Not a problem but an improvement: we should be able to automatically
> switch to building with GLES when we don't detect OpenGL, but we detect
> OpenGLESv2.

We have decided to make everything require explicit configuration arguments to prevent getting builds that silently lack features. Perhaps Michael can comment about whether or not he believes this is the same situation.
Comment 2 Carlos Alberto Lopez Perez 2015-05-27 08:45:21 PDT
(In reply to comment #1)
> (In reply to comment #0)
> > 3) Not a problem but an improvement: we should be able to automatically
> > switch to building with GLES when we don't detect OpenGL, but we detect
> > OpenGLESv2.
> 
> We have decided to make everything require explicit configuration arguments
> to prevent getting builds that silently lack features. Perhaps Michael can
> comment about whether or not he believes this is the same situation.

We are already conditional enabling ACCELERATED_2D_CANVAS depending on finding cairo-gl or not.

Also the feature here will be: "Use accelerated compositing". This can be done either via OpenGL or via OpenGLES. But the feature is the same. Is not like we will be switching off the feature when we find OpenGLES but not OpenGL, we will simply using the another library we support for the feature.
Comment 3 Carlos Alberto Lopez Perez 2015-05-27 10:34:01 PDT
Created attachment 253792 [details]
Patch
Comment 4 WebKit Commit Bot 2015-05-27 10:35:37 PDT
Attachment 253792 [details] did not pass style-queue:


ERROR: Source/WebCore/PlatformEfl.cmake:396:  Alphabetical sorting problem. "crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp" should be before "crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp".  [list/order] [5]
Total errors found: 1 in 9 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Michael Catanzaro 2015-05-27 11:00:15 PDT
(In reply to comment #2)
> We are already conditional enabling ACCELERATED_2D_CANVAS depending on
> finding cairo-gl or not.

I think this is not a very good example though. This one is detected automatically mostly as a stopgap, since Debian and Ubuntu do not have CarioGL and it's impossible to enable ACCELERATED_2D_CANVAS there even if we want to, but all other major distros have been using ACCELERATED_2D_CANVAS for a while and I'm not aware of any reason to turn that off for them.

> Also the feature here will be: "Use accelerated compositing". This can be
> done either via OpenGL or via OpenGLES. But the feature is the same. Is not
> like we will be switching off the feature when we find OpenGLES but not
> OpenGL, we will simply using the another library we support for the feature.

This seems like a good argument to me. It should be fine to automatically fall back to OpenGLES if OpenGL is not available, so long as there's no significant functionality regression when built with OpenGLES instead of OpenGL.
Comment 6 Michael Catanzaro 2015-05-27 11:11:35 PDT
Regarding your patch: it passes my sanity-check, except CMakePushCheckState should be included from FindOpenGL.cmake, not OptionsGTK.cmake and OptionsEFL.cmake.
Comment 7 Carlos Alberto Lopez Perez 2015-05-27 15:24:58 PDT
(In reply to comment #6)
> Regarding your patch: it passes my sanity-check, except CMakePushCheckState
> should be included from FindOpenGL.cmake, not OptionsGTK.cmake and
> OptionsEFL.cmake.

Good point.
Comment 8 Carlos Alberto Lopez Perez 2015-05-27 15:30:50 PDT
Created attachment 253804 [details]
Patch
Comment 9 WebKit Commit Bot 2015-05-27 15:33:39 PDT
Attachment 253804 [details] did not pass style-queue:


ERROR: Source/WebCore/PlatformEfl.cmake:396:  Alphabetical sorting problem. "crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp" should be before "crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp".  [list/order] [5]
Total errors found: 1 in 9 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 Carlos Alberto Lopez Perez 2015-05-27 18:15:05 PDT
(In reply to comment #9)
> Attachment 253804 [details] did not pass style-queue:
> 
> 
> ERROR: Source/WebCore/PlatformEfl.cmake:396:  Alphabetical sorting problem.
> "crypto/gnutls/CryptoAlgorithmRSASSA_PKCS1_v1_5GnuTLS.cpp" should be before
> "crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp".  [list/order] [5]
> Total errors found: 1 in 9 files
> 
> 
> If any of these errors are false positives, please file a bug against
> check-webkit-style.

It was already reported: https://bugs.webkit.org/show_bug.cgi?id=144959
Comment 11 Carlos Alberto Lopez Perez 2015-05-27 19:38:03 PDT
Created attachment 253827 [details]
Patch
Comment 12 Carlos Garcia Campos 2015-05-28 02:12:02 PDT
Comment on attachment 253827 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253827&action=review

This looks great to me, I only have the doubts in FindFoo whether we realy need to still use find_path and find_library even when pkg-config file was found

> Source/cmake/FindEGL.cmake:43
> +endif ()
> +
> +find_path(EGL_INCLUDE_DIRS NAMES EGL/egl.h
> +    HINTS ${PC_EGL_INCLUDEDIR} ${PC_EGL_INCLUDE_DIRS}
> +)

Do we still need to do this even if the pkg-config file was found?

> Source/cmake/FindEGL.cmake:48
> +find_library(EGL_LIBRARIES NAMES ${EGL_NAMES}
> +    HINTS ${PC_EGL_LIBDIR} ${PC_EGL_LIBRARY_DIRS}
> +)

Ditto.
Comment 13 Carlos Alberto Lopez Perez 2015-05-28 03:45:20 PDT
(In reply to comment #12)
> Comment on attachment 253827 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=253827&action=review
> 
> This looks great to me, I only have the doubts in FindFoo whether we realy
> need to still use find_path and find_library even when pkg-config file was
> found
> 
> > Source/cmake/FindEGL.cmake:43
> > +endif ()
> > +
> > +find_path(EGL_INCLUDE_DIRS NAMES EGL/egl.h
> > +    HINTS ${PC_EGL_INCLUDEDIR} ${PC_EGL_INCLUDE_DIRS}
> > +)
> 
> Do we still need to do this even if the pkg-config file was found?
> 
> > Source/cmake/FindEGL.cmake:48
> > +find_library(EGL_LIBRARIES NAMES ${EGL_NAMES}
> > +    HINTS ${PC_EGL_LIBDIR} ${PC_EGL_LIBRARY_DIRS}
> > +)
> 
> Ditto.

Yes. The reason is that when you below on that files you define:

FIND_PACKAGE_HANDLE_STANDARD_ARGS(EGL DEFAULT_MSG EGL_INCLUDE_DIRS EGL_LIBRARIES)

You are saying that you only want to define the library as found (EGL_FOUND=TRUE) if both variables are valid/defined (EGL_INCLUDE_DIRS and EGL_LIBRARIES).

But pkg-config will not define a <LIBRARY>_INCLUDE_DIRS when the headers are on the default system path (typically /usr/include) because is redundant.

But, find_path will do in any case. It finds the path where the headers are (even if they are on the default system path).

The same applies to find_library. If pkg-config don't defines a '-lfoobar', at least find_library will find all the .so files and add them with '-L/path/to/foobar.so'

So to my knowledge so far, the best way to find a library in a reliably way is to not directly use the values from pkg-config even when they are available, but use this values instead as hints to find_path() and find_library()
Comment 14 Carlos Alberto Lopez Perez 2015-05-28 04:31:14 PDT
Comment on attachment 253827 [details]
Patch

Clearing flags on attachment: 253827

Committed r184954: <http://trac.webkit.org/changeset/184954>
Comment 15 Carlos Alberto Lopez Perez 2015-05-28 04:31:24 PDT
All reviewed patches have been landed.  Closing bug.