Browse Source

modules: Make SDL2_INCLUDE_DIR point to the root.

So people using custom buildsystems don't need to add SDL2/ into the
include path.
findsdl-include-root
Vladimír Vondruš 7 years ago
parent
commit
cc738fe1c3
  1. 3
      doc/changelog.dox
  2. 20
      modules/FindSDL2.cmake
  3. 3
      src/Magnum/Platform/Sdl2Application.cpp
  4. 16
      src/Magnum/Platform/Sdl2Application.h
  5. 6
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

3
doc/changelog.dox

@ -547,6 +547,9 @@ See also:
- `FindSDL2.cmake` was updated to work with MinGW version 2.0.5 and newer, - `FindSDL2.cmake` was updated to work with MinGW version 2.0.5 and newer,
since these dropped the old directory hierarchy. Older versions have both since these dropped the old directory hierarchy. Older versions have both
the original and the new hierarchy, so it should work with these as well. the original and the new hierarchy, so it should work with these as well.
- `FindSDL2.cmake` now points `SDL2_INCLUDE_DIR` to the root and the
@ref Platform::Sdl2Application was updated to follow that; people using
custom buildsystems don't need to add `SDL2/` to their include path anymore
- When using Magnum as a CMake subproject, @ref Platform::GlfwApplication and - When using Magnum as a CMake subproject, @ref Platform::GlfwApplication and
@ref Platform::Sdl2Application now copy the GLFW / SDL2 DLLs to @ref Platform::Sdl2Application now copy the GLFW / SDL2 DLLs to
`CMAKE_RUNTIME_OUTPUT_DIRECTORY` (if set) as a post-build step. The DLL `CMAKE_RUNTIME_OUTPUT_DIRECTORY` (if set) as a post-build step. The DLL

20
modules/FindSDL2.cmake

@ -13,7 +13,8 @@
# SDL2_LIBRARY_RELEASE - SDL2 release library, if found # SDL2_LIBRARY_RELEASE - SDL2 release library, if found
# SDL2_DLL_DEBUG - SDL2 debug DLL on Windows, if found # SDL2_DLL_DEBUG - SDL2 debug DLL on Windows, if found
# SDL2_DLL_RELEASE - SDL2 release DLL on Windows, if found # SDL2_DLL_RELEASE - SDL2 release DLL on Windows, if found
# SDL2_INCLUDE_DIR - Root include dir # SDL2_INCLUDE_DIR - Root include dir. By adding it to PATH,
# <SDL2/SDL.h> will work on all sane systems and <SDL/SDL.h> on Emscripten.
# #
# #
@ -45,9 +46,12 @@
# In Emscripten SDL is linked automatically, thus no need to find the library. # In Emscripten SDL is linked automatically, thus no need to find the library.
# Also the includes are in SDL subdirectory, not SDL2. # Also the includes are in SDL subdirectory, not SDL2.
if(CORRADE_TARGET_EMSCRIPTEN) if(CORRADE_TARGET_EMSCRIPTEN)
set(_SDL2_PATH_SUFFIXES SDL) set(_SDL2_INCLUDE_PREFIX SDL)
else() else()
set(_SDL2_PATH_SUFFIXES SDL2) # macOS *.dmg distribution puts everything directly into the root inside
# the framework, but according to https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/IncludingFrameworks.html,
# <framweworkName>/<headerName> works so SDL2/SDL.h should work too.
set(_SDL2_INCLUDE_PREFIX SDL2)
if(WIN32) if(WIN32)
# Precompiled libraries for MSVC are in x86/x64 subdirectories # Precompiled libraries for MSVC are in x86/x64 subdirectories
if(MSVC) if(MSVC)
@ -65,11 +69,11 @@ else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_SDL2_LIBRARY_PATH_SUFFIX x86_64-w64-mingw32/lib) set(_SDL2_LIBRARY_PATH_SUFFIX x86_64-w64-mingw32/lib)
set(_SDL2_RUNTIME_PATH_SUFFIX x86_64-w64-mingw32/bin) set(_SDL2_RUNTIME_PATH_SUFFIX x86_64-w64-mingw32/bin)
list(APPEND _SDL2_PATH_SUFFIXES x86_64-w64-mingw32/include/SDL2) set(_SDL2_INCLUDE_PATH_SUFFIX x86_64-w64-mingw32/include)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(_SDL2_LIBRARY_PATH_SUFFIX i686-w64-mingw32/lib) set(_SDL2_LIBRARY_PATH_SUFFIX i686-w64-mingw32/lib)
set(_SDL2_RUNTIME_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) set(_SDL2_INCLUDE_PATH_SUFFIX i686-w64-mingw32/include)
endif() endif()
else() else()
message(FATAL_ERROR "Unsupported compiler") message(FATAL_ERROR "Unsupported compiler")
@ -97,15 +101,15 @@ select_library_configurations(SDL2)
# Include dir # Include dir
find_path(SDL2_INCLUDE_DIR find_path(SDL2_INCLUDE_DIR
# We must search file which is present only in SDL2 and not in SDL1. # We have to look for a file which is present only in SDL2 and not in SDL1.
# Apparently when both SDL.h and SDL_scancode.h are specified, CMake is # 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. # 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 # 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 # 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. # find SDL.framework/Headers/SDL.h if SDL1 is installed, which is wrong.
NAMES SDL_scancode.h NAMES ${_SDL2_INCLUDE_PREFIX}/SDL_scancode.h
PATH_SUFFIXES ${_SDL2_PATH_SUFFIXES}) PATH_SUFFIXES ${_SDL2_INCLUDE_PATH_SUFFIX})
# DLL on Windows # DLL on Windows
if(CORRADE_TARGET_WINDOWS) if(CORRADE_TARGET_WINDOWS)

