diff --git a/CMakeLists.txt b/CMakeLists.txt index ad8603b..7479234 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + function(toAbsolutePath SETVAR PATHS) set(PATHS ${PATHS} ${ARGN}) set(RET_VAL "") @@ -31,6 +34,7 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") set(NB_LOGGING ON) set(NB_BUILD_TESTS ON) set(NB_BUILD_DOCS ON) + set(NBENGINE_INSTALL ON) add_compile_definitions(_NB_BUILD_DEBUG) endif() @@ -55,7 +59,6 @@ if(NB_BUILD_TESTS) FetchContent_MakeAvailable(gtest) endif() set(GTEST_COLOR ON) - set(GLFW_BUILD_TESTS ON CACHE BOOL "" FORCE) endif() if (NB_LOGGING) @@ -70,13 +73,7 @@ elseif (NB_TARGET_LINUX) add_compile_definitions(_NB_TARGET_LINUX) endif() -# External Dep paths -set(GLFW_PATH ../glfw/) -set(GLAD_PATH ../glad/) -set(STBIMAGE_PATH ../stbi_image) -get_filename_component(GLFW_PATH ${GLFW_PATH} ABSOLUTE) -get_filename_component(GLAD_PATH ${GLAD_PATH} ABSOLUTE) -get_filename_component(STBIMAGE_PATH ${STBIMAGE_PATH} ABSOLUTE) +get_filename_component(NBENGINE_ROOT ./ ABSOLUTE) add_subdirectory(./engine) @@ -86,3 +83,23 @@ set(NB_REBUILD_DOCS) if (NB_BUILD_DOCS) add_subdirectory(./docs) endif() + +if (NBENGINE_INSTALL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + configure_package_config_file( + "NBEngineConfig.cmake.in" + "NBEngineConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake + PATH_VARS CMAKE_INSTALL_LIBDIR + ) + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/NBEngineConfigVersion.cmake" + COMPATIBILITY AnyNewerVersion + ) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/NBEngineConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/NBEngineConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" + ) +endif() diff --git a/NBEngineConfig.cmake.in b/NBEngineConfig.cmake.in new file mode 100644 index 0000000..fa38829 --- /dev/null +++ b/NBEngineConfig.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ +set(NBENGINE_PACKAGES + NBCore + NBGraphics +) +foreach(NBENGINE_LIB ${NBENGINE_PACKAGES}) + include("${CMAKE_CURRENT_LIST_DIR}/${NBENGINE_LIB}Config.cmake") +endforeach() \ No newline at end of file diff --git a/awesomeface.png b/awesomeface.png new file mode 100644 index 0000000..9840caf Binary files /dev/null and b/awesomeface.png differ diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 401f9c9..0a2e3b2 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1,6 +1,8 @@ -include_directories(./.) - add_subdirectory(./NBCore) + +get_target_property(NBCORE_INTERFACE_INCLUDES NBCore INTERFACE_INCLUDE_DIRECTORIES) +include_directories(${NBCORE_INTERFACE_INCLUDES}) + add_subdirectory(./NBEvents) add_subdirectory(./NBGraphics) @@ -10,7 +12,6 @@ if (NB_CORE_SOURCE OR NB_EVENTS_SOURCE OR NB_GRAPHICS_SOURCE) set(NB_SOURCE_FILES ${NB_SOURCE_FILES} PARENT_SCOPE) endif() - if (NB_CORE_INCLUDE OR NB_EVENTS_INCLUDE OR NB_GRAPHICS_INCLUDE) set(NB_INCLUDE_FILES "") list(APPEND NB_INCLUDE_FILES ${NB_CORE_INCLUDE} ${NB_GRAPHICS_INCLUDE} ${NB_EVENTS_INCLUDE}) diff --git a/engine/NBCore/CMakeLists.txt b/engine/NBCore/CMakeLists.txt index 76e9249..ad44959 100644 --- a/engine/NBCore/CMakeLists.txt +++ b/engine/NBCore/CMakeLists.txt @@ -1,3 +1,6 @@ +cmake_minimum_required(VERSION 3.10) +project(NBCore VERSION 0.1) + toAbsolutePath(NB_CORE_SOURCE ./src/ErrorsImpl.cpp ./src/Logger.cpp @@ -5,27 +8,64 @@ toAbsolutePath(NB_CORE_SOURCE ./src/StringUtils.cpp ./src/Utils.cpp ) - toAbsolutePath(NB_CORE_INCLUDE - ./ANSITerm.hpp - ./DataSink.hpp - ./Errors.hpp - ./ErrorsImpl.hpp - ./Logger.hpp - ./Processes.hpp - ./StringUtils.hpp - ./ThreadsafeQueue.hpp - ./Types.hpp - ./TypeTraits.hpp - ./Utils.hpp + ./include/NBCore/ANSITerm.hpp + ./include/NBCore/DataSink.hpp + ./include/NBCore/Errors.hpp + ./include/NBCore/ErrorsImpl.hpp + ./include/NBCore/Logger.hpp + ./include/NBCore/Processes.hpp + ./include/NBCore/StringUtils.hpp + ./include/NBCore/ThreadsafeQueue.hpp + ./include/NBCore/Types.hpp + ./include/NBCore/TypeTraits.hpp + ./include/NBCore/Utils.hpp ) set(NB_CORE_SOURCE ${NB_CORE_SOURCE} PARENT_SCOPE) set(NB_CORE_INCLUDE ${NB_CORE_INCLUDE} PARENT_SCOPE) add_library(NBCore ${NB_CORE_SOURCE}) +add_library(NBEngine::Core ALIAS NBCore) +target_include_directories(NBCore + PUBLIC "$" + PUBLIC "$" +) -target_include_directories(NBCore PUBLIC ./.) +if (NBENGINE_INSTALL) + message("Installing NBCore to ${CMAKE_INSTALL_PREFIX}") + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + install( + TARGETS NBCore + EXPORT NBCoreTargets + ) + install( + DIRECTORY "${PROJECT_SOURCE_DIR}/include/NBCore" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" + ) + install( + EXPORT NBCoreTargets + DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake + NAMESPACE NBEngine:: + ) + configure_package_config_file( + "NBCoreConfig.cmake.in" + "NBCoreConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake + PATH_VARS CMAKE_INSTALL_LIBDIR + ) + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/NBCoreConfigVersion.cmake" + COMPATIBILITY AnyNewerVersion + ) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/NBCoreConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/NBCoreConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" + ) +endif() if (NB_BUILD_TESTS) add_subdirectory(./tests) diff --git a/engine/NBCore/NBCoreConfig.cmake.in b/engine/NBCore/NBCoreConfig.cmake.in new file mode 100644 index 0000000..0f4863d --- /dev/null +++ b/engine/NBCore/NBCoreConfig.cmake.in @@ -0,0 +1,2 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/NBCoreTargets.cmake") \ No newline at end of file diff --git a/engine/NBCore/ANSITerm.hpp b/engine/NBCore/include/NBCore/ANSITerm.hpp similarity index 100% rename from engine/NBCore/ANSITerm.hpp rename to engine/NBCore/include/NBCore/ANSITerm.hpp diff --git a/engine/NBCore/DataSink.hpp b/engine/NBCore/include/NBCore/DataSink.hpp similarity index 98% rename from engine/NBCore/DataSink.hpp rename to engine/NBCore/include/NBCore/DataSink.hpp index 155c48a..06d3903 100644 --- a/engine/NBCore/DataSink.hpp +++ b/engine/NBCore/include/NBCore/DataSink.hpp @@ -5,7 +5,7 @@ #include #include -#include "ThreadSafeQueue.hpp" +#include namespace nb { diff --git a/engine/NBCore/Errors.hpp b/engine/NBCore/include/NBCore/Errors.hpp similarity index 93% rename from engine/NBCore/Errors.hpp rename to engine/NBCore/include/NBCore/Errors.hpp index 8a6db60..97649b8 100644 --- a/engine/NBCore/Errors.hpp +++ b/engine/NBCore/include/NBCore/Errors.hpp @@ -2,8 +2,8 @@ #ifndef _NB_ERROR #define _NB_ERROR -#include "ErrorsImpl.hpp" -#include "Logger.hpp" +#include +#include namespace nb { diff --git a/engine/NBCore/ErrorsImpl.hpp b/engine/NBCore/include/NBCore/ErrorsImpl.hpp similarity index 84% rename from engine/NBCore/ErrorsImpl.hpp rename to engine/NBCore/include/NBCore/ErrorsImpl.hpp index eecc50b..4aef324 100644 --- a/engine/NBCore/ErrorsImpl.hpp +++ b/engine/NBCore/include/NBCore/ErrorsImpl.hpp @@ -8,7 +8,7 @@ #include #include -#include "StringUtils.hpp" +#include namespace nb { @@ -25,14 +25,15 @@ class ErrorBase { ErrorBase(const ErrorBase&) = default; ErrorBase(const std::exception&) noexcept; + ErrorBase(const std::string&) noexcept; virtual std::string what() const noexcept { std::string ret = msg; if (trace) { std::string trace_msg = msg; - ret += nb::NEWLINE + indent_strblock( + ret += NEWLINE + indent_strblock( trace_msg, - nb::TABOVER, - nb::TABOVER+"Trace: " + TABOVER, + TABOVER+"Trace: " ); } return ret; @@ -52,7 +53,7 @@ class ErrorBase { {} }; -template +template class Error : public ErrorBase { private: void inline check_asserts() { @@ -132,39 +133,43 @@ class Error : public ErrorBase { using ErrorBase::type; }; -class NBError : public Error { +template<> +class Error : public Error> { protected: - using Base = Error; + using Base = Error>; public: + using Base::what; + using Base::code; + using Base::trace; enum Codes : unsigned int { STANDARD, UNDEFINED, INDEX_ERROR }; - - NBError(unsigned int code_=1) noexcept : Base(code_) {} - NBError(const std::exception& err) : Base( - STANDARD, - std::string(err.what()), - "std::exception", - nullptr - ) {} - - // fix - NBError(std::string msg_) noexcept : Base( - Codes::UNDEFINED, - msg_ - ) {} - inline static const std::string type = "nb::Error"; inline static const ErrorCodeMap ErrorMessages = { {STANDARD, "std::exception"}, {UNDEFINED, "Error"}, {INDEX_ERROR, "Indexing error"} }; + + Error(unsigned int code_=1) noexcept : Base(code_) {} + Error(const std::exception& err) : Base( + STANDARD, + std::string(err.what()), + "std::exception", + nullptr + ) {} + + Error(const std::string& msg_) noexcept : Base( + Codes::UNDEFINED, + msg_, + type, + nullptr + ) {} }; -// template -// Error(Args...) -> Error; +template +Error(Args...) -> Error; } // namespace nb diff --git a/engine/NBCore/Logger.hpp b/engine/NBCore/include/NBCore/Logger.hpp similarity index 91% rename from engine/NBCore/Logger.hpp rename to engine/NBCore/include/NBCore/Logger.hpp index f24181e..854564d 100644 --- a/engine/NBCore/Logger.hpp +++ b/engine/NBCore/include/NBCore/Logger.hpp @@ -8,11 +8,11 @@ #include #include -#include "DataSink.hpp" -#include "ErrorsImpl.hpp" -#include "Processes.hpp" -#include "ThreadSafeQueue.hpp" -#include "TypeTraits.hpp" +#include +#include +#include +#include +#include namespace nb { @@ -99,6 +99,14 @@ public: static_cast(this)->write_message(val, 0xFF, file, line); static_cast(this)->flush(); } + void error( + const std::string& val, + std::string file="", + unsigned int line=0 + ) { + static_cast(this)->write_message(Error(val), 0xFF, file, line); + static_cast(this)->flush(); + } protected: std::vector _ostream; diff --git a/engine/NBCore/Processes.hpp b/engine/NBCore/include/NBCore/Processes.hpp similarity index 100% rename from engine/NBCore/Processes.hpp rename to engine/NBCore/include/NBCore/Processes.hpp diff --git a/engine/NBCore/StringUtils.hpp b/engine/NBCore/include/NBCore/StringUtils.hpp similarity index 83% rename from engine/NBCore/StringUtils.hpp rename to engine/NBCore/include/NBCore/StringUtils.hpp index b8d9778..bd283f3 100644 --- a/engine/NBCore/StringUtils.hpp +++ b/engine/NBCore/include/NBCore/StringUtils.hpp @@ -6,17 +6,17 @@ #include #include -#include "TypeTraits.hpp" +#include namespace nb { #ifdef _NB_TARGET_WINDOWS - const std::string NEWLINE = "\n"; - const std::wstring WNEWLINE = L"\n"; + inline static const std::string NEWLINE = "\n"; + inline static const std::wstring WNEWLINE = L"\n"; #endif // _NB_TARGET_WINDOWS #ifdef _NB_TARGET_LINUX - const std::string NEWLINE = "\n"; - const std::wstring WNEWLINE = L"\n"; + inline const std::string NEWLINE = "\n"; + inline const std::wstring WNEWLINE = L"\n"; #endif // _NB_TARGET_LINUX const std::string TABOVER = " "; @@ -34,7 +34,7 @@ void stream(const Stream& s, Args&&... args) { } template -void term(Args&&... args) { stream(std::cout, args..., nb::NEWLINE); } +void term(Args&&... args) { stream(std::cout, args..., NEWLINE); } template void wterm(Args&&... args) { stream(std::wcout, args..., nb::WNEWLINE); } diff --git a/engine/NBCore/ThreadsafeQueue.hpp b/engine/NBCore/include/NBCore/ThreadsafeQueue.hpp similarity index 100% rename from engine/NBCore/ThreadsafeQueue.hpp rename to engine/NBCore/include/NBCore/ThreadsafeQueue.hpp diff --git a/engine/NBCore/TypeTraits.hpp b/engine/NBCore/include/NBCore/TypeTraits.hpp similarity index 100% rename from engine/NBCore/TypeTraits.hpp rename to engine/NBCore/include/NBCore/TypeTraits.hpp diff --git a/engine/NBCore/Utils.hpp b/engine/NBCore/include/NBCore/Utils.hpp similarity index 98% rename from engine/NBCore/Utils.hpp rename to engine/NBCore/include/NBCore/Utils.hpp index b704a86..f03761c 100644 --- a/engine/NBCore/Utils.hpp +++ b/engine/NBCore/include/NBCore/Utils.hpp @@ -5,7 +5,7 @@ #include #include -#include "Errors.hpp" +#include namespace nb { diff --git a/engine/NBCore/src/ErrorsImpl.cpp b/engine/NBCore/src/ErrorsImpl.cpp index 44bc1ad..c078af3 100644 --- a/engine/NBCore/src/ErrorsImpl.cpp +++ b/engine/NBCore/src/ErrorsImpl.cpp @@ -1,10 +1,10 @@ -#include "ErrorsImpl.hpp" +#include namespace nb { //ErrorBase:: ErrorBase::ErrorBase(const std::exception& exception_) noexcept -: ErrorBase(NBError(exception_)) {} +: ErrorBase(Error(exception_)) {} } // namespace nb diff --git a/engine/NBCore/src/Logger.cpp b/engine/NBCore/src/Logger.cpp index 70c8ff8..da963c0 100644 --- a/engine/NBCore/src/Logger.cpp +++ b/engine/NBCore/src/Logger.cpp @@ -1,7 +1,7 @@ #include -#include "Logger.hpp" -#include "StringUtils.hpp" +#include +#include namespace nb { diff --git a/engine/NBCore/src/Processes.cpp b/engine/NBCore/src/Processes.cpp index f0aec20..7af0f44 100644 --- a/engine/NBCore/src/Processes.cpp +++ b/engine/NBCore/src/Processes.cpp @@ -6,7 +6,7 @@ #include #endif // _NB_TARGET_LINUX -#include "Processes.hpp" +#include namespace nb { diff --git a/engine/NBCore/src/StringUtils.cpp b/engine/NBCore/src/StringUtils.cpp index 1946c3c..98035f8 100644 --- a/engine/NBCore/src/StringUtils.cpp +++ b/engine/NBCore/src/StringUtils.cpp @@ -1,4 +1,4 @@ -#include "StringUtils.hpp" +#include /* std::string nb::wstr_to_str(std::wstring in) { std::size_t wstrlen = in.length(); diff --git a/engine/NBCore/src/Utils.cpp b/engine/NBCore/src/Utils.cpp index 39fc680..9ea7406 100644 --- a/engine/NBCore/src/Utils.cpp +++ b/engine/NBCore/src/Utils.cpp @@ -1,4 +1,4 @@ -#include "Utils.hpp" +#include namespace nb { diff --git a/engine/NBCore/tests/testErrors.cpp b/engine/NBCore/tests/testErrors.cpp index 0c7be49..f429a60 100644 --- a/engine/NBCore/tests/testErrors.cpp +++ b/engine/NBCore/tests/testErrors.cpp @@ -1,10 +1,10 @@ #define CODE_ERROR_LOCATIONS #include - -#include "Errors.hpp" #include +#include + using namespace nb; class TestError : public Error { diff --git a/engine/NBCore/tests/testLogger.cpp b/engine/NBCore/tests/testLogger.cpp index 27da8da..3ff74ff 100644 --- a/engine/NBCore/tests/testLogger.cpp +++ b/engine/NBCore/tests/testLogger.cpp @@ -1,7 +1,7 @@ #include -#include "Errors.hpp" -#include "Logger.hpp" +#include +#include class TestError : public nb::Error { using Base = Error; diff --git a/engine/NBCore/tests/testProcesses.cpp b/engine/NBCore/tests/testProcesses.cpp index cee1e90..8b5ab1a 100644 --- a/engine/NBCore/tests/testProcesses.cpp +++ b/engine/NBCore/tests/testProcesses.cpp @@ -1,7 +1,7 @@ #define CODE_ERROR_LOCATIONS #include -#include "Processes.hpp" +#include #include TEST(ProcessesTest, GetPID) { diff --git a/engine/NBCore/tests/testUtils.cpp b/engine/NBCore/tests/testUtils.cpp index a726369..0244428 100644 --- a/engine/NBCore/tests/testUtils.cpp +++ b/engine/NBCore/tests/testUtils.cpp @@ -3,8 +3,8 @@ #include #include -#include "TypeTraits.hpp" -#include "StringUtils.hpp" +#include +#include namespace nb { diff --git a/engine/NBEvents/src/Events.cpp b/engine/NBEvents/src/Events.cpp index 16e3354..1e825c7 100644 --- a/engine/NBEvents/src/Events.cpp +++ b/engine/NBEvents/src/Events.cpp @@ -1,4 +1,4 @@ -#include "Events.hpp" +#include namespace NB {