diff options
author | Alex Merry <alex.merry@kde.org> | 2014-03-07 10:36:36 +0000 |
---|---|---|
committer | Alex Merry <alex.merry@kde.org> | 2014-04-14 16:14:25 +0100 |
commit | aeee805993a1bf5ac148cfbd3aec0e2c2d884f68 (patch) | |
tree | abe4b9ab91c6551611826c5b52d1b967019ec06f /find-modules | |
parent | fda1eaca7c2e86c7df2771486b19bd629a36421a (diff) | |
download | extra-cmake-modules-aeee805993a1bf5ac148cfbd3aec0e2c2d884f68.tar.gz extra-cmake-modules-aeee805993a1bf5ac148cfbd3aec0e2c2d884f68.tar.bz2 |
Improve FindEGL.cmake
- Add version handling
- Improve the docs
- mark cache variables as advanced
- make the pkg-config call actually work
REVIEW: 117490
Diffstat (limited to 'find-modules')
-rw-r--r-- | find-modules/FindEGL.cmake | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/find-modules/FindEGL.cmake b/find-modules/FindEGL.cmake index 765b6692..f1962b9a 100644 --- a/find-modules/FindEGL.cmake +++ b/find-modules/FindEGL.cmake @@ -7,15 +7,21 @@ # This will define the following variables: # # ``EGL_FOUND`` -# True if EGL is available +# True if (the requested version of) EGL is available +# ``EGL_VERSION`` +# The version of EGL; note that this is the API version defined in the +# headers, rather than the version of the implementation (eg: Mesa) # ``EGL_LIBRARIES`` -# Link these to use EGL +# This can be passed to target_link_libraries() instead of the ``EGL::EGL`` +# target # ``EGL_INCLUDE_DIRS`` -# Include directory for EGL +# This should be passed to target_include_directories() if the target is not +# used for linking # ``EGL_DEFINITIONS`` -# Compiler flags for using EGL +# This should be passed to target_compile_options() if the target is not +# used for linking # -# and the following imported targets: +# If ``EGL_FOUND`` is TRUE, it will also define the following imported target: # # ``EGL::EGL`` # The EGL library @@ -25,6 +31,7 @@ # exported library, it must be made available by the package config file. #============================================================================= +# Copyright 2014 Alex Merry <alex.merry@kde.org> # Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> # # Redistribution and use in source and binary forms, with or without @@ -62,7 +69,7 @@ if(NOT WIN32) # Use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls find_package(PkgConfig) - pkg_check_modules(PKG_EGL QUIET ${pkgConfigModules}) + pkg_check_modules(PKG_EGL QUIET egl) set(EGL_DEFINITIONS ${PKG_EGL_CFLAGS_OTHER}) @@ -81,8 +88,34 @@ if(NOT WIN32) ${PKG_EGL_LIBRARY_DIRS} ) - set(EGL_LIBRARIES ${EGL_LIBRARY}) - set(EGL_INCLUDE_DIRS ${EGL_INCLUDE_DIR}) + # NB: We do *not* use the version information from pkg-config, as that + # is the implementation version (eg: the Mesa version) + if(EGL_INCLUDE_DIR) + # egl.h has defines of the form EGL_VERSION_x_y for each supported + # version; so the header for EGL 1.1 will define EGL_VERSION_1_0 and + # EGL_VERSION_1_1. Finding the highest supported version involves + # finding all these defines and selecting the highest numbered. + file(READ "${EGL_INCLUDE_DIR}/egl.h" _EGL_header_contents) + string(REGEX MATCHALL + "[ \\t]EGL_VERSION_[0-9_]+" + _EGL_version_lines + "${_EGL_header_contents}" + ) + unset(_EGL_header_contents) + foreach(_EGL_version_line ${_EGL_version_lines}) + string(REGEX REPLACE + "[ \\t]EGL_VERSION_([0-9_]+)" + "\\1" + _version_candidate + "${_EGL_version_line}" + ) + string(REPLACE "_" "." _version_candidate "${_version_candidate}") + if(NOT DEFINED EGL_VERSION OR EGL_VERSION VERSION_LESS _version_candidate) + set(EGL_VERSION "${_version_candidate}") + endif() + endforeach() + unset(_EGL_version_lines) + endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(EGL @@ -91,6 +124,8 @@ if(NOT WIN32) REQUIRED_VARS EGL_LIBRARY EGL_INCLUDE_DIR + VERSION_VAR + EGL_VERSION ) if(EGL_FOUND AND NOT TARGET EGL::EGL) @@ -102,6 +137,13 @@ if(NOT WIN32) ) endif() + mark_as_advanced(EGL_LIBRARY EGL_INCLUDE_DIR) + + # compatibility variables + set(EGL_LIBRARIES ${EGL_LIBRARY}) + set(EGL_INCLUDE_DIRS ${EGL_INCLUDE_DIR}) + set(EGL_VERSION_STRING ${EGL_VERSION}) + else() message(STATUS "FindEGL.cmake cannot find EGL on Windows systems. Try finding WGL instead.") set(EGL_FOUND FALSE) @@ -110,5 +152,5 @@ endif() include(FeatureSummary) set_package_properties(EGL PROPERTIES URL "https://www.khronos.org/egl/" - DESCRIPTION "EGL provides a platform-agnostic mechanism for creating rendering surfaces for use with other graphics libraries, such as OpenGL|ES and OpenVG." + DESCRIPTION "A platform-agnostic mechanism for creating rendering surfaces for use with other graphics libraries, such as OpenGL|ES and OpenVG." ) |