make sound support optional

This commit is contained in:
Dethrace Labs 2025-06-22 08:25:55 +12:00
parent 85a5613494
commit 465fa22c02
3 changed files with 111 additions and 12 deletions

View File

@ -23,6 +23,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
else()
include(GetGitRevisionDescription)
git_describe(DETHRACE_VERSION)
if(NOT DETHRACE_VERSION)
set(DETHRACE_VERSION "unknown")
endif()
@ -39,15 +40,19 @@ option(DETHRACE_INSTALL "Add install target" OFF)
option(DETHRACE_WERROR "Treat warnings as errors")
option(DETHRACE_FIX_BUGS "Fix Dethrace bugs" ON)
option(DETHRACE_3DFX_PATCH "Include changes from VOODOO2C.EXE" ON)
option(DETHRACE_SOUND_ENABLED "Include audio support" ON)
function(add_compile_flag_if_supported TARGET FLAG)
cmake_parse_arguments(ARGS "" "" "LANGUAGES" ${ARGN})
if(NOT ARGS_LANGUAGES)
set(ARGS_LANGUAGES C CXX)
endif()
string(MAKE_C_IDENTIFIER "${FLAG}" FLAG_TO_IDENTIFIER)
set(HAVE_FLAG_VARIABLE_NAME "HAVE_${FLAG_TO_IDENTIFIER}")
check_c_compiler_flag("${FLAG}" "${HAVE_FLAG_VARIABLE_NAME}")
if(${HAVE_FLAG_VARIABLE_NAME})
string(REPLACE ";" "," ARGS_LANGUAGES "${ARGS_LANGUAGES}")
target_compile_options("${TARGET}" PRIVATE "$<$<COMPILE_LANGUAGE:${ARGS_LANGUAGES}>:${FLAG}>")
@ -63,20 +68,24 @@ endfunction()
test_big_endian(IS_BIGENDIAN)
option(DETHRACE_PLATFORM_SDL1 "Support SDL 1.2 platform driver" OFF)
option(DETHRACE_PLATFORM_SDL2 "Support SDL 2 platform driver" ON)
option(DETHRACE_PLATFORM_SDL2 "Support SDL 2 platform driver" ON)
set(count_sdl_platforms 0)
set(DETHRACE_PLATFORMS )
set(DETHRACE_PLATFORMS)
if(DETHRACE_PLATFORM_SDL1)
find_package(SDL REQUIRED)
list(APPEND DETHRACE_PLATFORMS SDL1)
math(EXPR count_sdl_platforms "${count_sdl_platforms} + 1")
endif()
if(DETHRACE_PLATFORM_SDL2)
find_package(SDL2 CONFIG)
if(NOT SDL2_FOUND)
find_package(SDL2 MODULE REQUIRED)
endif()
list(APPEND DETHRACE_PLATFORMS SDL2)
math(EXPR count_sdl_platforms "${count_sdl_platforms} + 1")
endif()
@ -98,8 +107,11 @@ endif()
add_subdirectory(lib/BRender-v1.3.2)
add_subdirectory(lib/libsmacker)
add_subdirectory(lib/miniaudio)
add_subdirectory(lib/stb)
if(DETHRACE_SOUND_ENABLED)
add_subdirectory(lib/miniaudio2)
add_subdirectory(lib/stb2)
endif()
add_library(compile_with_werror INTERFACE)
@ -140,6 +152,7 @@ if(DETHRACE_INSTALL)
set(CPACK_SYSTEM_NAME "${DETHRACE_PACKAGE_PLATFORM}")
set(CPACK_PACKAGE_FILE_NAME "dethrace-${DETHRACE_VERSION}-${DETHRACE_PACKAGE_PLATFORM}")
if(DETHRACE_PACKAGE_ARCH)
string(APPEND CPACK_PACKAGE_FILE_NAME "-${DETHRACE_PACKAGE_ARCH}")
endif()

View File

