Project setup
This commit is contained in:
18
examples/basicGLFWWindow/CMakeLists.txt
Normal file
18
examples/basicGLFWWindow/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(oatmeal)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
add_executable(basicGLFWWindow "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
|
||||
target_include_directories(basicGLFWWindow PRIVATE oatmeal SharedUtils)
|
||||
target_link_libraries(basicGLFWWindow oatmeal SharedUtils)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set_target_properties(basicGLFWWindow PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Debug/")
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set_target_properties(basicGLFWWindow PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Release/")
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
set_target_properties(basicGLFWWindow PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Relwithdeb/")
|
||||
endif()
|
||||
|
||||
10
examples/basicGLFWWindow/main.cpp
Normal file
10
examples/basicGLFWWindow/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "shared/logger.h"
|
||||
|
||||
int main() {
|
||||
OatmealUtils::initLogging();
|
||||
OatmealUtils::createLogger("window", nullptr);
|
||||
|
||||
OatmealUtils::get("window")->info("Test");
|
||||
|
||||
return 0;
|
||||
}
|
||||
18
examples/logging/CMakeLists.txt
Normal file
18
examples/logging/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(oatmeal)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
add_executable(logging "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
|
||||
target_include_directories(logging PRIVATE oatmeal SharedUtils)
|
||||
target_link_libraries(logging oatmeal SharedUtils)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set_target_properties(logging PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Debug/")
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set_target_properties(logging PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Release/")
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
set_target_properties(logging PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Relwithdeb/")
|
||||
endif()
|
||||
|
||||
17
examples/logging/main.cpp
Normal file
17
examples/logging/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <cstdint>
|
||||
#include "shared/logger.h"
|
||||
|
||||
int main() {
|
||||
OatmealUtils::initLogging();
|
||||
OatmealUtils::createLogger("logger", nullptr);
|
||||
|
||||
OatmealUtils::get("logger")->debug("This is a debug message!");
|
||||
OatmealUtils::get("logger")->info("This is an info message!");
|
||||
OatmealUtils::get("logger")->warn("This is a warning message!");
|
||||
OatmealUtils::get("logger")->critical("This is a critical message!");
|
||||
uint32_t a = 5;
|
||||
std::string b = "Test string arg!";
|
||||
OatmealUtils::get("logger")->info("String arg: {} uint32_t args: {}", b, a);
|
||||
|
||||
return 0;
|
||||
}
|
||||
20
examples/shared/CMakeLists.txt
Normal file
20
examples/shared/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(oatmeal)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
CPMAddPackage(
|
||||
URI "gh:gabime/spdlog@1.17.0"
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/shared/*.cpp")
|
||||
file(GLOB_RECURSE HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/shared/*.h")
|
||||
add_library(SharedUtils STATIC ${SRC_FILES} ${HEADER_FILES})
|
||||
|
||||
target_include_directories(SharedUtils PUBLIC
|
||||
${spdlog_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(SharedUtils PUBLIC
|
||||
spdlog
|
||||
)
|
||||
48
examples/shared/shared/logger.cpp
Normal file
48
examples/shared/shared/logger.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "logger.h"
|
||||
#include <memory>
|
||||
#include <spdlog/async_logger.h>
|
||||
#include <spdlog/common.h>
|
||||
#include "spdlog/async.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
namespace OatmealUtils {
|
||||
|
||||
void initLogging() {
|
||||
spdlog::init_thread_pool(8192, 1);
|
||||
spdlog::flush_every(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
void createLogger(const char *name, const char *filename) {
|
||||
std::vector<spdlog::sink_ptr> sinks{};
|
||||
|
||||
const auto stdoutSink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
|
||||
stdoutSink->set_level(spdlog::level::debug);
|
||||
stdoutSink->set_pattern("%^[%D %r %z] [%n] [%l] [thread %t] %v%$");
|
||||
sinks.emplace_back(stdoutSink);
|
||||
|
||||
if (filename != nullptr) {
|
||||
const auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename);
|
||||
fileSink->set_level(spdlog::level::debug);
|
||||
fileSink->set_pattern("%^[%D %r %z] [%n] [%l] [thread %t] %v%$");
|
||||
sinks.emplace_back(fileSink);
|
||||
}
|
||||
|
||||
const auto logger = std::make_shared<spdlog::async_logger>(
|
||||
name, sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
|
||||
|
||||
logger->flush_on(spdlog::level::warn);
|
||||
#ifndef NDEBUG
|
||||
logger->set_level(spdlog::level::debug);
|
||||
#else
|
||||
logger->set_level(spdlog::level::info);
|
||||
#endif // !NDEBUG
|
||||
|
||||
spdlog::register_logger(logger);
|
||||
}
|
||||
|
||||
void createLogger(std::string name, std::string filename) { createLogger(name.c_str(), filename.c_str()); }
|
||||
std::shared_ptr<logger> get(const char *name) { return spdlog::get(name); }
|
||||
std::shared_ptr<logger> get(std::string name) { return spdlog::get(name); }
|
||||
} // namespace OatmealUtils
|
||||
20
examples/shared/shared/logger.h
Normal file
20
examples/shared/shared/logger.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef OATMEAL_LOGGER
|
||||
#define OATMEAL_LOGGER
|
||||
|
||||
#include <memory>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "string"
|
||||
|
||||
namespace OatmealUtils {
|
||||
|
||||
using logger = spdlog::logger;
|
||||
|
||||
void initLogging();
|
||||
void createLogger(const char *name, const char *filename);
|
||||
void createLogger(std::string name, std::string filename);
|
||||
std::shared_ptr<logger> get(const char *name);
|
||||
std::shared_ptr<logger> get(std::string name);
|
||||
|
||||
} // namespace OatmealUtils
|
||||
|
||||
#endif // !OATMEAL_LOGGER
|
||||
Reference in New Issue
Block a user