Browse Source

modules: update FindCorrade and FindMagnum*.

Modules for Magnum dependencies are no longer needed, as it installs and
uses them automatically.
next
Vladimír Vondruš 2 years ago
parent
commit
1f5a8494d4
  1. 131
      modules/FindCorrade.cmake
  2. 86
      modules/FindEGL.cmake
  3. 141
      modules/FindGLFW.cmake
  4. 151
      modules/FindMagnum.cmake
  5. 78
      modules/FindOpenGLES2.cmake
  6. 92
      modules/FindOpenGLES3.cmake
  7. 286
      modules/FindSDL2.cmake

131
modules/FindCorrade.cmake

@ -118,8 +118,13 @@
# CORRADE_*_LIBRARY_DEBUG - Debug version of given library, if found
# CORRADE_*_LIBRARY_RELEASE - Release version of given library, if found
# CORRADE_*_EXECUTABLE - Location of given executable, if found
# CORRADE_*_EXECUTABLE_EMULATOR - Emulator to run CORRADE_*_EXECUTABLE, if a
# non-native version was found when cross-compiling
# CORRADE_USE_MODULE - Path to UseCorrade.cmake module (included
# automatically)
# CORRADE_DEPENDENCY_MODULE_DIR - Path to Find modules for dependencies used
# internally by Corrade. Defined only if any such modules are expected to
# exist on given platform.
# CORRADE_TESTSUITE_XCTEST_RUNNER - Path to XCTestRunner.mm.in file
# CORRADE_TESTSUITE_ADB_RUNNER - Path to AdbRunner.sh file
# CORRADE_UTILITY_JS - Path to CorradeUtility.js file
@ -272,7 +277,7 @@
# This file is part of Corrade.
#
# Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
# 2017, 2018, 2019, 2020, 2021, 2022, 2023
# 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024
# Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
@ -355,6 +360,12 @@ find_path(_CORRADE_MODULE_DIR
NAMES UseCorrade.cmake CorradeLibSuffix.cmake
PATH_SUFFIXES share/cmake/Corrade)
mark_as_advanced(_CORRADE_MODULE_DIR)
if(CORRADE_TARGET_EMSCRIPTEN)
find_path(CORRADE_DEPENDENCY_MODULE_DIR
NAMES FindNodeJs.cmake
PATH_SUFFIXES share/cmake/Corrade/dependencies)
mark_as_advanced(CORRADE_DEPENDENCY_MODULE_DIR)
endif()
set(CORRADE_USE_MODULE ${_CORRADE_MODULE_DIR}/UseCorrade.cmake)
set(CORRADE_LIB_SUFFIX_MODULE ${_CORRADE_MODULE_DIR}/CorradeLibSuffix.cmake)
@ -407,6 +418,11 @@ if(Corrade_FIND_COMPONENTS)
list(REMOVE_DUPLICATES Corrade_FIND_COMPONENTS)
endif()
# Special cases of include paths. Libraries not listed here have a path suffix
# and include name derived from the library name in the loop below.
set(_CORRADE_MAIN_INCLUDE_PATH_SUFFIX Corrade)
set(_CORRADE_MAIN_INCLUDE_PATH_NAMES Corrade.h)
# Find all components
foreach(_component ${Corrade_FIND_COMPONENTS})
string(TOUPPER ${_component} _COMPONENT)
@ -417,7 +433,16 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
if(TARGET Corrade::${_component})
set(Corrade_${_component}_FOUND TRUE)
else()
unset(Corrade_${_component}_FOUND)
# Default include path names to look for for library / header-only
# components, unless set above already
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS)
if(NOT _CORRADE_${_COMPONENT}_INCLUDE_PATH_SUFFIX)
set(_CORRADE_${_COMPONENT}_INCLUDE_PATH_SUFFIX Corrade/${_component})
endif()
if(NOT _CORRADE_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_CORRADE_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h)
endif()
endif()
# Library (and not header-only) components
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS AND NOT _component IN_LIST _CORRADE_HEADER_ONLY_COMPONENTS)
@ -428,20 +453,6 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
find_library(CORRADE_${_COMPONENT}_LIBRARY_RELEASE Corrade${_component})
mark_as_advanced(CORRADE_${_COMPONENT}_LIBRARY_DEBUG
CORRADE_${_COMPONENT}_LIBRARY_RELEASE)
if(CORRADE_${_COMPONENT}_LIBRARY_RELEASE)
set_property(TARGET Corrade::${_component} APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET Corrade::${_component} PROPERTY
IMPORTED_LOCATION_RELEASE ${CORRADE_${_COMPONENT}_LIBRARY_RELEASE})
endif()
if(CORRADE_${_COMPONENT}_LIBRARY_DEBUG)
set_property(TARGET Corrade::${_component} APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_property(TARGET Corrade::${_component} PROPERTY
IMPORTED_LOCATION_DEBUG ${CORRADE_${_COMPONENT}_LIBRARY_DEBUG})
endif()
endif()
# Header-only library components
@ -449,13 +460,6 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
add_library(Corrade::${_component} INTERFACE IMPORTED)
endif()
# Default include path names to look for for library / header-only
# components
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS)
set(_CORRADE_${_COMPONENT}_INCLUDE_PATH_SUFFIX Corrade/${_component})
set(_CORRADE_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h)
endif()
# Executable components
if(_component IN_LIST _CORRADE_EXECUTABLE_COMPONENTS)
add_executable(Corrade::${_component} IMPORTED)
@ -463,12 +467,72 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
find_program(CORRADE_${_COMPONENT}_EXECUTABLE corrade-${_component})
mark_as_advanced(CORRADE_${_COMPONENT}_EXECUTABLE)
# If the executable wasn't found, we're cross-compiling, an
# emulator is set and we're on CMake 3.6+ that actually uses
# CMAKE_CROSSCOMPILING_EMULATOR in add_custom_command((), try to
# find the cross-compiled version as a (slower) fallback. This
# assumes the toolchain sets CMAKE_FIND_ROOT_PATH_MODE_PROGRAM to
# NEVER, i.e. that the search is restricted to native executables
# by default.
if(NOT CORRADE_${_COMPONENT}_EXECUTABLE AND CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR AND NOT CMAKE_VERSION VERSION_LESS 3.6)
# Additionally, there are no CMAKE_FIND_PROGRAM_SUFFIXES akin
# to CMAKE_FIND_LIBRARY_SUFFIXES for libraries, so we have to
# try manually.
if(CORRADE_TARGET_EMSCRIPTEN)
set(_CORRADE_PROGRAM_EXTENSION .js)
endif()
find_program(CORRADE_${_COMPONENT}_EXECUTABLE
NAMES
corrade-${_component}
corrade-${_component}${_CORRADE_PROGRAM_EXTENSION}
ONLY_CMAKE_FIND_ROOT_PATH)
if(CORRADE_${_COMPONENT}_EXECUTABLE)
set(CORRADE_${_COMPONENT}_EXECUTABLE_EMULATOR ${CMAKE_CROSSCOMPILING_EMULATOR} CACHE PATH "Emulator for running a cross-compiled corrade-${_component} executable")
mark_as_advanced(CORRADE_${_COMPONENT}_EXECUTABLE_EMULATOR)
endif()
endif()
if(CORRADE_${_COMPONENT}_EXECUTABLE)
set_property(TARGET Corrade::${_component} PROPERTY
IMPORTED_LOCATION ${CORRADE_${_COMPONENT}_EXECUTABLE})
endif()
endif()
# Find library includes
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS)
find_path(_CORRADE_${_COMPONENT}_INCLUDE_DIR
NAMES ${_CORRADE_${_COMPONENT}_INCLUDE_PATH_NAMES}
HINTS ${CORRADE_INCLUDE_DIR}/${_CORRADE_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
mark_as_advanced(_CORRADE_${_COMPONENT}_INCLUDE_DIR)
endif()
# Decide if the component was found. If not, skip the rest, which
# populates the target properties and finds additional dependencies. If
# found, the _FOUND variable may still get reset by something below.
if((_component IN_LIST _CORRADE_LIBRARY_COMPONENTS AND _CORRADE_${_COMPONENT}_INCLUDE_DIR AND (_component IN_LIST _CORRADE_HEADER_ONLY_COMPONENTS OR CORRADE_${_COMPONENT}_LIBRARY_RELEASE OR CORRADE_${_COMPONENT}_LIBRARY_DEBUG)) OR (_component IN_LIST _CORRADE_EXECUTABLE_COMPONENTS AND CORRADE_${_COMPONENT}_EXECUTABLE))
set(Corrade_${_component}_FOUND TRUE)
else()
set(Corrade_${_component}_FOUND FALSE)
continue()
endif()
# Library location for (non-header-only) libraries
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS AND NOT _component IN_LIST _CORRADE_HEADER_ONLY_COMPONENTS)
if(CORRADE_${_COMPONENT}_LIBRARY_RELEASE)
set_property(TARGET Corrade::${_component} APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET Corrade::${_component} PROPERTY
IMPORTED_LOCATION_RELEASE ${CORRADE_${_COMPONENT}_LIBRARY_RELEASE})
endif()
if(CORRADE_${_COMPONENT}_LIBRARY_DEBUG)
set_property(TARGET Corrade::${_component} APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_property(TARGET Corrade::${_component} PROPERTY
IMPORTED_LOCATION_DEBUG ${CORRADE_${_COMPONENT}_LIBRARY_DEBUG})
endif()
endif()
# No special setup for Containers library
# Interconnect library
@ -488,9 +552,6 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
# Main library
elseif(_component STREQUAL Main)
set(_CORRADE_${_COMPONENT}_INCLUDE_PATH_SUFFIX Corrade)
set(_CORRADE_${_COMPONENT}_INCLUDE_PATH_NAMES Corrade.h)
if(CORRADE_TARGET_WINDOWS)
if(NOT MINGW)
# Abusing INTERFACE_LINK_LIBRARIES because
@ -582,14 +643,6 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
endif()
endif()
# Find library includes
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS)
find_path(_CORRADE_${_COMPONENT}_INCLUDE_DIR
NAMES ${_CORRADE_${_COMPONENT}_INCLUDE_PATH_NAMES}
HINTS ${CORRADE_INCLUDE_DIR}/${_CORRADE_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
mark_as_advanced(_CORRADE_${_COMPONENT}_INCLUDE_DIR)
endif()
# Add inter-library dependencies
if(_component IN_LIST _CORRADE_LIBRARY_COMPONENTS OR _component IN_LIST _CORRADE_HEADER_ONLY_COMPONENTS)
foreach(_dependency ${_CORRADE_${_component}_DEPENDENCIES})
@ -599,16 +652,6 @@ foreach(_component ${Corrade_FIND_COMPONENTS})
endif()
endforeach()
endif()
# Decide if the component was found, unless the _FOUND is already set
# by something above.
if(NOT DEFINED Corrade_${_component}_FOUND)
if((_component IN_LIST _CORRADE_LIBRARY_COMPONENTS AND _CORRADE_${_COMPONENT}_INCLUDE_DIR AND (_component IN_LIST _CORRADE_HEADER_ONLY_COMPONENTS OR CORRADE_${_COMPONENT}_LIBRARY_RELEASE OR CORRADE_${_COMPONENT}_LIBRARY_DEBUG)) OR (_component IN_LIST _CORRADE_EXECUTABLE_COMPONENTS AND CORRADE_${_COMPONENT}_EXECUTABLE))
set(Corrade_${_component}_FOUND TRUE)
else()
set(Corrade_${_component}_FOUND FALSE)
endif()
endif()
endif()
endforeach()

86
modules/FindEGL.cmake

@ -1,86 +0,0 @@
#.rst:
# Find EGL
# --------
#
# Finds the EGL library. This module defines:
#
# EGL_FOUND - True if EGL library is found
# EGL::EGL - EGL imported target
#
# Additionally these variables are defined for internal usage:
#
# EGL_LIBRARY - EGL library
# EGL_INCLUDE_DIR - Include dir
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Under Emscripten, EGL is linked implicitly. With MINIMAL_RUNTIME you need to
# specify -lEGL. Simply set the library name to that.
if(CORRADE_TARGET_EMSCRIPTEN)
set(EGL_LIBRARY EGL CACHE STRING "Path to a library." FORCE)
else()
find_library(EGL_LIBRARY NAMES
EGL
# ANGLE (CMake doesn't search for lib prefix on Windows)
libEGL
# On iOS a part of OpenGLES
OpenGLES)
endif()
# Include dir
find_path(EGL_INCLUDE_DIR NAMES
EGL/egl.h
# iOS
EAGL.h)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(EGL DEFAULT_MSG
EGL_LIBRARY
EGL_INCLUDE_DIR)
if(NOT TARGET EGL::EGL)
# 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)

141
modules/FindGLFW.cmake

@ -1,141 +0,0 @@
#.rst:
# Find GLFW
# ---------
#
# Finds the GLFW library using its cmake config if that exists, otherwise
# falls back to finding it manually. This module defines:
#
# GLFW_FOUND - True if GLFW library is found
# GLFW::GLFW - GLFW imported target
#
# Additionally, in case the config was not found, these variables are defined
# for internal usage:
#
# GLFW_LIBRARY - GLFW library
# GLFW_DLL_DEBUG - GLFW debug DLL on Windows, if found
# GLFW_DLL_RELEASE - GLFW release DLL on Windows, if found
# GLFW_INCLUDE_DIR - Root include dir
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# GLFW installs cmake package config files which handles dependencies in case
# GLFW is built statically. Try to find first, quietly, so it doesn't print
# loud messages when it's not found, since that's okay. If the glfw target
# already exists, it means we're using it through a CMake subproject -- don't
# attempt to find the package in that case.
if(NOT TARGET glfw)
find_package(glfw3 CONFIG QUIET)
endif()
# If either a glfw config file was found or we have a subproject, point
# GLFW::GLFW to that and exit -- nothing else to do here.
if(TARGET glfw)
if(NOT TARGET GLFW::GLFW)
# Aliases of (global) targets are only supported in CMake 3.11, so we
# work around it by this. This is easier than fetching all possible
# properties (which are impossible to track of) and then attempting to
# rebuild them into a new target.
add_library(GLFW::GLFW INTERFACE IMPORTED)
set_target_properties(GLFW::GLFW PROPERTIES INTERFACE_LINK_LIBRARIES glfw)
endif()
# Just to make FPHSA print some meaningful location, nothing else
get_target_property(_GLFW_INTERFACE_INCLUDE_DIRECTORIES glfw INTERFACE_INCLUDE_DIRECTORIES)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("GLFW" DEFAULT_MSG
_GLFW_INTERFACE_INCLUDE_DIRECTORIES)
if(CORRADE_TARGET_WINDOWS)
# .dll is in LOCATION, .lib is in IMPLIB. Yay, useful!
get_target_property(GLFW_DLL_DEBUG glfw IMPORTED_LOCATION_DEBUG)
get_target_property(GLFW_DLL_RELEASE glfw IMPORTED_LOCATION_RELEASE)
endif()
return()
endif()
if(CORRADE_TARGET_WINDOWS)
if(MSVC)
if(MSVC_VERSION VERSION_LESS 1910)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2015)
elseif(MSVC_VERSION VERSION_LESS 1920)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2017)
elseif(MSVC_VERSION VERSION_LESS 1930)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2019)
# MSVC 2022 17.10 overflowed the 1930 range to 1940, so assume a
# hypothetical MSVC 2025 will start with 1950.
elseif(MSVC_VERSION VERSION_LESS 1950)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2022)
else()
message(FATAL_ERROR "Unsupported MSVC version")
endif()
elseif(MINGW)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-mingw-w64)
else()
message(FATAL_ERROR "Unsupported compiler")
endif()
endif()
# In case no config file was found, try manually finding the library. Prefer
# the glfw3dll as it's a dynamic library.
find_library(GLFW_LIBRARY
NAMES glfw glfw3dll glfw3
PATH_SUFFIXES ${_GLFW_LIBRARY_PATH_SUFFIX})
if(CORRADE_TARGET_WINDOWS AND GLFW_LIBRARY MATCHES "glfw3dll.(lib|a)$")
# TODO: debug?
find_file(GLFW_DLL_RELEASE
NAMES glfw3.dll
PATH_SUFFIXES ${_GLFW_LIBRARY_PATH_SUFFIX})
endif()
# Include dir
find_path(GLFW_INCLUDE_DIR
NAMES GLFW/glfw3.h)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("GLFW" DEFAULT_MSG
GLFW_LIBRARY
GLFW_INCLUDE_DIR)
if(NOT TARGET GLFW::GLFW)
add_library(GLFW::GLFW UNKNOWN IMPORTED)
# Work around BUGGY framework support on macOS
# https://cmake.org/Bug/view.php?id=14105
if(CORRADE_TARGET_APPLE AND GLFW_LIBRARY MATCHES "\\.framework$")
set_property(TARGET GLFW::GLFW PROPERTY IMPORTED_LOCATION ${GLFW_LIBRARY}/GLFW)
else()
set_property(TARGET GLFW::GLFW PROPERTY IMPORTED_LOCATION ${GLFW_LIBRARY})
endif()
set_property(TARGET GLFW::GLFW PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${GLFW_INCLUDE_DIR})
endif()
mark_as_advanced(GLFW_LIBRARY GLFW_INCLUDE_DIR)

