Add spdlog dependency and Debug class
This commit is contained in:
@@ -4,35 +4,59 @@
|
||||
find_package(Vulkan REQUIRED)
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
spdlog
|
||||
GIT_REPOSITORY https://github.com/gabime/spdlog.git
|
||||
GIT_TAG f355b3d58f7067eee1706ff3c801c2361011f3d5 # v1.15.1
|
||||
FIND_PACKAGE_ARGS NAMES spdlog
|
||||
)
|
||||
FetchContent_MakeAvailable(spdlog)
|
||||
|
||||
set(ENGINE_SRC
|
||||
core/debug.cpp
|
||||
drivers/vulkan/render_driver.cpp
|
||||
render/renderer.cpp
|
||||
)
|
||||
|
||||
list(TRANSFORM ENGINE_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
set(ENGINE_INCLUDES_PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${Vulkan_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(ENGINE_LIBS
|
||||
set(ENGINE_INCLUDES_PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${spdlog_INCLUDE_DIRS}
|
||||
)
|
||||
set(ENGINE_LIBS_PRIVATE
|
||||
Vulkan::Vulkan
|
||||
)
|
||||
set(ENGINE_LIBS_PUBLIC
|
||||
spdlog::spdlog
|
||||
)
|
||||
|
||||
if (NOVA_ENGINE_SHARED)
|
||||
add_library(nova SHARED ${ENGINE_SRC})
|
||||
target_include_directories(nova
|
||||
PUBLIC ${ENGINE_INCLUDES_PUBLIC}
|
||||
PRIVATE ${ENGINE_INCLUDES_PRIVATE}
|
||||
)
|
||||
target_link_libraries(nova
|
||||
PUBLIC ${ENGINE_LIBS_PUBLIC}
|
||||
PRIVATE ${ENGINE_LIBS_PRIVATE}
|
||||
)
|
||||
target_compile_definitions(nova PRIVATE
|
||||
NOVA_DLL_EXPORT
|
||||
)
|
||||
target_link_libraries(nova PRIVATE
|
||||
${ENGINE_LIBS}
|
||||
)
|
||||
endif ()
|
||||
if (NOVA_ENGINE_STATIC)
|
||||
add_library(nova_static STATIC ${ENGINE_SRC})
|
||||
target_link_libraries(nova_static PRIVATE
|
||||
${ENGINE_LIBS}
|
||||
target_include_directories(nova_static PUBLIC
|
||||
PUBLIC ${ENGINE_INCLUDES_PUBLIC}
|
||||
PRIVATE ${ENGINE_INCLUDES_PRIVATE}
|
||||
)
|
||||
target_link_libraries(nova_static PUBLIC
|
||||
PUBLIC ${ENGINE_LIBS_PUBLIC}
|
||||
PRIVATE ${ENGINE_LIBS_PRIVATE}
|
||||
)
|
||||
endif ()
|
||||
|
||||
66
engine/include/nova/core/debug.h
Normal file
66
engine/include/nova/core/debug.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/api.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define NOVA_FUNC_NAME __FUNCTION__
|
||||
#else
|
||||
#define NOVA_FUNC_NAME __PRETTY_FUNCTION__
|
||||
#endif
|
||||
|
||||
namespace Nova {
|
||||
namespace Internals {
|
||||
NOVA_API void _assert_fail(std::string_view assertion, std::string_view file, std::string_view func, int line);
|
||||
|
||||
consteval std::string_view _format_func_name(const std::string_view name) {
|
||||
const auto start = name.find_first_of(' ') + 1;
|
||||
const auto end = name.find_first_of('(');
|
||||
return name.substr(start, end - start);
|
||||
}
|
||||
} // namespace Internals
|
||||
|
||||
class NOVA_API Debug {
|
||||
public:
|
||||
static std::shared_ptr<spdlog::logger> get_logger();
|
||||
static bool is_debug();
|
||||
|
||||
template<typename... Args>
|
||||
static void log(spdlog::format_string_t<Args...> fmt, Args&&... args) {
|
||||
get_logger()->info(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static void log_warning(spdlog::format_string_t<Args...> fmt, Args&&... args) {
|
||||
get_logger()->warn(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static void log_error(spdlog::format_string_t<Args...> fmt, Args&&... args) {
|
||||
get_logger()->error(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
} // namespace Nova
|
||||
|
||||
#define NOVA_LOG(...) ::Nova::Debug::get_logger()->info(__VA_ARGS__)
|
||||
#define NOVA_WARN(...) ::Nova::Debug::get_logger()->warn(__VA_ARGS__)
|
||||
#define NOVA_ERROR(...) ::Nova::Debug::get_logger()->error(__VA_ARGS__)
|
||||
#define NOVA_CRITICAL(...) ::Nova::Debug::get_logger()->critical(__VA_ARGS__)
|
||||
#define NOVA_DEBUG(...) ::Nova::Debug::get_logger()->debug(__VA_ARGS__)
|
||||
#define NOVA_TRACE(...) ::Nova::Debug::get_logger()->trace(__VA_ARGS__)
|
||||
|
||||
#define NOVA_AUTO_TRACE() NOVA_TRACE("{}()", ::Nova::Internals::_format_func_name(NOVA_FUNC_NAME))
|
||||
|
||||
#define NOVA_ASSERT(expr) \
|
||||
(static_cast<bool>(expr) \
|
||||
? static_cast<void>(0) \
|
||||
: ::Nova::Internals:: \
|
||||
_assert_fail(#expr, __FILE__, ::Nova::Internals::_format_func_name(NOVA_FUNC_NAME), __LINE__))
|
||||
39
engine/src/core/debug.cpp
Normal file
39
engine/src/core/debug.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <nova/core/debug.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
|
||||
using namespace Nova;
|
||||
|
||||
std::shared_ptr<spdlog::logger> Debug::get_logger() {
|
||||
static std::shared_ptr<spdlog::logger> s_logger;
|
||||
if (!s_logger) {
|
||||
s_logger = spdlog::stdout_color_mt("NOVA");
|
||||
s_logger->set_level(spdlog::level::trace);
|
||||
s_logger->set_pattern("%^[%T] %n: %v%$");
|
||||
}
|
||||
return s_logger;
|
||||
}
|
||||
|
||||
bool Debug::is_debug() {
|
||||
#ifdef NDEBUG
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Internals::_assert_fail(std::string_view assertion, std::string_view file, std::string_view func, int line) {
|
||||
Debug::get_logger()->critical(
|
||||
"ASSERTION FAILED\n Assertion: \"{}\"\n File: \"{}\" (line {})\n Function: {}()",
|
||||
assertion,
|
||||
file,
|
||||
line,
|
||||
func
|
||||
);
|
||||
std::abort();
|
||||
}
|
||||
Reference in New Issue
Block a user