diff --git a/.gitignore b/.gitignore index b3177a6..02e2c31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ build/ .vscode/ .cache/ -CLAUDE.md \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 736d83b..151ebd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/config_header.cmake b/cmake/config_header.cmake new file mode 100644 index 0000000..1bd9215 --- /dev/null +++ b/cmake/config_header.cmake @@ -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() \ No newline at end of file diff --git a/cmake/logcoe.cmake b/cmake/logcoe.cmake new file mode 100644 index 0000000..7bd604b --- /dev/null +++ b/cmake/logcoe.cmake @@ -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() \ No newline at end of file diff --git a/cmake/openal_config.cmake b/cmake/openal_soft.cmake similarity index 90% rename from cmake/openal_config.cmake rename to cmake/openal_soft.cmake index ca69c3e..f26495e 100644 --- a/cmake/openal_config.cmake +++ b/cmake/openal_soft.cmake @@ -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 diff --git a/cmake/soundcoe_config.cmake b/cmake/soundcoe_config.cmake index f68e2f1..775e0b4 100644 --- a/cmake/soundcoe_config.cmake +++ b/cmake/soundcoe_config.cmake @@ -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 \ No newline at end of file diff --git a/cmake/soundcoe_config.hpp.in b/cmake/soundcoe_config.hpp.in new file mode 100644 index 0000000..c8d7958 --- /dev/null +++ b/cmake/soundcoe_config.hpp.in @@ -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 + 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 \ No newline at end of file diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 69c4616..8db886f 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -3,12 +3,13 @@ add_library(soundcoe_headers INTERFACE) target_include_directories(soundcoe_headers INTERFACE $ - $ + $ + $ ) target_link_libraries(soundcoe_headers INTERFACE - logcoe + $<$:logcoe> ) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/soundcoe.hpp diff --git a/include/soundcoe/core/types.hpp b/include/soundcoe/core/types.hpp index b1953e4..7ab8827 100644 --- a/include/soundcoe/core/types.hpp +++ b/include/soundcoe/core/types.hpp @@ -1,10 +1,13 @@ #pragma once -#include #include #include #include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0091b6d..5705bcc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,8 +22,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") target_link_libraries(soundcoe PUBLIC soundcoe_headers - logcoe Threads::Threads + PRIVATE + $<$:logcoe> ) # Link with Emscripten's built-in OpenAL implementation target_link_options(soundcoe PRIVATE -lopenal) @@ -31,9 +32,9 @@ else() target_link_libraries(soundcoe PUBLIC soundcoe_headers - logcoe Threads::Threads PRIVATE OpenAL + $<$:logcoe> ) endif() \ No newline at end of file diff --git a/src/core/audio_context.cpp b/src/core/audio_context.cpp index 353936c..de70430 100644 --- a/src/core/audio_context.cpp +++ b/src/core/audio_context.cpp @@ -1,7 +1,10 @@ #include #include -#include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { diff --git a/src/core/error_handler.cpp b/src/core/error_handler.cpp index 7baf86a..d00e7f8 100644 --- a/src/core/error_handler.cpp +++ b/src/core/error_handler.cpp @@ -1,8 +1,11 @@ #include -#include #include #include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { diff --git a/src/playback/sound_manager.cpp b/src/playback/sound_manager.cpp index 0830402..ea16caa 100644 --- a/src/playback/sound_manager.cpp +++ b/src/playback/sound_manager.cpp @@ -1,10 +1,13 @@ #include #include #include -#include #include #include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { diff --git a/src/resources/audio_data.cpp b/src/resources/audio_data.cpp index f7678a6..c7e8680 100644 --- a/src/resources/audio_data.cpp +++ b/src/resources/audio_data.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #define DR_WAV_IMPLEMENTATION @@ -9,6 +8,11 @@ #include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif + namespace soundcoe { namespace detail diff --git a/src/resources/resource_manager.cpp b/src/resources/resource_manager.cpp index 86db6d8..fe1a6e8 100644 --- a/src/resources/resource_manager.cpp +++ b/src/resources/resource_manager.cpp @@ -1,8 +1,11 @@ #include #include #include -#include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { @@ -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) diff --git a/src/resources/sound_buffer.cpp b/src/resources/sound_buffer.cpp index 49394c6..5c88e32 100644 --- a/src/resources/sound_buffer.cpp +++ b/src/resources/sound_buffer.cpp @@ -2,11 +2,14 @@ #include #include #include -#include #include #include #include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { diff --git a/src/resources/sound_source.cpp b/src/resources/sound_source.cpp index fbc3bc0..e93f0b2 100644 --- a/src/resources/sound_source.cpp +++ b/src/resources/sound_source.cpp @@ -1,7 +1,10 @@ #include #include #include +#include +#if SOUNDCOE_USE_LOGCOE #include +#endif namespace soundcoe { diff --git a/src/soundcoe.cpp b/src/soundcoe.cpp index d09510a..239d555 100644 --- a/src/soundcoe.cpp +++ b/src/soundcoe.cpp @@ -1,7 +1,10 @@ #include #include -#include #include +#include +#if SOUNDCOE_USE_LOGCOE +#include +#endif namespace soundcoe { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e757f9e..f2ba78b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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)