Add way of disabling flac and vorbis support

This commit is contained in:
Ted John 2022-05-15 17:16:36 +01:00
parent d493563f7e
commit dc47f4296f
4 changed files with 68 additions and 23 deletions

View File

@ -355,7 +355,7 @@ jobs:
echo 'Image not pushed'
fi
linux-clang:
name: Linux (Debug, [http, network, OpenGL] disabled) using clang
name: Linux (Debug, [http, network, flac, vorbis OpenGL] disabled) using clang
runs-on: ubuntu-latest
needs: check-code-formatting
container: openrct2/openrct2-build:8-jammy
@ -369,7 +369,7 @@ jobs:
- name: Install GCC problem matcher
uses: ammaraskar/gcc-problem-matcher@master
- name: Build OpenRCT2
run: . scripts/setenv && build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DDISABLE_NETWORK=ON -DDISABLE_HTTP=ON -DDISABLE_OPENGL=ON
run: . scripts/setenv && build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DDISABLE_NETWORK=ON -DDISABLE_HTTP=ON -DDISABLE_FLAC=ON -DDISABLE_VORBIS=ON -DDISABLE_OPENGL=ON
android:
name: Android
runs-on: ubuntu-latest

View File

@ -5,18 +5,31 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
endif ()
# Options
option(DISABLE_OPENGL "Disable OpenGL support.")
option(DISABLE_FLAC "Disable FLAC support.")
option(DISABLE_VORBIS "Disable OGG/VORBIS support.")
option(DISABLE_OPENGL "Disable OpenGL support.")
# Third party libraries
if (MSVC)
find_package(SDL2 REQUIRED)
find_library(SPEEX_LDFLAGS libspeexdsp)
if (NOT DISABLE_FLAC)
find_library(SPEEX_LDFLAGS libflac)
endif ()
if (NOT DISABLE_VORBIS)
find_library(SPEEX_LDFLAGS libogg)
find_library(SPEEX_LDFLAGS libvorbis)
endif ()
else ()
PKG_CHECK_MODULES(SDL2 REQUIRED IMPORTED_TARGET sdl2)
PKG_CHECK_MODULES(SPEEX REQUIRED IMPORTED_TARGET speexdsp)
PKG_CHECK_MODULES(OGG REQUIRED IMPORTED_TARGET ogg)
PKG_CHECK_MODULES(VORBISFILE REQUIRED IMPORTED_TARGET vorbisfile)
PKG_CHECK_MODULES(FLAC REQUIRED IMPORTED_TARGET flac)
if (NOT DISABLE_FLAC)
PKG_CHECK_MODULES(FLAC REQUIRED IMPORTED_TARGET flac)
endif ()
if (NOT DISABLE_VORBIS)
PKG_CHECK_MODULES(OGG REQUIRED IMPORTED_TARGET ogg)
PKG_CHECK_MODULES(VORBISFILE REQUIRED IMPORTED_TARGET vorbisfile)
endif ()
endif ()
if (NOT DISABLE_OPENGL)
@ -50,20 +63,30 @@ ipo_set_target_properties(${PROJECT_NAME})
if (NOT MSVC AND NOT WIN32)
target_link_libraries(${PROJECT_NAME} "libopenrct2"
PkgConfig::SDL2
PkgConfig::SPEEX
PkgConfig::OGG
PkgConfig::VORBISFILE
PkgConfig::FLAC)
PkgConfig::SPEEX)
else ()
target_link_libraries(${PROJECT_NAME} "libopenrct2"
${SDL2_LDFLAGS}
${SPEEX_LDFLAGS}
${OGG_LDFLAGS}
${VORBIS_LDFLAGS}
${FLAC_LDFLAGS})
${SPEEX_LDFLAGS})
endif ()
target_link_platform_libraries(${PROJECT_NAME})
if (NOT DISABLE_FLAC)
if (NOT MSVC AND NOT WIN32)
target_link_libraries(${PROJECT_NAME} PkgConfig::FLAC)
else ()
target_link_libraries(${PROJECT_NAME} ${FLAC_LDFLAGS})
endif ()
endif ()
if (NOT DISABLE_VORBIS)
if (NOT MSVC AND NOT WIN32)
target_link_libraries(${PROJECT_NAME} PkgConfig::OGG PkgConfig::VORBISFILE)
else ()
target_link_libraries(${PROJECT_NAME} ${OGG_LDFLAGS} ${VORBISFILE_LDFLAGS})
endif ()
endif ()
if (NOT DISABLE_OPENGL)
if (WIN32)
target_link_libraries(${PROJECT_NAME} opengl32)
@ -114,6 +137,12 @@ if (MSVC)
endif ()
# Defines
if (DISABLE_FLAC)
add_definitions(-DDISABLE_FLAC)
fi ()
if (DISABLE_VORBIS)
add_definitions(-DDISABLE_VORBIS)
fi ()
if (DISABLE_OPENGL)
add_definitions(-DDISABLE_OPENGL)
else ()

View File

@ -9,12 +9,15 @@
#include "SDLAudioSource.h"
#include <FLAC/all.h>
#include <SDL.h>
#include <vector>
#ifndef DISABLE_FLAC
# include <FLAC/all.h>
# include <SDL.h>
# include <vector>
#endif
namespace OpenRCT2::Audio
{
#ifndef DISABLE_FLAC
/**
* An audio source which decodes a FLAC stream.
*/
@ -311,14 +314,19 @@ namespace OpenRCT2::Audio
{
}
};
#endif
std::unique_ptr<SDLAudioSource> CreateFlacAudioSource(SDL_RWops* rw)
{
#ifndef DISABLE_FLAC
auto source = std::make_unique<FlacAudioSource>();
if (!source->LoadFlac(rw))
{
source = nullptr;
throw std::runtime_error("Unable to load FLAC stream");
}
return source;
#else
throw std::runtime_error("OpenRCT2 has not been compiled with FLAC support");
#endif
}
} // namespace OpenRCT2::Audio

View File

@ -9,13 +9,16 @@
#include "SDLAudioSource.h"
#include <SDL.h>
#include <optional>
#include <vector>
#include <vorbis/vorbisfile.h>
#ifndef DISABLE_VORBIS
# include <SDL.h>
# include <optional>
# include <vector>
# include <vorbis/vorbisfile.h>
#endif
namespace OpenRCT2::Audio
{
#ifndef DISABLE_VORBIS
/**
* An audio source which decodes a OGG/Vorbis stream.
*/
@ -147,14 +150,19 @@ namespace OpenRCT2::Audio
return static_cast<long>(SDL_RWtell(reinterpret_cast<SDL_RWops*>(datasource)));
}
};
#endif
std::unique_ptr<SDLAudioSource> CreateOggAudioSource(SDL_RWops* rw)
{
#ifndef DISABLE_VORBIS
auto source = std::make_unique<OggAudioSource>();
if (!source->LoadOgg(rw))
{
source = nullptr;
throw std::runtime_error("Unable to load OGG/vorbis stream");
}
return source;
#else
throw std::runtime_error("OpenRCT2 has not been compiled with OGG/vorbis support");
#endif
}
} // namespace OpenRCT2::Audio