Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SDL2_INCLUDE_DIR point to the root #381

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions modules/FindSDL2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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,
# <SDL2/SDL.h> will work on all sane systems and <SDL/SDL.h> on Emscripten.
#

#
Expand Down Expand Up @@ -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,
# <framweworkName>/<headerName> 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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Magnum/Platform/Sdl2Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#include "Sdl2Application.h"

#include <cstring>
#include <SDL.h>
#ifndef CORRADE_TARGET_EMSCRIPTEN
#include <tuple>
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h>
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#endif
Expand Down
16 changes: 12 additions & 4 deletions src/Magnum/Platform/Sdl2Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@
#define SDL_MAIN_HANDLED
#endif
/* SDL.h includes the world, adding 50k LOC. We don't want that either. */
#include <SDL_keycode.h>
#include <SDL_mouse.h>
#include <SDL_video.h>
#include <SDL_scancode.h>
#ifndef CORRADE_TARGET_EMSCRIPTEN
#include <SDL2/SDL_keycode.h>
#include <SDL2/SDL_mouse.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
#include <SDL_main.h> /* For SDL_WinRTRunApp */
Expand Down
6 changes: 5 additions & 1 deletion src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

#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 {

Expand Down