151
modules/FindMagnum.cmake

@ -135,9 +135,9 @@
# globals unique even across different shared libraries
# MAGNUM_TARGET_GL - Defined if compiled with OpenGL interop
# MAGNUM_TARGET_GLES - Defined if compiled for OpenGL ES
# MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0
# MAGNUM_TARGET_GLES3 - Defined if compiled for OpenGL ES 3.0
# MAGNUM_TARGET_WEBGL - Defined if compiled for WebGL
# MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0 / WebGL
# 1 instead of OpenGL ES 3.0+ / WebGL 2
# MAGNUM_TARGET_EGL - Defined if compiled for EGL instead of a
# platform-specific OpenGL support library like CGL, EAGL, GLX or WGL
# MAGNUM_TARGET_VK - Defined if compiled with Vulkan interop
@ -152,6 +152,8 @@
# Android, Emscripten or Windows RT. Use MAGNUM_TARGET_EGL instead.
# MAGNUM_TARGET_DESKTOP_GLES` - Defined if compiled for OpenGL ES but
# GLX / WGL is used instead of EGL. Use MAGNUM_TARGET_EGL instead.
# MAGNUM_TARGET_GLES3 - Defined if compiled for OpenGL ES 3.0+ /
# WebGL 2. Use an inverse of the MAGNUM_TARGET_GLES2 variable instead.
#
# Additionally these variables are defined for internal usage:
#
@ -206,7 +208,8 @@
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
# 2020, 2021, 2022, 2023, 2024
# Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@ -291,7 +294,6 @@ set(_magnumFlags
TARGET_GL
TARGET_GLES
TARGET_GLES2
TARGET_GLES3
TARGET_WEBGL
TARGET_EGL
TARGET_VK)
@ -316,6 +318,33 @@ if(MAGNUM_BUILD_DEPRECATED)
set(MAGNUM_TARGET_DESKTOP_GLES 1)
endif()
endif()
if(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_GLES2)
set(MAGNUM_TARGET_GLES3 1)
endif()
endif()
# CMake module dir for dependencies. It might not be present at all if no
# feature that needs them is enabled, in which case it'll be left at NOTFOUND.
# But in that case it should also not be subsequently needed for any
# find_package(). If this is called from a superproject, the
# _MAGNUM_DEPENDENCY_MODULE_DIR is already set by modules/CMakeLists.txt.
find_path(_MAGNUM_DEPENDENCY_MODULE_DIR
NAMES
FindEGL.cmake FindGLFW.cmake FindOpenAL.cmake FindOpenGLES2.cmake
FindOpenGLES3.cmake FindSDL2.cmake FindVulkan.cmake
PATH_SUFFIXES share/cmake/Magnum/dependencies)
mark_as_advanced(_MAGNUM_DEPENDENCY_MODULE_DIR)
# If the module dir is found and is not present in CMAKE_MODULE_PATH already
# (such as when someone explicitly added it, or if it's the Magnum's modules/
# dir in case of a superproject), add it as the first before all other. Set a
# flag to remove it again at the end, so the modules don't clash with Find
# modules of the same name from other projects.
if(_MAGNUM_DEPENDENCY_MODULE_DIR AND NOT _MAGNUM_DEPENDENCY_MODULE_DIR IN_LIST CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH ${_MAGNUM_DEPENDENCY_MODULE_DIR} ${CMAKE_MODULE_PATH})
set(_MAGNUM_REMOVE_DEPENDENCY_MODULE_DIR_FROM_CMAKE_PATH ON)
else()
unset(_MAGNUM_REMOVE_DEPENDENCY_MODULE_DIR_FROM_CMAKE_PATH)
endif()
# Base Magnum library
@ -558,6 +587,15 @@ if(Magnum_FIND_COMPONENTS)
list(REMOVE_DUPLICATES Magnum_FIND_COMPONENTS)
endif()
# Special cases of include paths. Libraries not listed here have a path suffix
# and include name derived from the library name in the loop below.
set(_MAGNUM_MATERIALTOOLS_INCLUDE_PATH_NAMES PhongToPbrMetallicRoughness.h)
set(_MAGNUM_MESHTOOLS_INCLUDE_PATH_NAMES CompressIndices.h)
set(_MAGNUM_OPENGLTESTER_INCLUDE_PATH_SUFFIX Magnum/GL)
set(_MAGNUM_VULKANTESTER_INCLUDE_PATH_SUFFIX Magnum/Vk)
set(_MAGNUM_PRIMITIVES_INCLUDE_PATH_NAMES Cube.h)
set(_MAGNUM_SCENETOOLS_INCLUDE_PATH_NAMES Hierarchy.h)
# Find all components. Maintain a list of components that'll need to have
# their optional dependencies checked.
set(_MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD )
@ -574,9 +612,20 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS)
add_library(Magnum::${_component} UNKNOWN IMPORTED)
# Set library defaults, find the library
# Include path names to find, unless specified above already.
# Application and context libraries are a special case as well.
if(_component MATCHES ".+Application")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
elseif(_component MATCHES ".+Context")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES GLContext.h)
endif()
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/${_component})
endif()
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h)
endif()
# Try to find both debug and release version
find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG Magnum${_component}-d)
@ -595,7 +644,9 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Audio importer class is Audio::*Importer, thus we need to
# convert *AudioImporter.h to *Importer.h
string(REPLACE "AudioImporter" "Importer" _MAGNUM_${_COMPONENT}_HEADER_NAME "${_component}")
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_MAGNUM_${_COMPONENT}_HEADER_NAME}.h)
endif()
# ShaderConverter plugin specific name suffixes
elseif(_component MATCHES ".+ShaderConverter$")
@ -622,8 +673,10 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fontconverters)
endif()
# Don't override the exception for *AudioImporter plugins
# Include path names to find, unless specified above
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX MagnumPlugins/${_component})
endif()
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h)
endif()
@ -671,6 +724,26 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
continue()
endif()
# Find library/plugin includes
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS)
find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR
NAMES ${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES}
HINTS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
mark_as_advanced(_MAGNUM_${_COMPONENT}_INCLUDE_DIR)
endif()
# Decide if the library was found. If not, skip the rest, which
# populates the target properties and finds additional dependencies.
# This means that the rest can also rely on that e.g. FindEGL.cmake is
# present in _MAGNUM_DEPENDENCY_MODULE_DIR -- given that the library
# needing EGL was found, it likely also installed FindEGL for itself.
if(((_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS) AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR AND (MAGNUM_${_COMPONENT}_LIBRARY_DEBUG OR MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)) OR (_component IN_LIST _MAGNUM_EXECUTABLE_COMPONENTS AND MAGNUM_${_COMPONENT}_EXECUTABLE))
set(Magnum_${_component}_FOUND TRUE)
else()
set(Magnum_${_component}_FOUND FALSE)
continue()
endif()
# Library location for libraries/plugins
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS)
if(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)
@ -690,8 +763,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Applications
if(_component MATCHES ".+Application")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
# Android application dependencies
if(_component STREQUAL AndroidApplication)
find_package(EGL)
@ -854,9 +925,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Context libraries
elseif(_component MATCHES ".+Context")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES GLContext.h)
# GLX context dependencies
if(_component STREQUAL GlxContext)
# With GLVND (since CMake 3.10) we need to explicitly link to
@ -917,46 +985,23 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
find_package(OpenGLES2 REQUIRED)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGLES2::OpenGLES2)
elseif(MAGNUM_TARGET_GLES3)
else()
find_package(OpenGLES3 REQUIRED)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGLES3::OpenGLES3)
endif()
# MaterialTools library
elseif(_component STREQUAL MaterialTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES PhongToPbrMetallicRoughness.h)
# MeshTools library
elseif(_component STREQUAL MeshTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h)
# OpenGLTester library
elseif(_component STREQUAL OpenGLTester)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/GL)
# VulkanTester library
elseif(_component STREQUAL VulkanTester)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Vk)
# Primitives library
elseif(_component STREQUAL Primitives)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h)
# No special setup for MaterialTools library
# No special setup for MeshTools library
# No special setup for OpenGLTester library
# No special setup for VulkanTester library
# No special setup for Primitives library
# No special setup for SceneGraph library
# SceneTools library
elseif(_component STREQUAL SceneTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Hierarchy.h)
# No special setup for SceneTools library
# No special setup for ShaderTools library
# No special setup for Shaders library
# No special setup for Text library
# TextureTools library
elseif(_component STREQUAL TextureTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h)
# No special setup for TextureTools library
# No special setup for Trade library
# Vk library
@ -977,14 +1022,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# No special setup for TgaImporter plugin
# No special setup for WavAudioImporter plugin
# Find library/plugin includes
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS)
find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR
NAMES ${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES}
HINTS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
mark_as_advanced(_MAGNUM_${_COMPONENT}_INCLUDE_DIR)
endif()
# Automatic import of static plugins. Skip in case the include dir was
# not found -- that'll fail later with a proper message. Skip it also
# if the include dir doesn't contain the generated configure.h, which
@ -1026,13 +1063,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
list(APPEND _MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD ${_component})
endif()
endif()
# Decide if the library was found
if(((_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS) AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR AND (MAGNUM_${_COMPONENT}_LIBRARY_DEBUG OR MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)) OR (_component IN_LIST _MAGNUM_EXECUTABLE_COMPONENTS AND MAGNUM_${_COMPONENT}_EXECUTABLE))
set(Magnum_${_component}_FOUND TRUE)
else()
set(Magnum_${_component}_FOUND FALSE)
endif()
endif()
# Global aliases for Windowless*Application, *Application and *Context
@ -1109,6 +1139,13 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.16)
set(_MAGNUM_REASON_FAILURE_MESSAGE REASON_FAILURE_MESSAGE "${_MAGNUM_REASON_FAILURE_MESSAGE}")
endif()
# Remove Magnum's dependency module dir from CMAKE_MODULE_PATH again. Do it
# before the FPHSA call which may exit early in case of a failure.
if(_MAGNUM_REMOVE_DEPENDENCY_MODULE_DIR_FROM_CMAKE_PATH)
list(REMOVE_ITEM CMAKE_MODULE_PATH ${_MAGNUM_DEPENDENCY_MODULE_DIR})
unset(_MAGNUM_REMOVE_DEPENDENCY_MODULE_DIR_FROM_CMAKE_PATH)
endif()
# Complete the check with also all components
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Magnum

