CMAKE finds EGL, Qt does not: tiny bug in Qt's FindEGL.cmake prevents linking with static Qt
-
Recently, I ran into a problem with the static version Qt 6.4.2. that other people might also encounter. Fortunately, I found a solution, which I share in this post.
After I succesfully compiled and linked my application with the Qt 6.4.2 (default build, i.e. dynamic libraries), I tried to build and link the same application again, but now with a static build of Qt 6.4.2.
Building static Qt 6.4.2 was not a problem, but the cmake configuration of my own application failed, however.
The error messages indicated that the opengl library EGL could not be found. Because of this, linking to the Qt components I used (Gui, Widgets, ...) failed, with the error message telling that the test HAVE_EGL failed.This was weird, as cmake in the same configuration run could find all the required opengl components! It turned out the culprit was in the file FindEGL.cmake, which comes with the Qt distribution (../lib/cmake/Qt6/3rdparty/extra-cmake-modules/find-modules/FindEGL.cmake). In this file, there is the snippet:
check_cxx_source_compiles(" #include <EGL/egl.h> int main(int, char **) { EGLint x= 0; EGLDisplay dpy = 0; EGLContext ctx = 0; eglDestroyContext(dpy, ctx); }" HAVE_EGL)
The variable EGLint x=0; is not used elsewhere in this code snippet, triggering a warning from the compiler. The warning was treated as an error and the test failed accordingly. A resolution is to add the attribute [[maybe_unused]] immediately following x:
check_cxx_source_compiles(" #include <EGL/egl.h> int main(int, char **) { EGLint x [[maybe_unused]] = 0; EGLDisplay dpy = 0; EGLContext ctx = 0; eglDestroyContext(dpy, ctx); }" HAVE_EGL)
With this, the cmake-configuration of my application could again proceed as intended, after which compilation and linking to static Qt was possible.
-
You should create a bug report about this - most of the Qt devs don't read in the forum.
-
Hi,
That part comes from KDE, I would recommend also checking with them.