From 3c96880f2e577c65f60ab319e9f7138acc30de89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 3 Sep 2019 11:09:23 +0200 Subject: [PATCH] modules: updated GL-related Find modules. --- modules/FindEGL.cmake | 35 +++++++++++++------------ modules/FindOpenGLES2.cmake | 52 ++++++++++++++++--------------------- modules/FindOpenGLES3.cmake | 52 ++++++++++++++++--------------------- 3 files changed, 62 insertions(+), 77 deletions(-) diff --git a/modules/FindEGL.cmake b/modules/FindEGL.cmake index 5fbe6ad..45312c0 100644 --- a/modules/FindEGL.cmake +++ b/modules/FindEGL.cmake @@ -38,8 +38,11 @@ # DEALINGS IN THE SOFTWARE. # -# Library -if(NOT CORRADE_TARGET_EMSCRIPTEN) +# Under Emscripten, GL is linked implicitly. With MINIMAL_RUNTIME you need to +# specify -lGL. Simply set the library name to that. +if(CORRADE_TARGET_EMSCRIPTEN) + set(EGL_LIBRARY GL CACHE STRING "Path to a library." FORCE) +else() find_library(EGL_LIBRARY NAMES EGL @@ -48,7 +51,6 @@ if(NOT CORRADE_TARGET_EMSCRIPTEN) # On iOS a part of OpenGLES OpenGLES) - set(EGL_LIBRARY_NEEDED EGL_LIBRARY) endif() # Include dir @@ -60,26 +62,25 @@ find_path(EGL_INCLUDE_DIR NAMES include(FindPackageHandleStandardArgs) find_package_handle_standard_args(EGL DEFAULT_MSG - ${EGL_LIBRARY_NEEDED} + EGL_LIBRARY EGL_INCLUDE_DIR) if(NOT TARGET EGL::EGL) - if(EGL_LIBRARY_NEEDED) - # Work around BUGGY framework support on macOS - # http://public.kitware.com/pipermail/cmake/2016-April/063179.html - if(APPLE AND ${EGL_LIBRARY} MATCHES "\\.framework$") - add_library(EGL::EGL INTERFACE IMPORTED) - set_property(TARGET EGL::EGL APPEND PROPERTY - INTERFACE_LINK_LIBRARIES ${EGL_LIBRARY}) - else() - add_library(EGL::EGL UNKNOWN IMPORTED) - set_property(TARGET EGL::EGL PROPERTY - IMPORTED_LOCATION ${EGL_LIBRARY}) - endif() - else() + # Work around BUGGY framework support on macOS. Do this also in case of + # Emscripten, since there we don't have a location either. + # http://public.kitware.com/pipermail/cmake/2016-April/063179.html + if((APPLE AND ${EGL_LIBRARY} MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) add_library(EGL::EGL INTERFACE IMPORTED) + set_property(TARGET EGL::EGL APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${EGL_LIBRARY}) + else() + add_library(EGL::EGL UNKNOWN IMPORTED) + set_property(TARGET EGL::EGL PROPERTY + IMPORTED_LOCATION ${EGL_LIBRARY}) endif() set_target_properties(EGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${EGL_INCLUDE_DIR}) endif() + +mark_as_advanced(EGL_LIBRARY EGL_INCLUDE_DIR) diff --git a/modules/FindOpenGLES2.cmake b/modules/FindOpenGLES2.cmake index dad7442..78730f7 100644 --- a/modules/FindOpenGLES2.cmake +++ b/modules/FindOpenGLES2.cmake @@ -10,7 +10,10 @@ # Additionally these variables are defined for internal usage: # # OPENGLES2_LIBRARY - OpenGL ES 2 library -# OPENGLES2_INCLUDE_DIR - Include dir +# +# Please note this find module is tailored especially for the needs of Magnum. +# In particular, it depends on its platform definitions and doesn't look for +# OpenGL ES includes as Magnum has its own, generated using flextGL. # # @@ -38,9 +41,11 @@ # DEALINGS IN THE SOFTWARE. # -# In Emscripten OpenGL ES 2 is linked automatically, thus no need to find the -# library. -if(NOT CORRADE_TARGET_EMSCRIPTEN) +# Under Emscripten, GL is linked implicitly. With MINIMAL_RUNTIME you need to +# specify -lGL. Simply set the library name to that. +if(CORRADE_TARGET_EMSCRIPTEN) + set(OPENGLES2_LIBRARY GL CACHE STRING "Path to a library." FORCE) +else() find_library(OPENGLES2_LIBRARY NAMES GLESv2 @@ -49,38 +54,25 @@ if(NOT CORRADE_TARGET_EMSCRIPTEN) # iOS OpenGLES) - set(OPENGLES2_LIBRARY_NEEDED OPENGLES2_LIBRARY) endif() -# Include dir -find_path(OPENGLES2_INCLUDE_DIR NAMES - GLES2/gl2.h - - # iOS - ES2/gl.h) - include(FindPackageHandleStandardArgs) find_package_handle_standard_args(OpenGLES2 DEFAULT_MSG - ${OPENGLES2_LIBRARY_NEEDED} - OPENGLES2_INCLUDE_DIR) + OPENGLES2_LIBRARY) if(NOT TARGET OpenGLES2::OpenGLES2) - if(OPENGLES2_LIBRARY_NEEDED) - # Work around BUGGY framework support on macOS - # http://public.kitware.com/pipermail/cmake/2016-April/063179.html - if(CORRADE_TARGET_APPLE AND ${OPENGLES2_LIBRARY} MATCHES "\\.framework$") - add_library(OpenGLES2::OpenGLES2 INTERFACE IMPORTED) - set_property(TARGET OpenGLES2::OpenGLES2 APPEND PROPERTY - INTERFACE_LINK_LIBRARIES ${OPENGLES2_LIBRARY}) - else() - add_library(OpenGLES2::OpenGLES2 UNKNOWN IMPORTED) - set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY - IMPORTED_LOCATION ${OPENGLES2_LIBRARY}) - endif() - else() + # Work around BUGGY framework support on macOS. Do this also in case of + # Emscripten, since there we don't have a location either. + # http://public.kitware.com/pipermail/cmake/2016-April/063179.html + if((CORRADE_TARGET_APPLE AND ${OPENGLES2_LIBRARY} MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) add_library(OpenGLES2::OpenGLES2 INTERFACE IMPORTED) + set_property(TARGET OpenGLES2::OpenGLES2 APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${OPENGLES2_LIBRARY}) + else() + add_library(OpenGLES2::OpenGLES2 UNKNOWN IMPORTED) + set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY + IMPORTED_LOCATION ${OPENGLES2_LIBRARY}) endif() - - set_property(TARGET OpenGLES2::OpenGLES2 PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${OPENGLES2_INCLUDE_DIR}) endif() + +mark_as_advanced(OPENGLES2_LIBRARY) diff --git a/modules/FindOpenGLES3.cmake b/modules/FindOpenGLES3.cmake index 413be61..48ae023 100644 --- a/modules/FindOpenGLES3.cmake +++ b/modules/FindOpenGLES3.cmake @@ -10,7 +10,10 @@ # Additionally these variables are defined for internal usage: # # OPENGLES3_LIBRARY - OpenGL ES 3 library -# OPENGLES3_INCLUDE_DIR - Include dir +# +# Please note this find module is tailored especially for the needs of Magnum. +# In particular, it depends on its platform definitions and doesn't look for +# OpenGL ES includes as Magnum has its own, generated using flextGL. # # @@ -38,9 +41,11 @@ # DEALINGS IN THE SOFTWARE. # -# In Emscripten OpenGL ES 3 is linked automatically, thus no need to find the -# library. -if(NOT CORRADE_TARGET_EMSCRIPTEN) +# Under Emscripten, GL is linked implicitly. With MINIMAL_RUNTIME you need to +# specify -lGL. Simply set the library name to that. +if(CORRADE_TARGET_EMSCRIPTEN) + set(OPENGLES3_LIBRARY GL CACHE STRING "Path to a library." FORCE) +else() find_library(OPENGLES3_LIBRARY NAMES GLESv3 @@ -53,41 +58,26 @@ if(NOT CORRADE_TARGET_EMSCRIPTEN) # iOS OpenGLES) - set(OPENGLES3_LIBRARY_NEEDED OPENGLES3_LIBRARY) endif() -# Include dir -find_path(OPENGLES3_INCLUDE_DIR NAMES - GLES3/gl3.h - - # iOS - ES3/gl.h) - include(FindPackageHandleStandardArgs) find_package_handle_standard_args("OpenGLES3" DEFAULT_MSG - ${OPENGLES3_LIBRARY_NEEDED} - OPENGLES3_INCLUDE_DIR) + OPENGLES3_LIBRARY) if(NOT TARGET OpenGLES3::OpenGLES3) - if(OPENGLES3_LIBRARY_NEEDED) - # Work around BUGGY framework support on macOS - # http://public.kitware.com/pipermail/cmake/2016-April/063179.html - if(CORRADE_TARGET_APPLE AND ${OPENGLES3_LIBRARY} MATCHES "\\.framework$") - add_library(OpenGLES3::OpenGLES3 INTERFACE IMPORTED) - set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY - INTERFACE_LINK_LIBRARIES ${OPENGLES3_LIBRARY}) - else() - add_library(OpenGLES3::OpenGLES3 UNKNOWN IMPORTED) - set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY - IMPORTED_LOCATION ${OPENGLES3_LIBRARY}) - endif() - else() + # Work around BUGGY framework support on macOS. Do this also in case of + # Emscripten, since there we don't have a location either. + # http://public.kitware.com/pipermail/cmake/2016-April/063179.html + if((CORRADE_TARGET_APPLE AND ${OPENGLES3_LIBRARY} MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) add_library(OpenGLES3::OpenGLES3 INTERFACE IMPORTED) + set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${OPENGLES3_LIBRARY}) + else() + add_library(OpenGLES3::OpenGLES3 UNKNOWN IMPORTED) + set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY + IMPORTED_LOCATION ${OPENGLES3_LIBRARY}) endif() - set_property(TARGET OpenGLES3::OpenGLES3 PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${OPENGLES3_INCLUDE_DIR}) - # Emscripten needs a special flag to use WebGL 2. CMake 3.13 allows to set # this via INTERFACE_LINK_OPTIONS, for older versions we modify the global # CMAKE_EXE_LINKER_FLAGS inside FindMagnum.cmake. @@ -98,3 +88,5 @@ if(NOT TARGET OpenGLES3::OpenGLES3) INTERFACE_LINK_OPTIONS "SHELL:-s USE_WEBGL2=1") endif() endif() + +mark_as_advanced(OPENGLES3_LIBRARY)