Skip to content

Commit

Permalink
Merge branch 'master' into chris_async_networking
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-plusplus committed Mar 25, 2024
2 parents 573d1ab + 5d4db0d commit c13965e
Show file tree
Hide file tree
Showing 19 changed files with 382 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
with:
version: 12
version: 13
platform: x64

- name: Conan version
Expand Down Expand Up @@ -64,6 +64,6 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build
run: ./test_archimedes
run: ./archimedes_tests


4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ build
_deps
CMakeFiles/
Makefile
*.cmake
CMakeCache.txt
model.txt
linux_build/
Expand All @@ -21,5 +20,6 @@ Testing/
.vscode
CMakeUserPresets.json
compile_commands.json
conan_files/
cmake/conan_files/
CMakeSettings.json
cmake-build-*
45 changes: 13 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,21 @@ project(
)

set(CMAKE_CXX_STANDARD 20)
if (MSVC)
add_compile_options("/Zc:__cplusplus")
include("conan_files/conan_toolchain.cmake") # idk, but works xd
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/conan_files)
include_directories(${CMAKE_INCLUDE_PATH})
endif (MSVC)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

add_library(${PROJECT_NAME})
file(GLOB_RECURSE ARCHIMEDES_SOURCE src/*.cpp)
target_sources(${PROJECT_NAME} PRIVATE ${ARCHIMEDES_SOURCE})
include("cmake/build_mode.cmake")
include("cmake/os.cmake")
include("cmake/msvc.cmake")
include("cmake/defines.cmake")

find_package(stb CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)
find_package(assimp CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(glfw3 3.3 CONFIG REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC include ${glad_INCLUDE_DIR} ${assimp_INCLUDE_DIR}
${GTest_INCLUDE_DIR} ${glm_INCLUDE_DIR} ${glfw3_INCLUDE_DIR} ${spdlog_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE glfw fmt::fmt glad::glad assimp::assimp spdlog::spdlog stb::stb)
# uncomment below to force conan reinstallation
#set(ARCHIMEDES_FORCE_CONAN_INSTALL TRUE)
include("cmake/conan.cmake")

enable_testing()
set(TESTS_NAME test_${PROJECT_NAME})
file(GLOB_RECURSE TEST_ARCHIMEDES_SOURCE tests/**.cpp)
add_executable(${TESTS_NAME})
target_compile_definitions(${TESTS_NAME} PUBLIC -DSPDLOG_FMT_EXTERNAL)
target_sources(${TESTS_NAME} PRIVATE ${TEST_ARCHIMEDES_SOURCE})
target_include_directories(${TESTS_NAME} PRIVATE include)
target_link_libraries(${TESTS_NAME} PRIVATE ${PROJECT_NAME} fmt::fmt gtest::gtest GTest::gtest_main spdlog::spdlog stb::stb)
include("cmake/library.cmake")

add_executable(${PROJECT_NAME}_bin archimedes_bin/main.cpp)
target_compile_definitions(${PROJECT_NAME}_bin PUBLIC -DSPDLOG_FMT_EXTERNAL)
target_compile_definitions(${PROJECT_NAME} PUBLIC -DSPDLOG_FMT_EXTERNAL)
target_include_directories(${PROJECT_NAME}_bin PUBLIC include)
target_link_libraries(${PROJECT_NAME}_bin PRIVATE ${PROJECT_NAME} spdlog::spdlog fmt::fmt)
# CMake targets
file(GLOB_RECURSE ARCHIMEDES_TARGETS cmake/targets/*.cmake)
foreach(ARCHIMEDES_TARGET ${ARCHIMEDES_TARGETS})
include(${ARCHIMEDES_TARGET})
endforeach()
14 changes: 12 additions & 2 deletions archimedes_bin/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include <engine.h>
#include <spdlog/spdlog.h>
#include <Logger.h>

int main() {
spdlog::set_level(spdlog::level::debug);
arch::Logger::init(arch::LogLevel::trace);

arch::Logger::trace("Hello, {}!", "World");
arch::Logger::debug("Hello, {}!", "World");
arch::Logger::info("Hello, {}!", "World");
arch::Logger::warn("Hello, {}!", "World");
arch::Logger::error("Hello, {}!", "World");
arch::Logger::critical("Hello, {}!", "World");

arch::Logger::log(arch::LogLevel::info, "Info log");

arch::EngineConfig config {
600, 480, "Archimedes Test", glm::vec4(0, 0, 0, 0)
};
Expand Down
27 changes: 27 additions & 0 deletions cmake/build_mode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include_guard()

# check build type
if(
"${CMAKE_CONFIGURATION_TYPES}" STREQUAL Debug
OR "${CMAKE_BUILD_TYPE}" STREQUAL Debug
OR "${CMAKE_CONFIGURATION_TYPES}" STREQUAL "RelWithDebInfo"
OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo"
)
set(ARCHIMEDES_DEBUG TRUE)
set(ARCHIMEDES_RELEASE FALSE)

set(ARCHIMEDES_BUILD_TYPE "Debug")

add_compile_definitions(ARCHIMEDES_DEBUG=1)
add_compile_definitions(ARCHIMEDES_RELEASE=0)
else()
set(ARCHIMEDES_DEBUG FALSE)
set(ARCHIMEDES_RELEASE TRUE)

set(ARCHIMEDES_BUILD_TYPE "Release")

add_compile_definitions(ARCHIMEDES_DEBUG=0)
add_compile_definitions(ARCHIMEDES_RELEASE=1)
endif()

message(STATUS "Build mode: ${ARCHIMEDES_BUILD_TYPE}")
60 changes: 60 additions & 0 deletions cmake/conan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
include_guard()

include("${PROJECT_SOURCE_DIR}/cmake/os.cmake")

# check if conan is installed
execute_process(
COMMAND "conan" "--version"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CONAN_CHECK_OUT
)
if(NOT CONAN_CHECK_OUT MATCHES ".?Conan.?")
message(FATAL_ERROR "Conan not found")
else()
message(STATUS "Conan present")
endif()

# check for conan files
if(ARCHIMEDES_FORCE_CONAN_INSTALL OR NOT EXISTS "${PROJECT_SOURCE_DIR}/cmake/conan_files/${ARCHIMEDES_BUILD_TYPE}/conan_toolchain.cmake")
if(ARCHIMEDES_FORCE_CONAN_INSTALL)
message(STATUS "Forced Conan configuration for ${ARCHIMEDES_BUILD_TYPE} mode")
else()
message(STATUS "Conan files not found for ${ARCHIMEDES_BUILD_TYPE} mode, configuring conan for ${ARCHIMEDES_BUILD_TYPE} mode")
endif()

file(MAKE_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/conan_files/${ARCHIMEDES_BUILD_TYPE}/")

# option only for MSCV
if(MSVC)
set(ARCHIMEDES_CONAN_COMPILER_RUNTIME_TYPE "-s:b compiler.runtime_type=${ARCHIMEDES_BUILD_TYPE} -s:h compiler.runtime_type=${ARCHIMEDES_BUILD_TYPE}")
endif()

# install conan requirements
execute_process(
COMMAND conan install . -s:b build_type=${ARCHIMEDES_BUILD_TYPE} -s:b compiler.cppstd=20 -s:h build_type=${ARCHIMEDES_BUILD_TYPE} -s:h compiler.cppstd=20 ${ARCHIMEDES_CONAN_INSTALL_RUNTIME_TYPE} ${ARCHIMEDES_CONAN_PACKAGE_MANAGER} -of=cmake/conan_files/${ARCHIMEDES_BUILD_TYPE} --build=missing
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE ARCHIMEDES_CONAN_INSTALL_OUTPUT
RESULT_VARIABLE ARCHIMEDES_CONAN_INSTALL_RESULT
)

# check conan result
if(NOT ${ARCHIMEDES_CONAN_INSTALL_RESULT} EQUAL 0)
file(REMOVE_RECURSE "${PROJECT_SOURCE_DIR}/cmake/conan_files/${ARCHIMEDES_BUILD_TYPE}/")
message(FATAL_ERROR "Conan installation failed")
else()
message(STATUS "Conan installation succeded")
endif()
else()
message(STATUS "Conan files found for ${ARCHIMEDES_BUILD_TYPE} mode")
endif()

# manual include conan toolchain
include("${PROJECT_SOURCE_DIR}/cmake/conan_files/${ARCHIMEDES_BUILD_TYPE}/conan_toolchain.cmake")
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/conan_files/${ARCHIMEDES_BUILD_TYPE})

# includes from conan
include_directories(${CMAKE_INCLUDE_PATH})

# automatic find_package()
include("${PROJECT_SOURCE_DIR}/cmake/conan_files/${ARCHIMEDES_BUILD_TYPE}/conandeps_legacy.cmake")
list(APPEND ARCHIMEDES_LIBRARIES ${CONANDEPS_LEGACY})
1 change: 1 addition & 0 deletions cmake/defines.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include_guard()
14 changes: 14 additions & 0 deletions cmake/library.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include_guard()

include("${PROJECT_SOURCE_DIR}/cmake/conan.cmake")

add_library(${PROJECT_NAME})

include_directories(include)

# find source files
file(GLOB_RECURSE ARCHIMEDES_SOURCE src/**.cpp)
target_sources(${PROJECT_NAME} PUBLIC ${ARCHIMEDES_SOURCE})

# link conan libraries
target_link_libraries(${PROJECT_NAME} PUBLIC ${ARCHIMEDES_LIBRARIES})
8 changes: 8 additions & 0 deletions cmake/msvc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include_guard()

# msvc specific compile flags
if(MSVC)
add_compile_options("/Zc:__cplusplus")
add_compile_options("/Zc:preprocessor")
add_compile_options("/permissive-")
endif()
23 changes: 23 additions & 0 deletions cmake/os.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include_guard()

# check for OS
if(WIN32)
set(ARCHIMEDES_WINDOWS TRUE)
set(ARCHIMEDES_LINUX FALSE)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(ARCHIMEDES_WINDOWS FALSE)
set(ARCHIMEDES_LINUX TRUE)
endif()

# set user home directory
if(ARCHIMEDES_WINDOWS)
add_compile_definitions(ARCHIMEDES_WINDOWS=1)
add_compile_definitions(ARCHIMEDES_LINUX=0)

message(STATUS "OS: Windows")
elseif(ARCHIMEDES_LINUX)
add_compile_definitions(ARCHIMEDES_WINDOWS=0)
add_compile_definitions(ARCHIMEDES_LINUX=1)

message(STATUS "OS: Linux")
endif()
6 changes: 6 additions & 0 deletions cmake/targets/archimedes_bin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include_guard()

include("${PROJECT_SOURCE_DIR}/cmake/library.cmake")

add_executable(${PROJECT_NAME}_bin archimedes_bin/main.cpp)
target_link_libraries(${PROJECT_NAME}_bin PUBLIC ${PROJECT_NAME})
9 changes: 9 additions & 0 deletions cmake/targets/tests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include_guard()

include("${PROJECT_SOURCE_DIR}/cmake/library.cmake")

set(ARCHIMEDES_TEST "${PROJECT_NAME}_tests")
add_executable(${ARCHIMEDES_TEST})
file(GLOB_RECURSE ARCHIMEDES_TEST_SOURCE tests/**.cpp)
target_sources(${ARCHIMEDES_TEST} PUBLIC ${ARCHIMEDES_TEST_SOURCE})
target_link_libraries(${ARCHIMEDES_TEST} PUBLIC ${PROJECT_NAME})
5 changes: 4 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from conan import ConanFile
from conan.tools.microsoft.visual import is_msvc

class Archimedes(ConanFile):
name = "Archimedes"
Expand All @@ -9,7 +10,7 @@ def requirements(self):
self.requires("glfw/3.3.8")
self.requires("glm/0.9.9.8")
self.requires("assimp/5.2.2")
self.requires("spdlog/1.11.0")
self.requires("spdlog/1.12.0")
self.requires("gtest/1.13.0")
self.requires("stb/cci.20220909")
self.requires("draco/1.5.6", override=True)
Expand All @@ -20,5 +21,7 @@ def configure(self):
self.options["glad/0.1.36"].spec = "gl"
self.options["glad/0.1.36"].no_loader = False

if is_msvc(self, True):
self.options["spdlog/1.12.0"].use_std_fmt = True

generators = "CMakeDeps", "CMakeToolchain"
91 changes: 91 additions & 0 deletions include/Logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#pragma once
#include <spdlog/spdlog.h>

#include <source_location>

namespace arch {

/// @brief Logging level for Logger to indicate how important the message is.
///
enum class LogLevel
{
none = -1,
/// @brief Detailed trace information ().
trace,
/// @brief Debugging information.
debug,
/// @brief General information.
info,
/// @brief Information representing a minor problem that has occurred.
warn,
/// @brief Information representing a serious problem that has occurred.
error,
/// @brief Information representing a critical problem that has occurred.s
critical,
};

/// @brief Implementation details.
namespace _details {

template <typename... Args>
struct UniversalLogger;

template <LogLevel Level, typename... Args>
struct LeveledLogger;

}

/// @brief Main static Logger class for logging messages.
///
class Logger {
template <typename... Args>
friend struct _details::UniversalLogger;

template <LogLevel Level, typename... Args>
friend struct _details::LeveledLogger;
public:

/// @brief Initializes the logger.
/// @param logLevel minimum level of log messages to be logged. (All messages with lower level will be ignored)
/// @param name name of the logger. Used for identifying the logger.
static void init(LogLevel logLevel, const std::string& name = "Logger");

/// @brief Universal logger for logging messages using runtime @enum LogLevel.
template <typename... Args>
using log = _details::UniversalLogger<Args...>;

/// @brief Fast way of logging messages at @enum LogLevel::trace.
template <typename... Args>
using trace = _details::LeveledLogger<LogLevel::trace, Args...>;

/// @brief Fast way of logging messages at @enum LogLevel::debug.
template <typename... Args>
using debug = _details::LeveledLogger<LogLevel::debug, Args...>;

/// @brief Fast way of logging messages at @enum LogLevel::info.
template<typename... Args>
using info = _details::LeveledLogger<LogLevel::info, Args...>;

/// @brief Fast way of logging messages at \enum LogLevel::warn.
template<typename... Args>
using warn = _details::LeveledLogger<LogLevel::warn, Args...>;

/// @brief Fast way of logging messages at \enum LogLevel::error.
template<typename... Args>
using error = _details::LeveledLogger<LogLevel::error, Args...>;

/// @brief Fast way of logging messages at \enum LogLevel::critical.
template<typename... Args>
using critical = _details::LeveledLogger<LogLevel::critical, Args...>;

private:

template <typename... Args>
static void _log_impl(LogLevel level, std::source_location loc, spdlog::format_string_t<Args...> fmt, Args&&... args);

static std::shared_ptr<spdlog::logger> s_logger;
};

}

#include "Logger.hpp"
Loading

0 comments on commit c13965e

Please sign in to comment.