78
modules/FindOpenGLES2.cmake

@ -1,78 +0,0 @@
#.rst:
# Find OpenGL ES 2
# ----------------
#
# Finds the OpenGL ES 2 library. This module defines:
#
# OpenGLES2_FOUND - True if OpenGL ES 2 library is found
# OpenGLES2::OpenGLES2 - OpenGL ES 2 imported target
#
# Additionally these variables are defined for internal usage:
#
# OPENGLES2_LIBRARY - OpenGL ES 2 library
#
# 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.
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# 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
# ANGLE (CMake doesn't search for lib prefix on Windows)
libGLESv2
# iOS
OpenGLES)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenGLES2 DEFAULT_MSG
OPENGLES2_LIBRARY)
if(NOT TARGET OpenGLES2::OpenGLES2)
# 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()
endif()
mark_as_advanced(OPENGLES2_LIBRARY)

92
modules/FindOpenGLES3.cmake

@ -1,92 +0,0 @@
#.rst:
# Find OpenGL ES 3
# ----------------
#
# Finds the OpenGL ES 3 library. This module defines:
#
# OpenGLES3_FOUND - True if OpenGL ES 3 library is found
# OpenGLES3::OpenGLES3 - OpenGL ES 3 imported target
#
# Additionally these variables are defined for internal usage:
#
# OPENGLES3_LIBRARY - OpenGL ES 3 library
#
# 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.
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# 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
# Used by Android
GLESv3
# On some platforms (e.g. desktop emulation with Mesa or NVidia) ES3
# support is provided in ES2 lib
GLESv2
# ANGLE (CMake doesn't search for lib prefix on Windows)
libGLESv2
# iOS
OpenGLES)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("OpenGLES3" DEFAULT_MSG
OPENGLES3_LIBRARY)
if(NOT TARGET OpenGLES3::OpenGLES3)
# 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()
# Emscripten needs a special flag to use WebGL 2
if(CORRADE_TARGET_EMSCRIPTEN)
if(CMAKE_VERSION VERSION_LESS 3.13)
message(FATAL_ERROR "CMake 3.13+ is required in order to specify Emscripten linker options")
endif()
set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY
INTERFACE_LINK_OPTIONS "SHELL:-s USE_WEBGL2=1")
endif()
endif()
mark_as_advanced(OPENGLES3_LIBRARY)

