diff --git a/doc/changelog.dox b/doc/changelog.dox index 7998a87b6..4b2553335 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -547,6 +547,9 @@ See also: - `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 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 @ref Platform::Sdl2Application now copy the GLFW / SDL2 DLLs to `CMAKE_RUNTIME_OUTPUT_DIRECTORY` (if set) as a post-build step. The DLL diff --git a/modules/FindSDL2.cmake b/modules/FindSDL2.cmake index 4086a0025..1a386fbcb 100644 --- a/modules/FindSDL2.cmake +++ b/modules/FindSDL2.cmake @@ -13,7 +13,8 @@ # 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 +# SDL2_INCLUDE_DIR - Root include dir. By adding it to PATH, +# will work on all sane systems and on Emscripten. # # @@ -45,9 +46,12 @@ # 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) + set(_SDL2_INCLUDE_PREFIX SDL) 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, + # / works so SDL2/SDL.h should work too. + set(_SDL2_INCLUDE_PREFIX SDL2) if(WIN32) # Precompiled libraries for MSVC are in x86/x64 subdirectories if(MSVC) @@ -65,11 +69,11 @@ else() 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) + set(_SDL2_INCLUDE_PATH_SUFFIX x86_64-w64-mingw32/include) 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) + set(_SDL2_INCLUDE_PATH_SUFFIX i686-w64-mingw32/include) endif() else() message(FATAL_ERROR "Unsupported compiler") @@ -97,15 +101,15 @@ 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. + # 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 # 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}) + NAMES ${_SDL2_INCLUDE_PREFIX}/SDL_scancode.h + PATH_SUFFIXES ${_SDL2_INCLUDE_PATH_SUFFIX}) # DLL on Windows if(CORRADE_TARGET_WINDOWS) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 1a0dd4118..0c6624a99 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -26,10 +26,11 @@ #include "Sdl2Application.h" #include -#include #ifndef CORRADE_TARGET_EMSCRIPTEN #include +#include #else +#include #include #include #endif diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index f630508ce..f17dcf6ee 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -47,10 +47,18 @@ #define SDL_MAIN_HANDLED #endif /* SDL.h includes the world, adding 50k LOC. We don't want that either. */ -#include -#include -#include -#include +#ifndef CORRADE_TARGET_EMSCRIPTEN +#include +#include +#include +#include +#else +/* Emscripten has a SDL1/2 hybrid, with includes in SDL/ instead of SDL2/ */ +#include +#include +#include +#include +#endif #ifdef CORRADE_TARGET_WINDOWS_RT #include /* For SDL_WinRTRunApp */ diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index ec7eb6f39..0e9ce6b32 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -27,7 +27,11 @@ #include "Magnum/Platform/Sdl2Application.h" -#include +#ifndef CORRADE_TARGET_EMSCRIPTEN +#include +#else +#include +#endif namespace Magnum { namespace Platform { namespace Test { namespace {