Warning, /frameworks/extra-cmake-modules/find-modules/FindEGL.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>
0002 # SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005
0006 #[=======================================================================[.rst:
0007 FindEGL
0008 -------
0009
0010 Try to find EGL.
0011
0012 This will define the following variables:
0013
0014 ``EGL_FOUND``
0015 True if (the requested version of) EGL is available
0016 ``EGL_VERSION``
0017 The version of EGL; note that this is the API version defined in the
0018 headers, rather than the version of the implementation (eg: Mesa)
0019 ``EGL_LIBRARIES``
0020 This can be passed to target_link_libraries() instead of the ``EGL::EGL``
0021 target
0022 ``EGL_INCLUDE_DIRS``
0023 This should be passed to target_include_directories() if the target is not
0024 used for linking
0025 ``EGL_DEFINITIONS``
0026 This should be passed to target_compile_options() if the target is not
0027 used for linking
0028
0029 If ``EGL_FOUND`` is TRUE, it will also define the following imported target:
0030
0031 ``EGL::EGL``
0032 The EGL library
0033
0034 In general we recommend using the imported target, as it is easier to use.
0035 Bear in mind, however, that if the target is in the link interface of an
0036 exported library, it must be made available by the package config file.
0037
0038 Since pre-1.0.0.
0039 #]=======================================================================]
0040
0041 include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
0042 include(CheckCXXSourceCompiles)
0043 include(CMakePushCheckState)
0044
0045 ecm_find_package_version_check(EGL)
0046
0047 # Use pkg-config to get the directories and then use these values
0048 # in the FIND_PATH() and FIND_LIBRARY() calls
0049 find_package(PkgConfig QUIET)
0050 pkg_check_modules(PKG_EGL QUIET egl)
0051
0052 set(EGL_DEFINITIONS ${PKG_EGL_CFLAGS_OTHER})
0053
0054 find_path(EGL_INCLUDE_DIR
0055 NAMES
0056 EGL/egl.h
0057 HINTS
0058 ${PKG_EGL_INCLUDE_DIRS}
0059 )
0060 find_library(EGL_LIBRARY
0061 NAMES
0062 EGL
0063 libEGL
0064 HINTS
0065 ${PKG_EGL_LIBRARY_DIRS}
0066 )
0067
0068 # NB: We do *not* use the version information from pkg-config, as that
0069 # is the implementation version (eg: the Mesa version)
0070 if(EGL_INCLUDE_DIR)
0071 # egl.h has defines of the form EGL_VERSION_x_y for each supported
0072 # version; so the header for EGL 1.1 will define EGL_VERSION_1_0 and
0073 # EGL_VERSION_1_1. Finding the highest supported version involves
0074 # finding all these defines and selecting the highest numbered.
0075 file(READ "${EGL_INCLUDE_DIR}/EGL/egl.h" _EGL_header_contents)
0076 string(REGEX MATCHALL
0077 "[ \t]EGL_VERSION_[0-9_]+"
0078 _EGL_version_lines
0079 "${_EGL_header_contents}"
0080 )
0081 unset(_EGL_header_contents)
0082 foreach(_EGL_version_line ${_EGL_version_lines})
0083 string(REGEX REPLACE
0084 "[ \t]EGL_VERSION_([0-9_]+)"
0085 "\\1"
0086 _version_candidate
0087 "${_EGL_version_line}"
0088 )
0089 string(REPLACE "_" "." _version_candidate "${_version_candidate}")
0090 if(NOT DEFINED EGL_VERSION OR EGL_VERSION VERSION_LESS _version_candidate)
0091 set(EGL_VERSION "${_version_candidate}")
0092 endif()
0093 endforeach()
0094 unset(_EGL_version_lines)
0095 endif()
0096
0097 cmake_push_check_state(RESET)
0098 list(APPEND CMAKE_REQUIRED_LIBRARIES "${EGL_LIBRARY}")
0099 list(APPEND CMAKE_REQUIRED_INCLUDES "${EGL_INCLUDE_DIR}")
0100
0101 check_cxx_source_compiles("
0102 #include <EGL/egl.h>
0103
0104 int main(int argc, char *argv[]) {
0105 EGLint x = 0; EGLDisplay dpy = 0; EGLContext ctx = 0;
0106 eglDestroyContext(dpy, ctx);
0107 }" HAVE_EGL)
0108
0109 cmake_pop_check_state()
0110
0111 set(required_vars EGL_INCLUDE_DIR HAVE_EGL)
0112 if(NOT EMSCRIPTEN)
0113 list(APPEND required_vars EGL_LIBRARY)
0114 endif()
0115
0116 include(FindPackageHandleStandardArgs)
0117 find_package_handle_standard_args(EGL
0118 FOUND_VAR
0119 EGL_FOUND
0120 REQUIRED_VARS
0121 ${required_vars}
0122 VERSION_VAR
0123 EGL_VERSION
0124 )
0125
0126 if(EGL_FOUND AND NOT TARGET EGL::EGL)
0127 if (EMSCRIPTEN)
0128 add_library(EGL::EGL INTERFACE IMPORTED)
0129 # Nothing further to be done, system include paths have headers and linkage is implicit.
0130 else()
0131 add_library(EGL::EGL UNKNOWN IMPORTED)
0132 set_target_properties(EGL::EGL PROPERTIES
0133 IMPORTED_LOCATION "${EGL_LIBRARY}"
0134 INTERFACE_COMPILE_OPTIONS "${EGL_DEFINITIONS}"
0135 INTERFACE_INCLUDE_DIRECTORIES "${EGL_INCLUDE_DIR}"
0136 )
0137 endif()
0138 endif()
0139
0140 mark_as_advanced(EGL_LIBRARY EGL_INCLUDE_DIR HAVE_EGL)
0141
0142 # compatibility variables
0143 set(EGL_LIBRARIES ${EGL_LIBRARY})
0144 set(EGL_INCLUDE_DIRS ${EGL_INCLUDE_DIR})
0145 set(EGL_VERSION_STRING ${EGL_VERSION})
0146
0147 include(FeatureSummary)
0148 set_package_properties(EGL PROPERTIES
0149 URL "https://www.khronos.org/egl/"
0150 DESCRIPTION "A platform-agnostic mechanism for creating rendering surfaces for use with other graphics libraries, such as OpenGL|ES and OpenVG."
0151 )