Skip to content

Commit

Permalink
Merge pull request #8 from atsb/sdl3
Browse files Browse the repository at this point in the history
Initial SDL3 support
  • Loading branch information
atsb committed Aug 7, 2024
2 parents 3ecf770 + 25ecbc3 commit ceed5de
Show file tree
Hide file tree
Showing 11 changed files with 1,945 additions and 172 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,34 @@ Module.symvers
Mkfile.old
dkms.conf
.DS_Store
*.bin
*.txt
FindSDL2.cmake
*.recipe
*.tlog
*.list
*.aps
*.log
*.filters
*.depend
*.stamp
*.yaml
*.check_cache
*.rule
*.vcxproj
*.res
*.user
*.db-wal
*.db-shm
*.db
*.ipch
*.json
*.opendb
src/win32/.vs/avp/v17/.suo
*.vsidx
src/win32/CMakeFiles/3.29.3/CMakeCCompiler.cmake
src/win32/CMakeFiles/3.29.3/CMakeCXXCompiler.cmake
src/win32/CMakeFiles/3.29.3/CMakeRCCompiler.cmake
src/win32/CMakeFiles/3.29.3/CMakeSystem.cmake
src/win32/cmake_install.cmake
*.sln
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ PROJECT(avp)

# required dependencies
INCLUDE(FindOpenGLES2.cmake)
INCLUDE(FindSDL2.cmake)
INCLUDE(FindSDL3.cmake)
INCLUDE(FindOpenGL)
INCLUDE(FindOpenAL)

IF(NOT SDL2_FOUND)
MESSAGE(FATAL_ERROR "SDL 2.0 was requested but CMake couldn't find it.")
ENDIF(NOT SDL2_FOUND)
MESSAGE(WARNING "SDL 2.0 support is EXPERIMENTAL and INCOMPLETE.")
IF(NOT SDL3_FOUND)
MESSAGE(FATAL_ERROR "SDL 3.0 was requested but CMake couldn't find it.")
ENDIF(NOT SDL3_FOUND)
MESSAGE(WARNING "SDL 3.0 support is STABLE.")

# Use Desktop OpenGL if it is available, else try OpenGL ES.
IF(NOT OPENGL_TYPE)
Expand Down Expand Up @@ -306,7 +306,7 @@ INCLUDE_DIRECTORIES(src/include)
ADD_EXECUTABLE(avp ${source})

# required dependencies
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${SDL3_INCLUDE_DIR})

IF(OPENGL_TYPE STREQUAL "OPENGL")
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
Expand All @@ -320,7 +320,7 @@ ENDIF(OPENGL_TYPE STREQUAL "OPENGLES2")

INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})

TARGET_LINK_LIBRARIES(avp ${SDL2_LIBRARY})
TARGET_LINK_LIBRARIES(avp ${SDL3_LIBRARY})

IF(OPENGL_TYPE STREQUAL "OPENGL")
TARGET_LINK_LIBRARIES(avp ${OPENGL_gl_LIBRARY})
Expand Down
110 changes: 44 additions & 66 deletions FindSDL2.cmake → FindSDL3.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# Locate SDL2 library
# Locate SDL3 library
# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
# SDL2_INCLUDE_DIR, where to find SDL.h
# SDL3_LIBRARY, the name of the library to link against
# SDL3_FOUND, if false, do not try to link to SDL3
# SDL3_INCLUDE, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2main will be linked in because
# SDL3_BUILDING_LIBRARY
# If this is defined, then no SDL3main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the the proper link flags
# as part of the returned SDL2_LIBRARY variable.
# as part of the returned SDL3_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDL2main which
# OS X framework based version. (Other versions link to -lSDL3main which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
# Additional Note: If you see an empty SDL3_LIBRARY in your configuration
# and no SDL3_LIBRARY, it means CMake did not find your SDL3 library
# (SDL3.dll, libSDL3.so, SDL3.framework, etc).
# Set SDL3_LIBRARY to point to your SDL3 library, and configure again.
# Similarly, if you see an empty SDL3MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL3_LIBRARY
# variable, but when these values are unset, SDL3_LIBRARY does not get created.
#
#
# $SDL2DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL2DIR
# used in building SDL2.
# $SDL3DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL3DIR
# used in building SDL3.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
Expand All @@ -38,19 +38,19 @@
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for SDL3main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_LIBRARY to override this selection or set the CMake environment
# SDL3_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# Note that the header path has changed from SDL3/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
# is #include "SDL.h", not <SDL3/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL3/ (see FreeBSD).

