From bbcd6bfe4e65fc9b106e38b896ce08c55ec184d3 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 25 Nov 2022 15:26:50 -0500
Subject: [PATCH] Added some support files and CMake project.
---
CMakeLists.txt | 376 +++++++++++++++++++++++++++
cmake/modules/FindSDL3.cmake | 392 +++++++++++++++++++++++++++++
sdl2_compat.pc.in | 14 ++
src/SDLmain/dummy/SDL_dummy_main.c | 25 ++
update_version.sh | 30 +++
5 files changed, 837 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 cmake/modules/FindSDL3.cmake
create mode 100644 sdl2_compat.pc.in
create mode 100644 src/SDLmain/dummy/SDL_dummy_main.c
create mode 100755 update_version.sh
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..591d2f1
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,376 @@
+# NOTE: If you installed SDL2 at an unusual place and FindSDL2 fails,
+# you can define SDL2_INCLUDE_DIR on the cmdline. For example:
+# cmake -DSDL2_INCLUDE_DIR=/opt/SDL2/include/SDL2 [other stuff]
+
+cmake_minimum_required(VERSION 3.0.0)
+project(sdl2_compat
+ VERSION 2.90.0
+ LANGUAGES C)
+
+option(SDL2TESTS "Enable to build SDL2 test programs" ON)
+option(SDL2DEVEL "Enable installing SDL2 development headers" ON)
+option(STATICDEVEL "Enable installing static link library" OFF)
+
+if(STATICDEVEL AND NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
+ message(FATAL_ERROR "Static builds are only supported on Linux.")
+endif()
+
+list(APPEND CMAKE_MODULE_PATH
+ "${CMAKE_CURRENT_LIST_DIR}/cmake/modules"
+)
+
+include(CheckCSourceCompiles)
+include(CheckIncludeFile)
+include(CheckCCompilerFlag)
+include(GNUInstallDirs)
+
+set(CMAKE_SKIP_RPATH TRUE)
+
+if(APPLE)
+# !!! FIXME: assuming we don't need this; if so, remove this.
+ #set(OSX_SRCS "src/sdl2_compat_objc.m")
+ #set_source_files_properties(${OSX_SRCS} PROPERTIES LANGUAGE C)
+
+# # !!! FIXME: what does SDL2 expect here?
+# # compatibility version set to match SDL-1.2 autotools build
+# # Xcode project file uses 1.0.0, but it's more compatible to use the
+# # higher version.
+# set(DYLIB_COMPAT_VERSION 12.0.0 CACHE STRING "library compatibility version")
+# set(DYLIB_CURRENT_VERSION 12.61.0 CACHE STRING "library current version")
+ include_directories("/opt/X11/include") # hack.
+ if(CMAKE_VERSION VERSION_LESS 3.9)
+ else()
+ cmake_policy(SET CMP0068 NEW) # on macOS, don't let RPATH affect install_name.
+ endif()
+endif()
+
+if(WIN32)
+ set(WIN32_SRCS "src/version.rc")
+endif()
+
+set(SDL2COMPAT_SRCS
+ src/sdl2_compat.c
+ ${OSX_SRCS}
+ ${WIN32_SRCS}
+)
+add_library(SDL SHARED ${SDL2COMPAT_SRCS})
+
+find_package(SDL3)
+if(NOT SDL3_INCLUDE_DIRS)
+ message(FATAL_ERROR "Could not find SDL3 headers")
+endif()
+target_include_directories(SDL PRIVATE ${SDL3_INCLUDE_DIRS})
+
+set(EXTRA_CFLAGS )
+if (CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
+ set(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall")
+ check_c_compiler_flag(-Wdeclaration-after-statement HAVE_WDECLARATION_AFTER_STATEMENT)
+ if(HAVE_WDECLARATION_AFTER_STATEMENT)
+ set(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wdeclaration-after-statement")
+ endif()
+ check_c_compiler_flag(-Werror=declaration-after-statement HAVE_WERROR_DECLARATION_AFTER_STATEMENT)
+ if(HAVE_WERROR_DECLARATION_AFTER_STATEMENT)
+ set(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror=declaration-after-statement")
+ endif()
+endif()
+
+# !!! FIXME: is this still necessary with SDL2?
+# just in case:
+check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
+if(NOT HAVE_IMMINTRIN_H)
+ set(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DSDL_DISABLE_IMMINTRIN_H")
+endif()
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
+
+if(UNIX AND NOT APPLE)
+ set_target_properties(SDL PROPERTIES COMPILE_DEFINITIONS "_REENTRANT")
+ target_link_libraries(SDL PRIVATE ${CMAKE_DL_LIBS})
+endif()
+if(APPLE)
+ # !!! FIXME: check OUTPUT_NAME value, and do we need AppKit now? I assume that was for SDL_main code in 1.2.
+ set_target_properties(SDL PROPERTIES COMPILE_DEFINITIONS "_THREAD_SAFE")
+ set_target_properties(SDL PROPERTIES LINK_FLAGS
+ "-Wl,-compatibility_version,${DYLIB_COMPAT_VERSION} -Wl,-current_version,${DYLIB_CURRENT_VERSION}")
+ #target_link_libraries(SDL PRIVATE "-framework AppKit")
+ set_target_properties(SDL PROPERTIES
+ OUTPUT_NAME "SDL2-2.0.0"
+ )
+elseif(UNIX AND NOT ANDROID)
+ # !!! FIXME: check OUTPUT_NAME value
+ set_target_properties(SDL PROPERTIES
+ VERSION "${PROJECT_VERSION}"
+ SOVERSION "0"
+ OUTPUT_NAME "SDL2-2.0")
+elseif(WIN32)
+ # avoid DLL having 'lib' prefix with MinGW
+ set(CMAKE_SHARED_LIBRARY_PREFIX "")
+ set_target_properties(SDL PROPERTIES COMPILE_DEFINITIONS "DLL_EXPORT")
+ set_target_properties(SDL PROPERTIES
+ VERSION "${PROJECT_VERSION}"
+ SOVERSION "0"
+ OUTPUT_NAME "SDL2")
+elseif(OS2)
+ set_target_properties(SDL PROPERTIES COMPILE_DEFINITIONS "BUILD_SDL") # for DECLSPEC
+ set_target_properties(SDL PROPERTIES
+ VERSION "${PROJECT_VERSION}"
+ SOVERSION "0"
+ OUTPUT_NAME "SDL2")
+else()
+ set_target_properties(SDL PROPERTIES
+ VERSION "${PROJECT_VERSION}"
+ SOVERSION "0"
+ OUTPUT_NAME "SDL2")
+endif()
+
+if(MINGW)
+ set_target_properties(SDL PROPERTIES LINK_FLAGS "-nostdlib")
+ target_link_libraries(SDL PRIVATE "-static-libgcc -lgcc") # libgcc is needed for 32 bit (x86) builds
+endif()
+if(MSVC)
+ # Don't try to link with the default set of libraries.
+ set(MSVC_FLAGS "/GS-")
+ check_c_source_compiles("int main(void) {
+#ifndef _M_IX86
+#error not x86
+#endif
+return 0; }" IS_X86)
+ if(IS_X86) # don't emit SSE2 in x86 builds
+ set(MSVC_FLAGS "${MSVC_FLAGS} /arch:SSE")
+ endif()
+ set_target_properties(SDL PROPERTIES COMPILE_FLAGS ${MSVC_FLAGS})
+ set_target_properties(SDL PROPERTIES LINK_FLAGS "/NODEFAULTLIB")
+ # Make sure /RTC1 is disabled: (from SDL2 CMake)
+ foreach(flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
+ string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
+ endforeach(flag_var)
+endif()
+
+# !!! FIXME: what needs to be done for sdl2-compat? Look into this.
+## SDLmain library...
+#if(APPLE)
+# add_library(SDLmain STATIC src/SDLmain/macosx/SDLMain.m)
+# set_source_files_properties(src/SDLmain/macosx/SDLMain.m PROPERTIES LANGUAGE C)
+#elseif(WIN32)
+# add_library(SDLmain STATIC src/SDLmain/win32/SDL_win32_main.c)
+# set_target_properties(SDLmain PROPERTIES COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE") # !!! FIXME: don't use C runtime? We fixed this in SDL2.
+#else()
+ add_library(SDLmain STATIC src/SDLmain/dummy/SDL_dummy_main.c)
+#endif()
+target_include_directories(SDLmain PRIVATE "include/SDL")
+
+if(SDL2TESTS)
+ if(NOT (WIN32 OR APPLE OR CYGWIN OR HAIKU OR BEOS))
+ find_library(MATH_LIBRARY m)
+ endif()
+
+ find_package(OpenGL COMPONENTS OpenGL)
+ if(OPENGL_FOUND)
+ set(HAVE_OPENGL_DEFINE "HAVE_OPENGL")
+ if(WIN32)
+ set(OPENGL_gl_LIBRARY "opengl32")
+ set(OPENGL_opengl_LIBRARY "opengl32")
+ elseif(APPLE)
+ set(OPENGL_gl_LIBRARY "-Wl,-framework,OpenGL")
+ set(OPENGL_opengl_LIBRARY "-Wl,-framework,OpenGL")
+ endif()
+ endif()
+
+ macro(test_program _NAME _SRCS)
+ add_executable(${_NAME} ${_SRCS})
+ target_include_directories(${_NAME} PRIVATE "include/SDL")
+ if(MINGW)
+ target_link_libraries(${_NAME} mingw32 SDLmain SDL)
+ else()
+ target_link_libraries(${_NAME} SDLmain SDL)
+ endif()
+ # Turn off MSVC's aggressive C runtime warnings for the old test programs.
+ if(MSVC)
+ set_target_properties(${_NAME} PROPERTIES COMPILE_DEFINITIONS "${HAVE_OPENGL_DEFINE};_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE")
+ elseif(APPLE)
+ set_target_properties(${_NAME} PROPERTIES COMPILE_DEFINITIONS "${HAVE_OPENGL_DEFINE};GL_SILENCE_DEPRECATION=1")
+ target_link_libraries(${_NAME} "-Wl,-framework,Cocoa")
+ else()
+ set_target_properties(${_NAME} PROPERTIES COMPILE_DEFINITIONS "${HAVE_OPENGL_DEFINE}")
+ endif()
+ if(MATH_LIBRARY)
+ target_link_libraries(${_NAME} ${MATH_LIBRARY})
+ endif()
+ endmacro()
+
+ test_program(checkkeys "test/checkkeys.c")
+ test_program(checkkeysthreads "test/checkkeysthreads.c")
+ test_program(controllermap "test/controllermap.c")
+ test_program(loopwave "test/loopwave.c")
+ test_program(loopwavequeue "test/loopwavequeue.c")
+ test_program(testatomic "test/testatomic.c")
+ test_program(testaudiocapture "test/testaudiocapture.c")
+ test_program(testaudiohotplug "test/testaudiohotplug.c")
+ test_program(testaudioinfo "test/testaudioinfo.c")
+ test_program(testautomation "test/testautomation.c")
+ test_program(testbounds "test/testbounds.c")
+ test_program(testcustomcursor "test/testcustomcursor.c")
+ test_program(testdisplayinfo "test/testdisplayinfo.c")
+ test_program(testdraw2 "test/testdraw2.c")
+ test_program(testdrawchessboard "test/testdrawchessboard.c")
+ test_program(testdropfile "test/testdropfile.c")
+ test_program(testerror "test/testerror.c")
+ test_program(testevdev "test/testevdev.c")
+ test_program(testfile "test/testfile.c")
+ test_program(testfilesystem "test/testfilesystem.c")
+ test_program(testgamecontroller "test/testgamecontroller.c")
+ test_program(testgeometry "test/testgeometry.c")
+ test_program(testgesture "test/testgesture.c")
+ test_program(testhaptic "test/testhaptic.c")
+ test_program(testhittesting "test/testhittesting.c")
+ test_program(testhotplug "test/testhotplug.c")
+ test_program(testiconv "test/testiconv.c")
+ test_program(testime "test/testime.c")
+ test_program(testintersections "test/testintersections.c")
+ test_program(testjoystick "test/testjoystick.c")
+ test_program(testkeys "test/testkeys.c")
+ test_program(testloadso "test/testloadso.c")
+ test_program(testlocale "test/testlocale.c")
+ test_program(testlock "test/testlock.c")
+ test_program(testmessage "test/testmessage.c")
+ test_program(testmouse "test/testmouse.c")
+ test_program(testmultiaudio "test/testmultiaudio.c")
+ test_program(testnative "test/testnative.c")
+ test_program(testoverlay2 "test/testoverlay2.c")
+ test_program(testplatform "test/testplatform.c")
+ test_program(testpower "test/testpower.c")
+ test_program(testqsort "test/testqsort.c")
+ test_program(testrelative "test/testrelative.c")
+ test_program(testrendercopyex "test/testrendercopyex.c")
+ test_program(testrendertarget "test/testrendertarget.c")
+ test_program(testresample "test/testresample.c")
+ test_program(testrumble "test/testrumble.c")
+ test_program(testscale "test/testscale.c")
+ test_program(testsem "test/testsem.c")
+ test_program(testsensor "test/testsensor.c")
+ test_program(testshape "test/testshape.c")
+ test_program(testsprite2 "test/testsprite2.c")
+ test_program(testspriteminimal "test/testspriteminimal.c")
+ test_program(teststreaming "test/teststreaming.c")
+ test_program(testsurround "test/testsurround.c")
+ test_program(testthread "test/testthread.c")
+ test_program(testtimer "test/testtimer.c")
+ test_program(testurl "test/testurl.c")
+ test_program(testver "test/testver.c")
+ test_program(testviewport "test/testviewport.c")
+ test_program(testvulkan "test/testvulkan.c")
+ test_program(testwm2 "test/testwm2.c")
+ test_program(testyuv "test/testyuv.c")
+ test_program(torturethread "test/torturethread.c")
+ test_program(testgl2 "test/testgl2.c")
+ test_program(testgles "test/testgles.c")
+ test_program(testgles2 "test/testgles2.c")
+ test_program(testgles2_sdf "test/testgles2_sdf.c")
+
+ if(OPENGL_FOUND)
+ if(CMAKE_VERSION VERSION_LESS 3.10 OR NOT OPENGL_opengl_LIBRARY)
+ target_link_libraries(testgl2 ${OPENGL_gl_LIBRARY})
+ else()
+ target_link_libraries(testgl2 ${OPENGL_opengl_LIBRARY})
+ endif()
+ endif()
+
+ foreach(fname
+ "axis.bmp"
+ "button.bmp"
+ "controllermap.bmp"
+ "controllermap_back.bmp"
+ "icon.bmp"
+ "moose.dat"
+ "sample.bmp"
+ "sample.wav"
+ "testgles2_sdf_img_normal.bmp"
+ "testgles2_sdf_img_sdf.bmp"
+ "testyuv.bmp"
+ "unifont-13.0.06.hex"
+ "utf8.txt")
+ file(COPY "${CMAKE_SOURCE_DIR}/test/${fname}" DESTINATION "${CMAKE_BINARY_DIR}")
+ endforeach()
+endif()
+
+install(TARGETS SDL SDLmain
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+
+if(SDL2DEVEL)
+ install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+ if(NOT MSVC)
+ if(WIN32)
+ set(SDL_CFLAGS "")
+ set(SDL_RLD_FLAGS "")
+ set(SDL_LIBS "-lmingw32 -lSDLmain -lSDL -mwindows")
+ set(SDL_STATIC_LIBS "")
+ elseif(APPLE)
+ set(SDL_CFLAGS "-D_THREAD_SAFE")
+ set(SDL_LIBS "-lSDLmain -lSDL -Wl,-framework,Cocoa")
+ set(SDL_STATIC_LIBS "")
+ set(SDL_RLD_FLAGS "") # !!! FIXME: this forces rpath, which we might want?
+ else() # unix
+ set(SDL_CFLAGS "-D_GNU_SOURCE=1 -D_REENTRANT")
+ set(SDL_RLD_FLAGS "") # !!! FIXME: this forces rpath, which we might want?
+ set(SDL_LIBS "-lSDL")
+ set(SDL_STATIC_LIBS "")
+ foreach(lib ${CMAKE_DL_LIBS})
+ set(SDL_STATIC_LIBS "-l${lib}")
+ endforeach()
+ if(NOT STATICDEVEL)
+ set(SDL_STATIC_LIBS "")
+ endif()
+ endif()
+
+ # !!! FIXME: do we _want_ static builds?
+ if(STATICDEVEL)
+ set(ENABLE_STATIC_TRUE "")
+ set(ENABLE_STATIC_FALSE "#")
+ else()
+ set(ENABLE_STATIC_TRUE "#")
+ set(ENABLE_STATIC_FALSE "")
+ endif()
+ set(ENABLE_SHARED_TRUE "")
+ set(ENABLE_SHARED_FALSE "#")
+
+ configure_file(sdl2_compat.pc.in sdl2_compat.pc @ONLY)
+ install(FILES ${CMAKE_BINARY_DIR}/sdl2_compat.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
+ )
+
+ configure_file("${CMAKE_SOURCE_DIR}/sdl2-config.in" "${CMAKE_BINARY_DIR}/sdl2-config" @ONLY)
+ install(PROGRAMS "${CMAKE_BINARY_DIR}/sdl2-config" DESTINATION bin)
+ endif()
+
+ set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
+ get_target_property(SONAME SDL OUTPUT_NAME)
+ if(UNIX AND NOT ANDROID)
+ install(CODE "
+ execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
+ \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL${SOPOSTFIX}${SOEXT}\"
+ WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")")
+ install(FILES ${CMAKE_BINARY_DIR}/libSDL${SOPOSTFIX}${SOEXT} DESTINATION "${CMAKE_INSTALL_LIBDIR}")
+ endif()
+
+ install(FILES "${CMAKE_SOURCE_DIR}/sdl.m4" DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/aclocal")
+endif()
+
+if(STATICDEVEL AND SDL2DEVEL)
+ add_library(SDL-static STATIC ${SDL2COMPAT_SRCS})
+ target_include_directories(SDL-static PRIVATE ${SDL2_INCLUDE_DIRS})
+ set_target_properties(SDL-static PROPERTIES COMPILE_DEFINITIONS "_REENTRANT")
+ target_link_libraries(SDL-static PRIVATE ${CMAKE_DL_LIBS})
+ set_target_properties(SDL-static PROPERTIES
+ VERSION "${PROJECT_VERSION}"
+ OUTPUT_NAME "SDL")
+
+ install(TARGETS SDL-static
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ )
+endif()
diff --git a/cmake/modules/FindSDL3.cmake b/cmake/modules/FindSDL3.cmake
new file mode 100644
index 0000000..d733098
--- /dev/null
+++ b/cmake/modules/FindSDL3.cmake
@@ -0,0 +1,392 @@
+# (I updated this to change '2' to '3'. There will probably be a more
+# formal FindSDL3.cmake at some point. --ryan.)
+#
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# Copyright 2019 Amine Ben Hassouna <amine.benhassouna@gmail.com>
+# Copyright 2000-2019 Kitware, Inc. and Contributors
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+
+# * Neither the name of Kitware, Inc. nor the names of Contributors
+# may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#[=======================================================================[.rst:
+FindSDL3
+--------
+
+Locate SDL3 library
+
+This module defines the following 'IMPORTED' targets:
+
+::
+
+ SDL3::Core
+ The SDL3 library, if found.
+ Libraries should link to SDL3::Core
+
+ SDL3::Main
+ The SDL3main library, if found.
+ Applications should link to SDL3::Main instead of SDL3::Core
+
+
+
+This module will set the following variables in your project:
+
+::
+
+ SDL3_LIBRARIES, the name of the library to link against
+ SDL3_INCLUDE_DIRS, where to find SDL.h
+ SDL3_FOUND, if false, do not try to link to SDL3
+ SDL3MAIN_FOUND, if false, do not try to link to SDL3main
+ SDL3_VERSION_STRING, human-readable string containing the version of SDL3
+
+
+
+This module responds to the following cache variables:
+
+::
+
+ SDL3_PATH
+ Set a custom SDL3 Library path (default: empty)
+
+ SDL3_NO_DEFAULT_PATH
+ Disable search SDL3 Library in default path.
+ If SDL3_PATH (default: ON)
+ Else (default: OFF)
+
+ SDL3_INCLUDE_DIR
+ SDL3 headers path.
+
+ SDL3_LIBRARY
+ SDL3 Library (.dll, .so, .a, etc) path.
+
+ SDL3MAIN_LIBRAY
+ SDL3main Library (.a) path.
+
+ SDL3_BUILDING_LIBRARY
+ This flag is useful only when linking to SDL3_LIBRARIES insead of
+ SDL3::Main. It is required only when building a library that links to
+ SDL3_LIBRARIES, because only applications need main() (No need to also
+ link to SDL3main).
+ If this flag is defined, then no SDL3main will be added to SDL3_LIBRARIES
+ and no SDL3::Main target will be created.
+
+
+Don't forget to include SDLmain.h and SDLmain.m in your project for the
+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 SDL3_LIBRARY in your project
+configuration, 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_LIBRARIES variable and the
+SDL3::Core and SDL3::Main targets, but when these values are unset,
+SDL3_LIBRARIES, SDL3::Core and SDL3::Main does not get created.
+
+
+$SDL3DIR is an environment variable that would correspond to the
+./configure --prefix=$SDL3DIR used in building SDL3. l.e.galup 9-20-02
+
+
+
+Created by Amine Ben Hassouna:
+ Adapt FindSDL.cmake to SDL3 (FindSDL3.cmake).
+ Add cache variables for more flexibility:
+ SDL3_PATH, SDL3_NO_DEFAULT_PATH (for details, see doc above).
+ Mark 'Threads' as a required dependency for non-OSX systems.
+ Modernize the FindSDL3.cmake module by creating specific targets:
+ SDL3::Core and SDL3::Main (for details, see doc above).
+
+
+Original FindSDL.cmake module:
+ Modified by Eric Wing. Added code to assist with automated building
+ by using environmental variables and providing a more
+ controlled/consistent search behavior. 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 SDLmain 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 value of SDL3_LIBRARY to
+override this selection or set the SDL3_PATH variable or the CMake
+environment CMAKE_INCLUDE_PATH to modify the search paths.
+
+Note that the header path has changed from SDL/SDL.h to just SDL.h
+This needed to change because "proper" SDL convention is #include
+"SDL.h", not <SDL/SDL.h>. This is done for portability reasons
+because not all systems place things in SDL/ (see FreeBSD).
+#]=======================================================================]
+
+# Define options for searching SDL3 Library in a custom path
+
+set(SDL3_PATH "" CACHE STRING "Custom SDL3 Library path")
+
+set(_SDL3_NO_DEFAULT_PATH OFF)
+if(SDL3_PATH)
+ set(_SDL3_NO_DEFAULT_PATH ON)
+endif()
+
+set(SDL3_NO_DEFAULT_PATH ${_SDL3_NO_DEFAULT_PATH}
+ CACHE BOOL "Disable search SDL3 Library in default path")
+unset(_SDL3_NO_DEFAULT_PATH)
+
+set(SDL3_NO_DEFAULT_PATH_CMD)
+if(SDL3_NO_DEFAULT_PATH)
+ set(SDL3_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH)
+endif()
+
+# Search for the SDL3 include directory
+find_path(SDL3_INCLUDE_DIR SDL.h
+ HINTS
+ ENV SDL3DIR
+ ${SDL3_NO_DEFAULT_PATH_CMD}
+ PATH_SUFFIXES SDL3
+ # path suffixes to search inside ENV{SDL3DIR}
+ include/SDL3 include
+ PATHS ${SDL3_PATH}
+ DOC "Where the SDL3 headers can be found"
+)
+
+set(SDL3_INCLUDE_DIRS "${SDL3_INCLUDE_DIR}")
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+# SDL-3.0 is the name used by FreeBSD ports...
+# don't confuse it for the version number.
+find_library(SDL3_LIBRARY
+ NAMES SDL3 SDL-3.0
+ HINTS
+ ENV SDL3DIR
+ ${SDL3_NO_DEFAULT_PATH_CMD}
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+ PATHS ${SDL3_PATH}
+ DOC "Where the SDL3 Library can be found"
+)
+
+set(SDL3_LIBRARIES "${SDL3_LIBRARY}")
+
+if(NOT SDL3_BUILDING_LIBRARY)
+ if(NOT SDL3_INCLUDE_DIR MATCHES ".framework")
+ # Non-OS X framework versions expect you to also dynamically link to
+ # SDL3main. This is mainly for Windows and OS X. Other (Unix) platforms
+ # seem to provide SDL3main for compatibility even though they don't
+ # necessarily need it.
+
+ if(SDL3_PATH)
+ set(SDL3MAIN_LIBRARY_PATHS "${SDL3_PATH}")
+ endif()
+
+ if(NOT SDL3_NO_DEFAULT_PATH)
+ set(SDL3MAIN_LIBRARY_PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ "${SDL3MAIN_LIBRARY_PATHS}"
+ )
+ endif()
+
+ find_library(SDL3MAIN_LIBRARY
+ NAMES SDL3main
+ HINTS
+ ENV SDL3DIR
+ ${SDL3_NO_DEFAULT_PATH_CMD}
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+ PATHS ${SDL3MAIN_LIBRARY_PATHS}
+ DOC "Where the SDL3main library can be found"
+ )
+ unset(SDL3MAIN_LIBRARY_PATHS)
+ endif()
+endif()
+
+# 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.
+if(NOT APPLE)
+ find_package(Threads QUIET)
+ if(NOT Threads_FOUND)
+ set(SDL3_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL3).")
+ if(SDL3_FIND_REQUIRED)
+ message(FATAL_ERROR ${SDL3_THREADS_NOT_FOUND})
+ else()
+ if(NOT SDL3_FIND_QUIETLY)
+ message(STATUS ${SDL3_THREADS_NOT_FOUND})
+ endif()
+ return()
+ endif()
+ unset(SDL3_THREADS_NOT_FOUND)
+ endif()
+endif()
+
+# MinGW needs an additional link flag, -mwindows
+# It's total link flags should look like -lmingw32 -lSDL3main -lSDL3 -mwindows
+if(MINGW)
+ set(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "link flags for MinGW")
+endif()
+
+if(SDL3_LIBRARY)
+ # For SDL3main
+ if(SDL3MAIN_LIBRARY AND NOT SDL3_BUILDING_LIBRARY)
+ list(FIND SDL3_LIBRARIES "${SDL3MAIN_LIBRARY}" _SDL3_MAIN_INDEX)
+ if(_SDL3_MAIN_INDEX EQUAL -1)
+ set(SDL3_LIBRARIES "${SDL3MAIN_LIBRARY}" ${SDL3_LIBRARIES})
+ endif()
+ unset(_SDL3_MAIN_INDEX)
+ endif()
+
+ # 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(SDL3_LIBRARIES ${SDL3_LIBRARIES} -framework Cocoa)
+ endif()
+
+ # 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(SDL3_LIBRARIES ${SDL3_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+
+ # For MinGW library
+ if(MINGW)
+ set(SDL3_LIBRARIES ${MINGW32_LIBRARY} ${SDL3_LIBRARIES})
+ endif()
+
+endif()
+
+# Read SDL3 version
+if(SDL3_INCLUDE_DIR AND EXISTS "${SDL3_INCLUDE_DIR}/SDL_version.h")
+ file(STRINGS "${SDL3_INCLUDE_DIR}/SDL_version.h" SDL3_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL3_INCLUDE_DIR}/SDL_version.h" SDL3_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL3_INCLUDE_DIR}/SDL_version.h" SDL3_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL3_VERSION_MAJOR "${SDL3_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL3_VERSION_MINOR "${SDL3_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL3_VERSION_PATCH "${SDL3_VERSION_PATCH_LINE}")
+ set(SDL3_VERSION_STRING ${SDL3_VERSION_MAJOR}.${SDL3_VERSION_MINOR}.${SDL3_VERSION_PATCH})
+ unset(SDL3_VERSION_MAJOR_LINE)
+ unset(SDL3_VERSION_MINOR_LINE)
+ unset(SDL3_VERSION_PATCH_LINE)
+ unset(SDL3_VERSION_MAJOR)
+ unset(SDL3_VERSION_MINOR)
+ unset(SDL3_VERSION_PATCH)
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL3
+ REQUIRED_VARS SDL3_LIBRARY SDL3_INCLUDE_DIR
+ VERSION_VAR SDL3_VERSION_STRING)
+
+if(SDL3MAIN_LIBRARY)
+ set(FPHSA_NAME_MISMATCHED 1)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL3main
+ REQUIRED_VARS SDL3MAIN_LIBRARY SDL3_INCLUDE_DIR
+ VERSION_VAR SDL3_VERSION_STRING)
+endif()
+
+
+mark_as_advanced(SDL3_PATH
+ SDL3_NO_DEFAULT_PATH
+ SDL3_LIBRARY
+ SDL3MAIN_LIBRARY
+ SDL3_INCLUDE_DIR
+ SDL3_BUILDING_LIBRARY)
+
+
+# SDL3:: targets (SDL3::Core and SDL3::Main)
+if(SDL3_FOUND)
+
+ # SDL3::Core target
+ if(SDL3_LIBRARY AND NOT TARGET SDL3::Core)
+ add_library(SDL3::Core UNKNOWN IMPORTED)
+ set_target_properties(SDL3::Core PROPERTIES
+ IMPORTED_LOCATION "${SDL3_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}")
+
+ if(APPLE)
+ # For OS X, SDL3 uses Cocoa as a backend so it must link to Cocoa.
+ # For more details, please see above.
+ set_property(TARGET SDL3::Core APPEND PROPERTY
+ INTERFACE_LINK_OPTIONS -framework Cocoa)
+ else()
+ # For threads, as mentioned Apple doesn't need this.
+ # For more details, please see above.
+ set_property(TARGET SDL3::Core APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES Threads::Threads)
+ endif()
+ endif()
+
+ # SDL3::Main target
+ # Applications should link to SDL3::Main instead of SDL3::Core
+ # For more details, please see above.
+ if(NOT SDL3_BUILDING_LIBRARY AND NOT TARGET SDL3::Main)
+
+ if(SDL3_INCLUDE_DIR MATCHES ".framework" OR NOT SDL3MAIN_LIBRARY)
+ add_library(SDL3::Main INTERFACE IMPORTED)
+ set_property(TARGET SDL3::Main PROPERTY
+ INTERFACE_LINK_LIBRARIES SDL3::Core)
+ elseif(SDL3MAIN_LIBRARY)
+ # MinGW requires that the mingw32 library is specified before the
+ # libSDL3main.a static library when linking.
+ # The SDL3::MainInternal target is used internally to make sure that
+ # CMake respects this condition.
+ add_library(SDL3::MainInternal UNKNOWN IMPORTED)
+ set_property(TARGET SDL3::MainInternal PROPERTY
+ IMPORTED_LOCATION "${SDL3MAIN_LIBRARY}")
+ set_property(TARGET SDL3::MainInternal PROPERTY
+ INTERFACE_LINK_LIBRARIES SDL3::Core)
+
+ add_library(SDL3::Main INTERFACE IMPORTED)
+
+ if(MINGW)
+ # MinGW needs an additional link flag '-mwindows' and link to mingw32
+ set_property(TARGET SDL3::Main PROPERTY
+ INTERFACE_LINK_LIBRARIES "mingw32" "-mwindows")
+ endif()
+
+ set_property(TARGET SDL3::Main APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES SDL3::MainInternal)
+ endif()
+
+ endif()
+endif()
diff --git a/sdl2_compat.pc.in b/sdl2_compat.pc.in
new file mode 100644
index 0000000..1df560c
--- /dev/null
+++ b/sdl2_compat.pc.in
@@ -0,0 +1,14 @@
+# sdl2_compat pkg-config source file
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
+
+Name: sdl2_compat
+Description: An SDL2 compatibility layer that uses SDL3 behind the scenes.
+Version: @PROJECT_VERSION@
+Provides: sdl = @PROJECT_VERSION@
+Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@
+@ENABLE_STATIC_TRUE@Libs.private: -L${libdir} @SDL_LIBS@ @SDL_STATIC_LIBS@
+Cflags: -I${includedir}/SDL @SDL_CFLAGS@
diff --git a/src/SDLmain/dummy/SDL_dummy_main.c b/src/SDLmain/dummy/SDL_dummy_main.c
new file mode 100644
index 0000000..b78d8db
--- /dev/null
+++ b/src/SDLmain/dummy/SDL_dummy_main.c
@@ -0,0 +1,25 @@
+/*
+ SDL_dummy_main.c, placed in the public domain by Sam Lantinga 3/13/14
+*/
+#include "../../SDL_internal.h"
+
+/* Include the SDL main definition header */
+#include "SDL_main.h"
+
+#ifdef main
+#undef main
+int
+main(int argc, char *argv[])
+{
+ return (SDL_main(argc, argv));
+}
+#else
+/* Nothing to do on this platform */
+int
+SDL_main_stub_symbol(void)
+{
+ return 0;
+}
+#e
(Patch may be truncated, please check the link at the top of this post.)