Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build/
.vscode/
.cache/
CLAUDE.md
38 changes: 8 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
cmake_minimum_required(VERSION 3.14)
project(soundcoe VERSION 0.0.1 LANGUAGES CXX)
cmake_minimum_required(VERSION 3.20)
project(soundcoe LANGUAGES C CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(SOUNDCOE_SOURCE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

include(FetchContent)
include(cmake/soundcoe_config.cmake)

find_package(Threads REQUIRED)

# Configure OpenAL: Use Emscripten's built-in OpenAL or fetch OpenAL-Soft
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
message(STATUS "[soundcoe] Using Emscripten's built-in OpenAL implementation")
# Emscripten provides its own OpenAL implementation via -lopenal linker flag
# No need to fetch or configure OpenAL-Soft
else()
message(STATUS "[soundcoe] Fetching OpenAL-Soft from source...")

FetchContent_Declare(
openal
GIT_REPOSITORY https://github.com/kcat/openal-soft.git
GIT_TAG 1.24.3
)

configure_openal()
FetchContent_MakeAvailable(openal)
ignore_external_warnings(OpenAL)
endif()

message(STATUS "[soundcoe] Fetching logcoe from source...")
fetch_openal_soft()
fetch_logcoe()

FetchContent_Declare(
logcoe
GIT_REPOSITORY https://github.com/nircoe/logcoe.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(logcoe)
ignore_external_warnings(logcoe)
generate_soundcoe_config_header()

add_subdirectory(include)
add_subdirectory(src)
Expand Down
12 changes: 12 additions & 0 deletions cmake/config_header.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function(generate_soundcoe_config_header)
set(SOUNDCOE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/config")
set(SOUNDCOE_CONFIG_DIR ${SOUNDCOE_CONFIG_DIR} PARENT_SCOPE)

file(MAKE_DIRECTORY ${SOUNDCOE_CONFIG_DIR})

configure_file(
${SOUNDCOE_SOURCE_ROOT_DIR}/cmake/soundcoe_config.hpp.in
${SOUNDCOE_CONFIG_DIR}/soundcoe_config.hpp
@ONLY
)
endfunction()
31 changes: 31 additions & 0 deletions cmake/logcoe.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function(fetch_logcoe)
if(NOT DEFINED SOUNDCOE_USE_LOGCOE)
set(SOUNDCOE_USE_LOGCOE OFF)
endif()

if(SOUNDCOE_USE_LOGCOE)
message(STATUS "[soundcoe] Using logcoe for logging")
message(STATUS "[soundcoe] To disable: \"set(SOUNDCOE_USE_LOGCOE OFF)\" before fetching soundcoe")
set(SOUNDCOE_USE_LOGCOE 1 PARENT_SCOPE)

find_package(logcoe QUIET)

if(NOT logcoe_FOUND)
message(STATUS "[soundcoe] Fetching logcoe from source...")

FetchContent_Declare(
logcoe
GIT_REPOSITORY https://github.com/nircoe/logcoe.git
GIT_TAG v0.1.1
)
FetchContent_MakeAvailable(logcoe)
ignore_external_warnings(logcoe)
else()
message(STATUS "[soundcoe] Using existing logcoe")
endif()
else()
message(STATUS "[soundcoe] logcoe disabled")
message(STATUS "[soundcoe] To enable: \"set(SOUNDCOE_USE_LOGCOE ON)\" before fetching soundcoe")
set(SOUNDCOE_USE_LOGCOE 0 PARENT_SCOPE)
endif()
endfunction()
22 changes: 22 additions & 0 deletions cmake/openal_config.cmake → cmake/openal_soft.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
# OpenAL-Soft Configuration for soundcoe
# This file contains all OpenAL backend configurations for different platforms

function(fetch_openal_soft)
# Configure OpenAL: Use Emscripten's built-in OpenAL or fetch OpenAL-Soft
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
message(STATUS "[soundcoe] Using Emscripten's built-in OpenAL implementation")
# Emscripten provides its own OpenAL implementation via -lopenal linker flag
# No need to fetch or configure OpenAL-Soft
else()
message(STATUS "[soundcoe] Fetching OpenAL-Soft from source...")

FetchContent_Declare(
openal
GIT_REPOSITORY https://github.com/kcat/openal-soft.git
GIT_TAG 1.24.3
)

configure_openal()
FetchContent_MakeAvailable(openal)
ignore_external_warnings(OpenAL)
endif()
endfunction()


# Helper function to disable all non-target backends
function(disable_all_backends_except target_backends)
# All known OpenAL-Soft backends
Expand Down
4 changes: 3 additions & 1 deletion cmake/soundcoe_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Master include file for all soundcoe cmake utilities

include(${CMAKE_CURRENT_LIST_DIR}/utils.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/openal_config.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/openal_soft.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/logcoe.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/config_header.cmake)

# Future modules can be added here
32 changes: 32 additions & 0 deletions cmake/soundcoe_config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Auto-generated soundcoe configuration - DO NOT EDIT
#pragma once

#define SOUNDCOE_USE_LOGCOE @SOUNDCOE_USE_LOGCOE@

#if !SOUNDCOE_USE_LOGCOE
#include <string>
namespace logcoe
{
enum class LogLevel { DEBUG, INFO, WARNING, ERROR, NONE };

inline void initialize([[maybe_unused]] LogLevel level = LogLevel::DEBUG,
[[maybe_unused]] const std::string& defaultSource = "",
[[maybe_unused]] bool enableConsole = true,
[[maybe_unused]] bool enableFile = false,
[[maybe_unused]] const std::string &filename = "logcoe.log") { }

inline void shutdown() { }
inline void debug([[maybe_unused]] const std::string &message,
[[maybe_unused]] const std::string &source = "",
[[maybe_unused]] bool flush = true) { }
inline void info([[maybe_unused]] const std::string &message,
[[maybe_unused]] const std::string &source = "",
[[maybe_unused]] bool flush = true) { }
inline void warning([[maybe_unused]] const std::string &message,
[[maybe_unused]] const std::string &source = "",
[[maybe_unused]] bool flush = true) { }
inline void error([[maybe_unused]] const std::string &message,
[[maybe_unused]] const std::string &source = "",
[[maybe_unused]] bool flush = true) { }
} // namespace logcoe
#endif
5 changes: 3 additions & 2 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ add_library(soundcoe_headers INTERFACE)
target_include_directories(soundcoe_headers
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${SOUNDCOE_CONFIG_DIR}>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(soundcoe_headers
INTERFACE
logcoe
$<$<BOOL:${SOUNDCOE_USE_LOGCOE}>:logcoe>
)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/soundcoe.hpp
Expand Down
5 changes: 4 additions & 1 deletion include/soundcoe/core/types.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include <logcoe.hpp>
#include <cmath>
#include <string_view>
#include <sstream>
#include <limits>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
target_link_libraries(soundcoe
PUBLIC
soundcoe_headers
logcoe
Threads::Threads
PRIVATE
$<$<BOOL:${SOUNDCOE_USE_LOGCOE}>:logcoe>
)
# Link with Emscripten's built-in OpenAL implementation
target_link_options(soundcoe PRIVATE -lopenal)
else()
target_link_libraries(soundcoe
PUBLIC
soundcoe_headers
logcoe
Threads::Threads
PRIVATE
OpenAL
$<$<BOOL:${SOUNDCOE_USE_LOGCOE}>:logcoe>
)
endif()
5 changes: 4 additions & 1 deletion src/core/audio_context.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <soundcoe/core/audio_context.hpp>
#include <soundcoe/core/error_handler.hpp>
#include <logcoe.hpp>
#include <iostream>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
5 changes: 4 additions & 1 deletion src/core/error_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <soundcoe/core/error_handler.hpp>
#include <logcoe.hpp>
#include <iostream>
#include <sstream>
#include <exception>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
5 changes: 4 additions & 1 deletion src/playback/sound_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <soundcoe/playback/sound_manager.hpp>
#include <soundcoe/core/error_handler.hpp>
#include <AL/al.h>
#include <logcoe.hpp>
#include <functional>
#include <filesystem>
#include <algorithm>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
6 changes: 5 additions & 1 deletion src/resources/audio_data.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <soundcoe/resources/audio_data.hpp>
#include <soundcoe/core/error_handler.hpp>
#include <logcoe.hpp>
#include <exception>

#define DR_WAV_IMPLEMENTATION
Expand All @@ -9,6 +8,11 @@
#include <dr_libs/dr_mp3.h>
#include <stb/stb_vorbis.c>

#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
namespace detail
Expand Down
7 changes: 5 additions & 2 deletions src/resources/resource_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <soundcoe/resources/resource_manager.hpp>
#include <soundcoe/core/audio_context.hpp>
#include <soundcoe/core/error_handler.hpp>
#include <logcoe.hpp>
#include <algorithm>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down Expand Up @@ -116,7 +119,7 @@ namespace soundcoe
}

logcoe::warning("ResourceManager::preloadDirectory: No audio files found in directory: " + subdirectory);
return false;
return true;
}

bool ResourceManager::unloadDirectory(const std::string &subdirectory)
Expand Down
5 changes: 4 additions & 1 deletion src/resources/sound_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#include <soundcoe/core/audio_context.hpp>
#include <soundcoe/core/error_handler.hpp>
#include <soundcoe/core/types.hpp>
#include <logcoe.hpp>
#include <iostream>
#include <exception>
#include <cassert>
#include <filesystem>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
3 changes: 3 additions & 0 deletions src/resources/sound_source.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <soundcoe/resources/sound_source.hpp>
#include <soundcoe/core/error_handler.hpp>
#include <exception>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
5 changes: 4 additions & 1 deletion src/soundcoe.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <soundcoe.hpp>
#include <soundcoe/playback/sound_manager.hpp>
#include <logcoe.hpp>
#include <cassert>
#include <soundcoe_config.hpp>
#if SOUNDCOE_USE_LOGCOE
#include <logcoe.hpp>
#endif

namespace soundcoe
{
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(FetchContent)
FetchContent_Declare(
testcoe
GIT_REPOSITORY https://github.com/nircoe/testcoe.git
GIT_TAG v0.1.0
GIT_TAG v0.1.1
)

FetchContent_MakeAvailable(testcoe)
Expand Down
Loading