add possibility to compile with SDL2 automatically
authorkoda
Mon, 28 Oct 2013 16:53:20 +0100
changeset 9650 1c7c87ce37fd
parent 9649 2d30721b1a11
child 9651 c0a389ccb0c1
add possibility to compile with SDL2 automatically
QTfrontend/CMakeLists.txt
QTfrontend/ui/widget/about.cpp
cmake_modules/FindSDL1or2.cmake
hedgewars/CMakeLists.txt
misc/libphyslayer/CMakeLists.txt
--- a/QTfrontend/CMakeLists.txt	Mon Oct 28 14:16:04 2013 +0100
+++ b/QTfrontend/CMakeLists.txt	Mon Oct 28 16:53:20 2013 +0100
@@ -19,7 +19,7 @@
     message(FATAL_ERROR "This version of QT is known *not* to work, please update or use a lower version")
 endif()
 
-find_package(SDL REQUIRED)       #video in SDLInteraction
+find_package(SDL1or2)            #video in SDLInteraction
 find_package(SDL_mixer REQUIRED) #audio in SDLInteraction
 
 if(${FFMPEG_FOUND})
--- a/QTfrontend/ui/widget/about.cpp	Mon Oct 28 14:16:04 2013 +0100
+++ b/QTfrontend/ui/widget/about.cpp	Mon Oct 28 16:53:20 2013 +0100
@@ -28,8 +28,13 @@
 #include <QDebug>
 #include "hwconsts.h"
 #include "SDLInteraction.h"
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#include "SDL2/SDL.h"
+#include "SDL2/SDL_version.h"
+#else
 #include "SDL.h"
 #include "SDL_version.h"
+#endif
 #include "physfs.h"
 
 #ifdef VIDEOREC
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/FindSDL1or2.cmake	Mon Oct 28 16:53:20 2013 +0100
@@ -0,0 +1,24 @@
+find_package(SDL QUIET)
+
+if(NOT SDL_FOUND)
+    find_package(SDL2 REQUIRED)
+    set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIR})
+    set(SDL_LIBRARY ${SDL2_LIBRARY})
+endif()
+
+if(NOT SDL_VERSION)
+    #find which version of SDL we have
+    find_file(sdlversion_h SDL_version.h ${SDL_INCLUDE_DIR})
+    if(sdlversion_h)
+        file(STRINGS ${sdlversion_h} sdl_majorversion_tmp REGEX "SDL_MAJOR_VERSION[\t' ']+[0-9]+")
+        file(STRINGS ${sdlversion_h} sdl_minorversion_tmp REGEX "SDL_MINOR_VERSION[\t' ']+[0-9]+")
+        file(STRINGS ${sdlversion_h} sdl_patchversion_tmp REGEX "SDL_PATCHLEVEL[\t' ']+[0-9]+")
+        string(REGEX MATCH "([0-9]+)" sdl_majorversion "${sdl_majorversion_tmp}")
+        string(REGEX MATCH "([0-9]+)" sdl_minorversion "${sdl_minorversion_tmp}")
+        string(REGEX MATCH "([0-9]+)" sdl_patchversion "${sdl_patchversion_tmp}")
+        set(SDL_VERSION "${sdl_majorversion}.${sdl_minorversion}.${sdl_patchversion}")
+    endif()
+endif()
+
+mark_as_advanced(sdlversion_h sdl_majorversion sdl_minorversion sdl_patchversion)
+
--- a/hedgewars/CMakeLists.txt	Mon Oct 28 14:16:04 2013 +0100
+++ b/hedgewars/CMakeLists.txt	Mon Oct 28 16:53:20 2013 +0100
@@ -1,4 +1,4 @@
-find_package(SDL)
+find_package(SDL1or2)
 find_package(SDL_image)
 find_package(SDL_net)
 find_package(SDL_ttf)
@@ -158,6 +158,10 @@
     add_definitions(-dSDL_IMAGE_NEWER)
 endif(HAVE_IMGINIT)
 
+if(NOT (SDL_VERSION VERSION_LESS 2.0))
+    add_definitions(-dSDL2)
+endif()
+
 #needs to be last
 add_definitions(-dDEBUGFILE)
 
--- a/misc/libphyslayer/CMakeLists.txt	Mon Oct 28 14:16:04 2013 +0100
+++ b/misc/libphyslayer/CMakeLists.txt	Mon Oct 28 16:53:20 2013 +0100
@@ -1,5 +1,5 @@
 
-find_package(SDL REQUIRED)
+find_package(SDL1or2)
 include_directories(${PHYSFS_INCLUDE_DIR})
 include_directories(${SDL_INCLUDE_DIR})
 include_directories(${LUA_INCLUDE_DIR})