#.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, 2024 # Vladimír Vondruš # Copyright © 2018 Jonathan Hale # # 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. # # SDL2 installs CMake package config files which handle dependencies in case # it's 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 unprefixed SDL2 # targets already exist, it means we're using it through a CMake subproject -- # don't attempt to find the package in that case. # # Don't do this on Emscripten -- there the config file is broken if # EMSCRIPTEN_SYSROOT isn't defined, adding /include/SDL2 as an include path. # Plus, it wants to pass -sUSE_SDL=2, which we definitely *do not* want here. if(NOT CORRADE_TARGET_EMSCRIPTEN AND NOT TARGET SDL2 AND NOT TARGET SDL2-static) find_package(SDL2 CONFIG QUIET) endif() # If either a SDL2 config file was found or we have a CMake subproject, use the # targets directly. I'd prefer the static variant if there's a choice, 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::SDL2 OR TARGET SDL2::SDL2-static OR TARGET SDL2 OR TARGET SDL2-static) # 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?! if(TARGET SDL2::SDL2) set(_SDL2_TARGET SDL2::SDL2) set(_SDL2_DYNAMIC ON) elseif(TARGET SDL2::SDL2-static) set(_SDL2_TARGET SDL2::SDL2-static) elseif(TARGET SDL2) set(_SDL2_TARGET SDL2) set(_SDL2_DYNAMIC ON) elseif(TARGET SDL2-static) set(_SDL2_TARGET SDL2-static) endif() # 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_TARGET}) endif() # Just to make FPHSA print some meaningful location, nothing else. Not # using the INTERFACE_INCLUDE_DIRECTORIES for the CMake subproject case as # that contains $