Fix build on Linux where GLESv3 is not present

Only build the texture example if GLESv3 headers are found
This commit is contained in:
Simon Hausmann 2023-10-02 12:50:35 +02:00 committed by Simon Hausmann
parent 0773e51d92
commit e44f70c9df
2 changed files with 62 additions and 3 deletions

53
cmake/FindOpenGLES3.cmake Normal file
View file

@ -0,0 +1,53 @@
# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
include(CheckCXXSourceCompiles)
find_path(OPENGLES3_INCLUDE_DIR NAMES "GLES3/gl3.h" "OpenGLES/ES3/gl.h" DOC "The path where the OpenGL ES 3.0 headers are located")
# GLESv3 entry points are in v2 lib
find_library(OPENGLES3_LIBRARY NAMES GLESv2 OpenGLES)
# Sometimes EGL linkage is required, so look it up and always use if available.
find_package(OpenGL COMPONENTS EGL)
# See if we can compile some example code with what we've found.
set(saved_libraries "${CMAKE_REQUIRED_LIBRARIES}")
set(saved_includes "${CMAKE_REQUIRED_INCLUDES}")
if (OPENGLES3_LIBRARY)
list(APPEND CMAKE_REQUIRED_INCLUDES "${OPENGLES3_INCLUDE_DIR}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${OPENGLES3_LIBRARY}")
endif()
if(OPENGL_egl_LIBRARY)
list(APPEND CMAKE_REQUIRED_INCLUDES "${OPENGL_EGL_INCLUDE_DIRS}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${OPENGL_egl_LIBRARY}")
endif()
check_cxx_source_compiles("
#include <GLES3/gl3.h>
#include <GLES3/gl3platform.h>
int main(int argc, char *argv[]) {
glClear(GL_STENCIL_BUFFER_BIT);
glUseProgram(0);
}" HAVE_OPENGLES3)
set(CMAKE_REQUIRED_INCLUDES "${saved_includes}")
set(CMAKE_REQUIRED_LIBRARIES "${saved_libraries}")
# Standard CMake package dance
set(package_args OPENGLES3_INCLUDE_DIR OPENGLES3_LIBRARY HAVE_OPENGLES3)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenGLES3 DEFAULT_MSG ${package_args})
mark_as_advanced(${package_args})
# Create a convenience target for linkage
if (OPENGLES3_FOUND AND NOT TARGET OpenGLES3::OpenGLES3)
add_library(OpenGLES3::OpenGLES3 UNKNOWN IMPORTED)
set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${OPENGLES3_INCLUDE_DIR}")
set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY IMPORTED_LOCATION "${OPENGLES3_LIBRARY}")
if (TARGET OpenGL::EGL)
target_link_libraries(OpenGLES3::OpenGLES3 INTERFACE OpenGL::EGL)
endif()
endif()

View file

@ -5,7 +5,9 @@ project(SlintExamples LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
# TODO: Use find_package(OpenGL) when switching to CMake >= 3.27
find_package(OpenGLES2 QUIET)
find_package(OpenGLES3 QUIET)
if (NOT TARGET Slint::Slint)
find_package(Slint REQUIRED)
@ -29,9 +31,13 @@ endif()
if (SLINT_FEATURE_INTERPRETER)
add_subdirectory(iot-dashboard/)
endif()
if (TARGET Slint::slint-compiler AND OpenGLES2_FOUND AND (SLINT_FEATURE_BACKEND_WINIT OR SLINT_FEATURE_BACKEND_WINIT_WAYLAND OR SLINT_FEATURE_BACKEND_WINIT_X11) AND SLINT_FEATURE_RENDERER_FEMTOVG)
add_subdirectory(opengl_underlay)
add_subdirectory(opengl_texture)
if (TARGET Slint::slint-compiler AND (SLINT_FEATURE_BACKEND_WINIT OR SLINT_FEATURE_BACKEND_WINIT_WAYLAND OR SLINT_FEATURE_BACKEND_WINIT_X11) AND SLINT_FEATURE_RENDERER_FEMTOVG)
if (OpenGLES2_FOUND)
add_subdirectory(opengl_underlay)
endif()
if (OpenGLES3_FOUND)
add_subdirectory(opengl_texture)
endif()
endif()
if (SLINT_FEATURE_INTERPRETER AND SLINT_FEATURE_BACKEND_QT)
add_subdirectory(cpp/qt_viewer)