| 1 |
#.rst: |
| 2 |
# FindEGL |
| 3 |
# ------- |
| 4 |
# |
| 5 |
# Try to find EGL. |
| 6 |
# |
| 7 |
# This will define the following variables: |
| 8 |
# |
| 9 |
# ``EGL_FOUND`` |
| 10 |
# True if (the requested version of) EGL is available |
| 11 |
# ``EGL_VERSION`` |
| 12 |
# The version of EGL; note that this is the API version defined in the |
| 13 |
# headers, rather than the version of the implementation (eg: Mesa) |
| 14 |
# ``EGL_LIBRARIES`` |
| 15 |
# This can be passed to target_link_libraries() instead of the ``EGL::EGL`` |
| 16 |
# target |
| 17 |
# ``EGL_INCLUDE_DIRS`` |
| 18 |
# This should be passed to target_include_directories() if the target is not |
| 19 |
# used for linking |
| 20 |
# ``EGL_DEFINITIONS`` |
| 21 |
# This should be passed to target_compile_options() if the target is not |
| 22 |
# used for linking |
| 23 |
# |
| 24 |
# If ``EGL_FOUND`` is TRUE, it will also define the following imported target: |
| 25 |
# |
| 26 |
# ``EGL::EGL`` |
| 27 |
# The EGL library |
| 28 |
# |
| 29 |
# In general we recommend using the imported target, as it is easier to use. |
| 30 |
# Bear in mind, however, that if the target is in the link interface of an |
| 31 |
# exported library, it must be made available by the package config file. |
| 32 |
# |
| 33 |
# Since pre-1.0.0. |
| 34 |
|
| 35 |
#============================================================================= |
| 36 |
# Copyright 2014 Alex Merry <[email protected]> |
| 37 |
# Copyright 2014 Martin Gräßlin <[email protected]> |
| 38 |
# |
| 39 |
# Redistribution and use in source and binary forms, with or without |
| 40 |
# modification, are permitted provided that the following conditions |
| 41 |
# are met: |
| 42 |
# |
| 43 |
# 1. Redistributions of source code must retain the copyright |
| 44 |
# notice, this list of conditions and the following disclaimer. |
| 45 |
# 2. Redistributions in binary form must reproduce the copyright |
| 46 |
# notice, this list of conditions and the following disclaimer in the |
| 47 |
# documentation and/or other materials provided with the distribution. |
| 48 |
# 3. The name of the author may not be used to endorse or promote products |
| 49 |
# derived from this software without specific prior written permission. |
| 50 |
# |
| 51 |
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 52 |
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 53 |
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 54 |
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 55 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 56 |
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 60 |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 |
#============================================================================= |
| 62 |
|
| 63 |
include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake) |
| 64 |
include(CheckCXXSourceCompiles) |
| 65 |
include(CMakePushCheckState) |
| 66 |
|
| 67 |
ecm_find_package_version_check(EGL) |
| 68 |
|
| 69 |
# Use pkg-config to get the directories and then use these values |
| 70 |
# in the FIND_PATH() and FIND_LIBRARY() calls |
| 71 |
find_package(PkgConfig QUIET) |
| 72 |
pkg_check_modules(PKG_EGL QUIET egl) |
| 73 |
|
| 74 |
set(EGL_DEFINITIONS ${PKG_EGL_CFLAGS_OTHER}) |
| 75 |
|
| 76 |
find_path(EGL_INCLUDE_DIR |
| 77 |
NAMES |
| 78 |
EGL/egl.h |
| 79 |
HINTS |
| 80 |
${PKG_EGL_INCLUDE_DIRS} |
| 81 |
) |
| 82 |
find_library(EGL_LIBRARY |
| 83 |
NAMES |
| 84 |
EGL |
| 85 |
HINTS |
| 86 |
${PKG_EGL_LIBRARY_DIRS} |
| 87 |
) |
| 88 |
|
| 89 |
# NB: We do *not* use the version information from pkg-config, as that |
| 90 |
# is the implementation version (eg: the Mesa version) |
| 91 |
if(EGL_INCLUDE_DIR) |
| 92 |
# egl.h has defines of the form EGL_VERSION_x_y for each supported |
| 93 |
# version; so the header for EGL 1.1 will define EGL_VERSION_1_0 and |
| 94 |
# EGL_VERSION_1_1. Finding the highest supported version involves |
| 95 |
# finding all these defines and selecting the highest numbered. |
| 96 |
file(READ "${EGL_INCLUDE_DIR}/EGL/egl.h" _EGL_header_contents) |
| 97 |
string(REGEX MATCHALL |
| 98 |
"[ \t]EGL_VERSION_[0-9_]+" |
| 99 |
_EGL_version_lines |
| 100 |
"${_EGL_header_contents}" |
| 101 |
) |
| 102 |
unset(_EGL_header_contents) |
| 103 |
foreach(_EGL_version_line ${_EGL_version_lines}) |
| 104 |
string(REGEX REPLACE |
| 105 |
"[ \t]EGL_VERSION_([0-9_]+)" |
| 106 |
"\\1" |
| 107 |
_version_candidate |
| 108 |
"${_EGL_version_line}" |
| 109 |
) |
| 110 |
string(REPLACE "_" "." _version_candidate "${_version_candidate}") |
| 111 |
if(NOT DEFINED EGL_VERSION OR EGL_VERSION VERSION_LESS _version_candidate) |
| 112 |
set(EGL_VERSION "${_version_candidate}") |
| 113 |
endif() |
| 114 |
endforeach() |
| 115 |
unset(_EGL_version_lines) |
| 116 |
endif() |
| 117 |
|
| 118 |
cmake_push_check_state(RESET) |
| 119 |
list(APPEND CMAKE_REQUIRED_LIBRARIES "${EGL_LIBRARY}") |
| 120 |
list(APPEND CMAKE_REQUIRED_INCLUDES "${EGL_INCLUDE_DIR}") |
| 121 |
list(APPEND CMAKE_REQUIRED_DEFINITIONS "${EGL_DEFINITIONS}") |
| 122 |
|
| 123 |
find_package(PlatformGraphics QUIET) |
| 124 |
if(TARGET PlatformGraphics::PlatformGraphics) |
| 125 |
platform_graphics_extend_check_cxx_source_required_variables() |
| 126 |
endif() |
| 127 |
|
| 128 |
check_cxx_source_compiles(" |
| 129 |
#include <EGL/egl.h> |
| 130 |
|
| 131 |
int main(int, char **) { |
| 132 |
[[maybe_unused]] EGLint x = 0; |
| 133 |
EGLDisplay dpy = 0; EGLContext ctx = 0; |
| 134 |
eglDestroyContext(dpy, ctx); |
| 135 |
}" HAVE_EGL) |
| 136 |
|
| 137 |
cmake_pop_check_state() |
| 138 |
|
| 139 |
set(required_vars EGL_INCLUDE_DIR HAVE_EGL) |
| 140 |
if(NOT EMSCRIPTEN) |
| 141 |
list(APPEND required_vars EGL_LIBRARY) |
| 142 |
endif() |
| 143 |
|
| 144 |
include(FindPackageHandleStandardArgs) |
| 145 |
find_package_handle_standard_args(EGL |
| 146 |
FOUND_VAR |
| 147 |
EGL_FOUND |
| 148 |
REQUIRED_VARS |
| 149 |
${required_vars} |
| 150 |
VERSION_VAR |
| 151 |
EGL_VERSION |
| 152 |
) |
| 153 |
|
| 154 |
if(EGL_FOUND AND NOT TARGET EGL::EGL) |
| 155 |
if (EMSCRIPTEN) |
| 156 |
add_library(EGL::EGL INTERFACE IMPORTED) |
| 157 |
# Nothing further to be done, system include paths have headers and linkage is implicit. |
| 158 |
else() |
| 159 |
add_library(EGL::EGL UNKNOWN IMPORTED) |
| 160 |
set_target_properties(EGL::EGL PROPERTIES |
| 161 |
IMPORTED_LOCATION "${EGL_LIBRARY}" |
| 162 |
INTERFACE_COMPILE_OPTIONS "${EGL_DEFINITIONS}" |
| 163 |
INTERFACE_INCLUDE_DIRECTORIES "${EGL_INCLUDE_DIR}" |
| 164 |
) |
| 165 |
endif() |
| 166 |
endif() |
| 167 |
|
| 168 |
mark_as_advanced(EGL_LIBRARY EGL_INCLUDE_DIR HAVE_EGL) |
| 169 |
|
| 170 |
# compatibility variables |
| 171 |
set(EGL_LIBRARIES ${EGL_LIBRARY}) |
| 172 |
set(EGL_INCLUDE_DIRS ${EGL_INCLUDE_DIR}) |
| 173 |
set(EGL_VERSION_STRING ${EGL_VERSION}) |
| 174 |
|
| 175 |
include(FeatureSummary) |
| 176 |
set_package_properties(EGL PROPERTIES |
| 177 |
URL "https://www.khronos.org/egl/" |
| 178 |
DESCRIPTION "A platform-agnostic mechanism for creating rendering surfaces for use with other graphics libraries, such as OpenGL|ES and OpenVG." |
| 179 |
) |