#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
Expand All @@ -65,7 +65,7 @@
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

SET(SDL2_SEARCH_PATHS
SET(SDL3_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
Expand All @@ -76,43 +76,27 @@ SET(SDL2_SEARCH_PATHS
/opt
)

FIND_PATH(SDL2_INCLUDE_DIR
FIND_PATH(SDL3_INCLUDE
NAMES
SDL_gesture.h # A SDL2-only header
SDL_gesture.h # A SDL3-only header
HINTS
$ENV{SDL2DIR}
$ENV{SDL3DIR}
PATH_SUFFIXES
include/SDL2
include/SDL3
include
PATHS
${SDL2_SEARCH_PATHS}
${SDL3_SEARCH_PATHS}
)

FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2
FIND_LIBRARY(SDL3_LIBRARY
NAMES SDL3
HINTS
$ENV{SDL2DIR}
$ENV{SDL3DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
PATHS ${SDL3_SEARCH_PATHS}
)

IF(NOT SDL2_BUILDING_LIBRARY)
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDL2main for compatibility even though they don't
# necessarily need it.
FIND_LIBRARY(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)

# SDL2 may require threads on your system.
# SDL3 may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
Expand All @@ -121,48 +105,42 @@ IF(NOT APPLE)
ENDIF(NOT APPLE)

# MinGW needs an additional library, mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
# It's total link flags should look like -lmingw32 -lSDL3main -lSDL3 -lmwindows
# (Actually on second look, I think it only needs one of the m* libraries.)
IF(MINGW)
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)

IF(SDL2_LIBRARY_TEMP)
# For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL2MAIN_LIBRARY)
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(SDL2MAIN_LIBRARY)
ENDIF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL3_LIBRARY)

# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# For OS X, SDL3 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
# I think it has something to do with the CACHE STRING.
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
IF(APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
SET(SDL3_LIBRARY ${SDL3_LIBRARY} "-framework Cocoa")
ENDIF(APPLE)

# For threads, as mentioned Apple doesn't need this.
# In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
IF(NOT APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
SET(SDL3_LIBRARY ${SDL3_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
ENDIF(NOT APPLE)

# For MinGW library
IF(MINGW)
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
SET(SDL3_LIBRARY ${MINGW32_LIBRARY} ${SDL3_LIBRARY})
ENDIF(MINGW)

# Set the final string here so the GUI reflects the final state.
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
SET(SDL3_LIBRARY ${SDL3_LIBRARY} CACHE STRING "Where the SDL3 Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(SDL2_LIBRARY_TEMP)
SET(SDL3_LIBRARY "${SDL3_LIBRARY}" CACHE INTERNAL "")
ENDIF(SDL3_LIBRARY)

INCLUDE(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL3 REQUIRED_VARS SDL3_LIBRARY SDL3_INCLUDE)
2 changes: 1 addition & 1 deletion src/cdplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>

#include "SDL.h"
#include <SDL3/SDL.h>

#include "fixer.h"
#include "win95/cd_player.h"
Expand Down
7 changes: 3 additions & 4 deletions src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <assert.h>

#include <SDL3/SDL_filesystem.h>
#include <SDL3/SDL.h>

#ifndef _WIN32
#include <unistd.h>
#include <dirent.h>
Expand All @@ -16,10 +19,6 @@
#define W_OK 0
#endif

#if defined __APPLE__
#include <SDL2/SDL.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
Loading

0 comments on commit ceed5de

Please sign in to comment.