286
modules/FindSDL2.cmake

@ -1,286 +0,0 @@
#.rst:
# Find SDL2
# ---------
#
# Finds the SDL2 library. This module defines:
#
# SDL2_FOUND - True if SDL2 library is found
# SDL2::SDL2 - SDL2 imported target
#
# Additionally these variables are defined for internal usage:
#
# SDL2_LIBRARY_DEBUG - SDL2 debug library, if found
# SDL2_LIBRARY_RELEASE - SDL2 release library, if found
# SDL2_DLL_DEBUG - SDL2 debug DLL on Windows, if found
# SDL2_DLL_RELEASE - SDL2 release DLL on Windows, if found
# SDL2_INCLUDE_DIR - Root include dir
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2018 Jonathan Hale <squareys@googlemail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# If we have a CMake subproject, use the targets directly. I'd prefer the
# static variant, however SDL2 defines its own SDL2::SDL2 alias for only the
# dynamic variant since https://github.com/libsdl-org/SDL/pull/4074 and so I'm
# forced to use that, if available.
if(TARGET SDL2)
# In case we don't have https://github.com/libsdl-org/SDL/pull/4074 yet,
# do the alias ourselves.
if(NOT TARGET SDL2::SDL2)
# Aliases of (global) targets are only supported in CMake 3.11, so we
# work around it by this. This is easier than fetching all possible
# properties (which are impossible to track of) and then attempting to
# rebuild them into a new target.
add_library(SDL2::SDL2 INTERFACE IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES SDL2)
endif()
# Just to make FPHSA print some meaningful location, nothing else. Not
# using the INTERFACE_INCLUDE_DIRECTORIES as that contains
# $<BUILD_INTERFACE and looks ugly in the output. Funnily enough, the
# BUILD_INTERFACE thing works here without having to override it with
# custom-found paths like I do in FindAssimp and elsewhere. Needs further
# investigation.
get_target_property(_SDL2_SOURCE_DIR SDL2 SOURCE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("SDL2" DEFAULT_MSG _SDL2_SOURCE_DIR)
if(CORRADE_TARGET_WINDOWS)
# .dll is in LOCATION, .lib is in IMPLIB. Yay, useful!
get_target_property(SDL2_DLL_DEBUG SDL2 IMPORTED_LOCATION_DEBUG)
get_target_property(SDL2_DLL_RELEASE SDL2 IMPORTED_LOCATION_RELEASE)
endif()
return()
# The static build is a separate target for some reason. I wonder HOW that
# makes more sense than just having a build-time option for static/shared and
# use the same name for both. Are all depending projects supposed to branch on
# it like this?!
elseif(TARGET SDL2-static)
# The target should not be defined by SDL itself. If it is, that's from us.
if(NOT TARGET SDL2::SDL2)
# Aliases of (global) targets are only supported in CMake 3.11, so we
# work around it by this. This is easier than fetching all possible
# properties (which are impossible to track of) and then attempting to
# rebuild them into a new target.
add_library(SDL2::SDL2 INTERFACE IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES SDL2-static)
endif()
# Just to make FPHSA print some meaningful location, nothing else
get_target_property(_SDL2_SOURCE_DIR SDL2-static SOURCE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("SDL2" DEFAULT_MSG _SDL2_SOURCE_DIR)
return()
endif()
# In Emscripten SDL is linked automatically, thus no need to find the library.
# Also the includes are in SDL subdirectory, not SDL2.
if(CORRADE_TARGET_EMSCRIPTEN)
set(_SDL2_PATH_SUFFIXES SDL)
else()
set(_SDL2_PATH_SUFFIXES SDL2)
if(WIN32)
# Precompiled libraries for MSVC are in x86/x64 subdirectories
if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_SDL2_LIBRARY_PATH_SUFFIX lib/x64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(_SDL2_LIBRARY_PATH_SUFFIX lib/x86)
endif()
# Both includes and libraries for MinGW are in some directory deep
# inside. There's also a CMake config file but it has HARDCODED path
# to /opt/local/i686-w64-mingw32, which doesn't make ANY SENSE,
# especially on Windows.
elseif(MINGW)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_SDL2_LIBRARY_PATH_SUFFIX x86_64-w64-mingw32/lib)
set(_SDL2_RUNTIME_PATH_SUFFIX x86_64-w64-mingw32/bin)
list(APPEND _SDL2_PATH_SUFFIXES x86_64-w64-mingw32/include/SDL2)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(_SDL2_LIBRARY_PATH_SUFFIX i686-w64-mingw32/lib)
set(_SDL2_RUNTIME_PATH_SUFFIX i686-w64-mingw32/lib)
list(APPEND _SDL2_PATH_SUFFIXES i686-w64-mingw32/include/SDL2)
endif()
else()
message(FATAL_ERROR "Unsupported compiler")
endif()
endif()
find_library(SDL2_LIBRARY_RELEASE
# Compiling SDL2 from scratch on macOS creates dead libSDL2.so symlink
# which CMake somehow prefers before the SDL2-2.0.dylib file. Making
# the dylib first so it is preferred. Not sure how this maps to debug
# config though :/
NAMES SDL2-2.0 SDL2 SDL2-static
PATH_SUFFIXES ${_SDL2_LIBRARY_PATH_SUFFIX})
find_library(SDL2_LIBRARY_DEBUG
NAMES SDL2d SDL2-staticd
PATH_SUFFIXES ${_SDL2_LIBRARY_PATH_SUFFIX})
# FPHSA needs one of the _DEBUG/_RELEASE variables to check that the
# library was found -- using SDL_LIBRARY, which will get populated by
# select_library_configurations() below.
set(SDL2_LIBRARY_NEEDED SDL2_LIBRARY)
endif()
include(SelectLibraryConfigurations)
select_library_configurations(SDL2)
# Include dir
find_path(SDL2_INCLUDE_DIR
# We must search file which is present only in SDL2 and not in SDL1.
# Apparently when both SDL.h and SDL_scancode.h are specified, CMake is
# happy enough that it found SDL.h and doesn't bother about the other.
#
# On macOS, where the includes are not in SDL2/SDL.h form (which would
# solve this issue), but rather SDL2.framework/Headers/SDL.h, CMake might
# find SDL.framework/Headers/SDL.h if SDL1 is installed, which is wrong.
NAMES SDL_scancode.h
PATH_SUFFIXES ${_SDL2_PATH_SUFFIXES})
# DLL on Windows
if(CORRADE_TARGET_WINDOWS)
find_file(SDL2_DLL_RELEASE
NAMES SDL2.dll
PATH_SUFFIXES bin ${_SDL2_RUNTIME_PATH_SUFFIX} ${_SDL2_LIBRARY_PATH_SUFFIX})
find_file(SDL2_DLL_DEBUG
NAMES SDL2d.dll # not sure?
PATH_SUFFIXES bin ${_SDL2_RUNTIME_PATH_SUFFIX} ${_SDL2_LIBRARY_PATH_SUFFIX})
endif()
# (Static) macOS / iOS dependencies. On macOS these were mainly needed when
# building SDL statically using its CMake project, on iOS always.
if(CORRADE_TARGET_APPLE AND (SDL2_LIBRARY_DEBUG MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$" OR SDL2_LIBRARY_RELEASE MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$"))
set(_SDL2_FRAMEWORKS
iconv # should be in the system, needed by iOS as well now
AudioToolbox
AVFoundation
CoreHaptics # needed since 2.0.18(?) on iOS and macOS
Foundation
Metal # needed since 2.0.8 on iOS, since 2.0.14 on macOS
GameController) # needed since 2.0.18(?) on macOS as well
if(CORRADE_TARGET_IOS)
list(APPEND _SDL2_FRAMEWORKS
CoreBluetooth # needed since 2.0.10
CoreGraphics
CoreMotion
Foundation
QuartzCore
UIKit)
else()
list(APPEND _SDL2_FRAMEWORKS
Carbon
Cocoa
CoreAudio
CoreVideo
ForceFeedback
IOKit)
endif()
set(_SDL2_FRAMEWORK_LIBRARIES )
foreach(framework ${_SDL2_FRAMEWORKS})
find_library(_SDL2_${framework}_LIBRARY ${framework})
mark_as_advanced(_SDL2_${framework}_LIBRARY)
list(APPEND _SDL2_FRAMEWORK_LIBRARIES ${_SDL2_${framework}_LIBRARY})
list(APPEND _SDL2_FRAMEWORK_LIBRARY_NAMES _SDL2_${framework}_LIBRARY)
endforeach()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("SDL2" DEFAULT_MSG
${SDL2_LIBRARY_NEEDED}
${_SDL2_FRAMEWORK_LIBRARY_NAMES}
SDL2_INCLUDE_DIR)
if(NOT TARGET SDL2::SDL2)
if(SDL2_LIBRARY_NEEDED)
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
# Work around BUGGY framework support on macOS
# https://cmake.org/Bug/view.php?id=14105
if(CORRADE_TARGET_APPLE AND SDL2_LIBRARY_RELEASE MATCHES "\\.framework$")
set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE}/SDL2)
else()
if(SDL2_LIBRARY_RELEASE)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE})
endif()
if(SDL2_LIBRARY_DEBUG)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_DEBUG ${SDL2_LIBRARY_DEBUG})
endif()
endif()
# Link additional `dl` and `pthread` libraries required by a static
# build of SDL on Unixy platforms (except Apple, where it is most
# probably some frameworks instead)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (SDL2_LIBRARY_DEBUG MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$" OR SDL2_LIBRARY_RELEASE MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$"))
find_package(Threads REQUIRED)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY
INTERFACE_LINK_LIBRARIES Threads::Threads ${CMAKE_DL_LIBS})
endif()
# Link frameworks on macOS / iOS if we have a static SDL
if(CORRADE_TARGET_APPLE AND (SDL2_LIBRARY_DEBUG MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$" OR SDL2_LIBRARY_RELEASE MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$"))
set_property(TARGET SDL2::SDL2 APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${_SDL2_FRAMEWORK_LIBRARIES})
endif()
# Windows dependencies for a static library. Unfortunately there's no
# easy way to figure out if a *.lib is static or dynamic, so we're
# adding only if a DLL is not found.
if(CORRADE_TARGET_WINDOWS AND NOT CORRADE_TARGET_WINDOWS_RT AND NOT SDL2_DLL_RELEASE AND NOT SDL2_DLL_DEBUG)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY INTERFACE_LINK_LIBRARIES
# https://github.com/SDL-mirror/SDL/blob/release-2.0.10/CMakeLists.txt#L1338
user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32
# https://github.com/SDL-mirror/SDL/blob/release-2.0.10/CMakeLists.txt#L1384
dinput8)
# https://github.com/SDL-mirror/SDL/blob/release-2.0.10/CMakeLists.txt#L1422
# additionally has dxerr for MSVC if DirectX SDK is not used, but
# according to https://walbourn.github.io/wheres-dxerr-lib/ this
# thing is long deprecated.
if(MINGW)
set_property(TARGET SDL2::SDL2 APPEND PROPERTY INTERFACE_LINK_LIBRARIES
# https://github.com/SDL-mirror/SDL/blob/release-2.0.10/CMakeLists.txt#L1386
dxerr8
# https://github.com/SDL-mirror/SDL/blob/release-2.0.10/CMakeLists.txt#L1388
mingw32)
endif()
endif()
else()
add_library(SDL2::SDL2 INTERFACE IMPORTED)
endif()
set_property(TARGET SDL2::SDL2 PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR})
endif()
mark_as_advanced(SDL2_INCLUDE_DIR)
Loading…
Cancel
Save