@ -4,18 +4,18 @@ add_library(harness STATIC)
target_include_directories(harness
PRIVATE
.
${CMAKE_SOURCE_DIR}
"${CMAKE_CURRENT_BINARY_DIR}"
.
${CMAKE_SOURCE_DIR}
"${CMAKE_CURRENT_BINARY_DIR}"
PUBLIC
include
include
)
if(DETHRACE_FIX_BUGS)
target_compile_definitions(harness PRIVATE DETHRACE_FIX_BUGS)
endif()
target_link_libraries(harness PRIVATE brender miniaudio stb compile_with_werror)
target_link_libraries(harness PRIVATE brender compile_with_werror)
if(NOT MSVC)
target_compile_options(harness PRIVATE
@ -41,19 +41,29 @@ target_sources(harness PRIVATE
include/harness/config.h
include/harness/os.h
include/harness/audio.h
# cameras/debug_camera.c
# cameras/debug_camera.h
ascii_tables.h
harness_trace.c
harness.c
harness.h
audio/miniaudio.c
platforms/null.c
platforms/null.h
"${CMAKE_CURRENT_BINARY_DIR}/version.h"
)
if(DETHRACE_SOUND_ENABLED)
target_sources(harness PRIVATE
audio/miniaudio.c
)
target_link_libraries(harness PRIVATE miniaudio stb)
else()
target_sources(harness PRIVATE
audio/null.c
)
endif()
if(DETHRACE_PLATFORM_SDL1)
target_sources(harness PRIVATE
platforms/sdl1.c
@ -61,6 +71,7 @@ if(DETHRACE_PLATFORM_SDL1)
platforms/sdl1_syms.h
)
target_compile_definitions(harness PRIVATE DETHRACE_PLATFORM_SDL1)
if(DETHRACE_PLATFORM_SDL_DYNAMIC)
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/platforms/sdl1.c" APPEND PROPERTY INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:SDL::SDL,INTERFACE_INCLUDE_DIRECTORIES>")
get_filename_component(sdl_library_directory "${SDL_LIBRARY}" DIRECTORY)
@ -78,6 +89,7 @@ if(DETHRACE_PLATFORM_SDL2)
platforms/sdl2_syms.h
)
target_compile_definitions(harness PRIVATE DETHRACE_PLATFORM_SDL2)
if(DETHRACE_PLATFORM_SDL_DYNAMIC)
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/platforms/sdl2.c" APPEND PROPERTY INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:SDL2::SDL2,INTERFACE_INCLUDE_DIRECTORIES>")
set_property(GLOBAL APPEND PROPERTY DETHRACE_BUILD_RPATHS "$<TARGET_FILE_DIR:SDL2::SDL2>")

74
src/harness/audio/null.c Normal file
View File

@ -0,0 +1,74 @@
#include "harness/audio.h"
#include <string.h>
tAudioBackend_error_code AudioBackend_Init(void) {
return eAB_error;
}
void AudioBackend_UnInit(void) {
}
tAudioBackend_error_code AudioBackend_InitCDA(void) {
return eAB_error;
}
void AudioBackend_UnInitCDA(void) {
}
void* AudioBackend_AllocateSampleTypeStruct(void) {
}
tAudioBackend_error_code AudioBackend_PlaySample(void* type_struct_sample, int channels, void* data, int size, int rate, int loop) {
return eAB_error;
}
int AudioBackend_SoundIsPlaying(void* type_struct_sample) {
}
tAudioBackend_error_code AudioBackend_StopSample(void* type_struct_sample) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_SetVolume(void* type_struct_sample, int volume) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_SetPan(void* type_struct_sample, int pan) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_SetFrequency(void* type_struct_sample, int original_rate, int new_rate) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_SetVolumeSeparate(void* type_struct_sample, int left_volume, int right_volume) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_PlayCDA(int track) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_StopCDA(void) {
return eAB_error;
}
int AudioBackend_CDAIsPlaying(void) {
}
tAudioBackend_error_code AudioBackend_SetCDAVolume(int volume) {
return eAB_error;
}
// Used by smackw32
tAudioBackend_stream* AudioBackend_StreamOpen(int bitdepth, int channels, unsigned int sample_rate) {
return NULL;
}
tAudioBackend_error_code AudioBackend_StreamWrite(tAudioBackend_stream* stream_handle, const unsigned char* data, unsigned long size) {
return eAB_error;
}
tAudioBackend_error_code AudioBackend_StreamClose(tAudioBackend_stream* stream_handle) {
return eAB_error;
}