3
src/Magnum/Platform/Sdl2Application.cpp

@ -26,10 +26,11 @@
#include "Sdl2Application.h" #include "Sdl2Application.h"
#include <cstring> #include <cstring>
#include <SDL.h>
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
#include <tuple> #include <tuple>
#include <SDL2/SDL.h>
#else #else
#include <SDL/SDL.h>
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#include <emscripten/html5.h> #include <emscripten/html5.h>
#endif #endif

16
src/Magnum/Platform/Sdl2Application.h

@ -47,10 +47,18 @@
#define SDL_MAIN_HANDLED #define SDL_MAIN_HANDLED
#endif #endif
/* SDL.h includes the world, adding 50k LOC. We don't want that either. */ /* SDL.h includes the world, adding 50k LOC. We don't want that either. */
#include <SDL_keycode.h> #ifndef CORRADE_TARGET_EMSCRIPTEN
#include <SDL_mouse.h> #include <SDL2/SDL_keycode.h>
#include <SDL_video.h> #include <SDL2/SDL_mouse.h>
#include <SDL_scancode.h> #include <SDL2/SDL_video.h>
#include <SDL2/SDL_scancode.h>
#else
/* Emscripten has a SDL1/2 hybrid, with includes in SDL/ instead of SDL2/ */
#include <SDL/SDL_keycode.h>
#include <SDL/SDL_mouse.h>
#include <SDL/SDL_video.h>
#include <SDL/SDL_scancode.h>
#endif
#ifdef CORRADE_TARGET_WINDOWS_RT #ifdef CORRADE_TARGET_WINDOWS_RT
#include <SDL_main.h> /* For SDL_WinRTRunApp */ #include <SDL_main.h> /* For SDL_WinRTRunApp */

6
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -27,7 +27,11 @@
#include "Magnum/Platform/Sdl2Application.h" #include "Magnum/Platform/Sdl2Application.h"
#include <SDL_events.h> #ifndef CORRADE_TARGET_EMSCRIPTEN
#include <SDL2/SDL_events.h>
#else
#include <SDL/SDL_events.h>
#endif
namespace Magnum { namespace Platform { namespace Test { namespace { namespace Magnum { namespace Platform { namespace Test { namespace {

Loading…
Cancel
Save