aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorfuzzard <fuzzard@kodi.tv>2023-09-10 15:40:43 +1000
committerfuzzard <fuzzard@kodi.tv>2023-09-27 19:09:18 +1000
commit6c05fdeb469e5218427c3f6cd3a7699f8f76a2ac (patch)
tree91888276a95e72ecb44c660ad0084dd7162b41ad /cmake
parent0dddec4199edcf750bbef5dc0933e0721efdb75b (diff)
[cmake] FindOpenGL migrate to full TARGET usage
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/FindOpenGl.cmake65
1 files changed, 37 insertions, 28 deletions
diff --git a/cmake/modules/FindOpenGl.cmake b/cmake/modules/FindOpenGl.cmake
index e155cda520..cabee46db3 100644
--- a/cmake/modules/FindOpenGl.cmake
+++ b/cmake/modules/FindOpenGl.cmake
@@ -3,38 +3,47 @@
# ----------
# Finds the FindOpenGl library
#
-# This will define the following variables::
+# This will define the following target:
#
-# OPENGL_FOUND - system has OpenGl
-# OPENGL_INCLUDE_DIRS - the OpenGl include directory
-# OPENGL_LIBRARIES - the OpenGl libraries
-# OPENGL_DEFINITIONS - the OpenGl definitions
+# OpenGL::GL - The OpenGL library
-if(PKG_CONFIG_FOUND)
- pkg_check_modules(PC_OPENGL gl QUIET)
-endif()
+if(NOT TARGET OpenGL::GL)
+ find_package(PkgConfig)
+ if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_OPENGL gl QUIET)
+ endif()
-if(NOT CORE_SYSTEM_NAME STREQUAL osx)
- find_path(OPENGL_INCLUDE_DIR GL/gl.h
- PATHS ${PC_OPENGL_gl_INCLUDEDIR})
- find_library(OPENGL_gl_LIBRARY NAMES GL
- PATHS ${PC_OPENGL_gl_LIBDIR})
-else()
- find_library(OPENGL_gl_LIBRARY NAMES OpenGL
- PATHS ${CMAKE_OSX_SYSROOT}/System/Library
+ find_library(OPENGL_gl_LIBRARY NAMES GL OpenGL
+ HINTS ${PC_OPENGL_gl_LIBDIR} ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
- NO_DEFAULT_PATH)
- set(OPENGL_INCLUDE_DIR ${OPENGL_gl_LIBRARY}/Headers)
-endif()
+ NO_CACHE)
+ find_path(OPENGL_INCLUDE_DIR NAMES GL/gl.h gl.h
+ HINTS ${PC_OPENGL_gl_INCLUDEDIR} ${OPENGL_gl_LIBRARY}/Headers
+ NO_CACHE)
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(OpenGl
- REQUIRED_VARS OPENGL_gl_LIBRARY OPENGL_INCLUDE_DIR)
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(OpenGl
+ REQUIRED_VARS OPENGL_gl_LIBRARY OPENGL_INCLUDE_DIR)
-if(OPENGL_FOUND)
- set(OPENGL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
- set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY})
- set(OPENGL_DEFINITIONS -DHAS_GL=1)
-endif()
+ if(OPENGL_FOUND)
+ if(CORE_SYSTEM_NAME STREQUAL osx)
+ # Cmake only added support for Frameworks as the IMPORTED_LOCATION as of 3.28
+ # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8586
+ # Until we move to cmake 3.28 as minimum, explicitly set to binary inside framework
+ if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$")
+ set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}")
+ if(EXISTS "${_gl_fw}.tbd")
+ string(APPEND _gl_fw ".tbd")
+ endif()
+ set(OPENGL_gl_LIBRARY ${_gl_fw})
+ endif()
+ endif()
-mark_as_advanced(OPENGL_INCLUDE_DIR OPENGL_gl_LIBRARY)
+ add_library(OpenGL::GL UNKNOWN IMPORTED)
+ set_target_properties(OpenGL::GL PROPERTIES
+ IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
+ INTERFACE_COMPILE_DEFINITIONS HAS_GL=1)
+ set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP OpenGL::GL)
+ endif()
+endif()