Skip to content

Commit

Permalink
Initial FAUDIO_SDL3_PLATFORM
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Apr 14, 2024
1 parent 6ee58c1 commit 360786b
Show file tree
Hide file tree
Showing 4 changed files with 769 additions and 7 deletions.
53 changes: 48 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ project(FAudio C)
# Options
option(BUILD_UTILS "Build utils/ folder" OFF)
option(BUILD_TESTS "Build tests/ folder for unit tests to be executed on the host against FAudio" OFF)
option(BUILD_SDL3 "Build against SDL 3.0" OFF)
if(WIN32)
option(PLATFORM_WIN32 "Enable native Win32 platform instead of SDL2" OFF)
option(PLATFORM_WIN32 "Enable native Win32 platform instead of SDL" OFF)
endif()
option(XNASONG "Build with XNA_Song.c" ON)
option(LOG_ASSERTIONS "Bind FAudio_assert to log, instead of platform's assert" OFF)
Expand Down Expand Up @@ -98,6 +99,7 @@ add_library(FAudio
src/FAudio_internal_simd.c
src/FAudio_operationset.c
src/FAudio_platform_sdl2.c
src/FAudio_platform_sdl3.c
src/FAudio_platform_win32.c
# Optional source files
src/XNA_Song.c
Expand All @@ -110,7 +112,12 @@ if(PLATFORM_WIN32)
set(PLATFORM_CFLAGS "-DFAUDIO_WIN32_PLATFORM")
set(XNASONG OFF)
else()
set(PLATFORM_CFLAGS)
if(BUILD_SDL3)
target_compile_definitions(FAudio PUBLIC FAUDIO_SDL3_PLATFORM)
set(PLATFORM_CFLAGS "-DFAUDIO_SDL3_PLATFORM")
else()
set(PLATFORM_CFLAGS)
endif()
endif()

# Only disable DebugConfiguration in release builds
Expand Down Expand Up @@ -150,9 +157,41 @@ if(DUMP_VOICES)
target_compile_definitions(FAudio PRIVATE FAUDIO_DUMP_VOICES)
endif()

# SDL2 Dependency
# SDL Dependency
if (PLATFORM_WIN32)
message(STATUS "not using SDL2")
message(STATUS "not using SDL")
elseif (BUILD_SDL3)
if (DEFINED SDL3_INCLUDE_DIRS AND DEFINED SDL3_LIBRARIES)
message(STATUS "using pre-defined SDL3 variables SDL3_INCLUDE_DIRS and SDL3_LIBRARIES")
target_include_directories(FAudio PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(FAudio PUBLIC ${SDL3_LIBRARIES})
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(${SDL3_LIBRARIES} DESTINATION bin NO_INSTALL_SYMLINKS)
endif()
else()
# Only try to autodetect if both SDL3 variables aren't explicitly set
find_package(SDL3 CONFIG)
if (TARGET SDL3::SDL3)
message(STATUS "using TARGET SDL3::SDL3")
target_link_libraries(FAudio PUBLIC SDL3::SDL3)
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(TARGETS SDL3::SDL3 DESTINATION bin NO_INSTALL_SYMLINKS REQUIRED)
endif()
elseif (TARGET SDL3)
message(STATUS "using TARGET SDL3")
target_link_libraries(FAudio PUBLIC SDL3)
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(TARGETS SDL3 DESTINATION bin NO_INSTALL_SYMLINKS REQUIRED)
endif()
else()
message(STATUS "no TARGET SDL3::SDL3, or SDL3, using variables")
target_include_directories(FAudio PUBLIC "$<BUILD_INTERFACE:${SDL3_INCLUDE_DIRS}>")
target_link_libraries(FAudio PUBLIC ${SDL3_LIBRARIES})
if(INSTALL_MINGW_DEPENDENCIES)
install_shared_libs(${SDL3_LIBRARIES} DESTINATION bin NO_INSTALL_SYMLINKS)
endif()
endif()
endif()
elseif (DEFINED SDL2_INCLUDE_DIRS AND DEFINED SDL2_LIBRARIES)
message(STATUS "using pre-defined SDL2 variables SDL2_INCLUDE_DIRS and SDL2_LIBRARIES")
target_include_directories(FAudio PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
Expand Down Expand Up @@ -300,7 +339,11 @@ join_paths(FAUDIO_PKGCONF_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(FAUDIO_PKGCONF_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")

if(NOT PLATFORM_WIN32)
set(PC_REQUIRES_PRIVATE "Requires.private: sdl2")
if(BUILD_SDL3)
set(PC_REQUIRES_PRIVATE "Requires.private: sdl3")
else()
set(PC_REQUIRES_PRIVATE "Requires.private: sdl2")
endif()
endif()

configure_file(
Expand Down
7 changes: 7 additions & 0 deletions src/FAudio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,17 @@ extern void FAudio_Log(char const *msg);
((x << 24) & 0x00FF000000000000) | \
((x << 32) & 0xFF00000000000000)
#else
#ifdef FAUDIO_SDL3_PLATFORM
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_assert.h>
#include <SDL3/SDL_endian.h>
#include <SDL3/SDL_log.h>
#else
#include <SDL_stdinc.h>
#include <SDL_assert.h>
#include <SDL_endian.h>
#include <SDL_log.h>
#endif

#define FAudio_malloc SDL_malloc
#define FAudio_realloc SDL_realloc
Expand Down
4 changes: 2 additions & 2 deletions src/FAudio_platform_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
*/

#ifndef FAUDIO_WIN32_PLATFORM
#if !defined(FAUDIO_WIN32_PLATFORM) && !defined(FAUDIO_SDL3_PLATFORM)

#include "FAudio_internal.h"

Expand Down Expand Up @@ -671,4 +671,4 @@ void FAudio_UTF8_To_UTF16(const char *src, uint16_t *dst, size_t len)

extern int this_tu_is_empty;

#endif /* FAUDIO_WIN32_PLATFORM */
#endif /* !defined(FAUDIO_WIN32_PLATFORM) && !defined(FAUDIO_SDL3_PLATFORM) */
Loading

0 comments on commit 360786b

Please sign in to comment.