From 39d0ad6b67a109ce04eb992abe7244456a4350b8 Mon Sep 17 00:00:00 2001 From: Andrey Doroschenko Date: Fri, 23 Sep 2022 16:58:21 +0300 Subject: [PATCH] Added cmake building system for a new structure --- .gitignore | 4 ++ new_structure/README.md | 5 --- new_structure/radian/CMakeLists.txt | 30 +++++++++++++ new_structure/{engine => radian}/Makefile | 0 new_structure/radian/README.md | 11 +++++ .../{engine => radian}/include/radian.hpp | 3 ++ new_structure/radian/include/radian.hpp.in | 43 +++++++++++++++++++ .../include/tools/exception.hpp | 0 .../include/tools/logger.hpp | 0 .../{engine => radian}/src/radian.cpp | 0 .../{engine => radian}/src/tools/logger.cpp | 0 new_structure/sandbox/CMakeLists.txt | 18 ++++++++ .../sandbox/{ => src}/application.cpp | 0 13 files changed, 109 insertions(+), 5 deletions(-) delete mode 100644 new_structure/README.md create mode 100644 new_structure/radian/CMakeLists.txt rename new_structure/{engine => radian}/Makefile (100%) create mode 100644 new_structure/radian/README.md rename new_structure/{engine => radian}/include/radian.hpp (94%) create mode 100644 new_structure/radian/include/radian.hpp.in rename new_structure/{engine => radian}/include/tools/exception.hpp (100%) rename new_structure/{engine => radian}/include/tools/logger.hpp (100%) rename new_structure/{engine => radian}/src/radian.cpp (100%) rename new_structure/{engine => radian}/src/tools/logger.cpp (100%) create mode 100644 new_structure/sandbox/CMakeLists.txt rename new_structure/sandbox/{ => src}/application.cpp (100%) diff --git a/.gitignore b/.gitignore index 1a3fa30..63960db 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ imgui* target/* resources/* .vscode + +*/build/* + + diff --git a/new_structure/README.md b/new_structure/README.md deleted file mode 100644 index 12ae3ef..0000000 --- a/new_structure/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Radian - -```bash -$ sudo apt install libspdlog-dev -``` diff --git a/new_structure/radian/CMakeLists.txt b/new_structure/radian/CMakeLists.txt new file mode 100644 index 0000000..e8bd0df --- /dev/null +++ b/new_structure/radian/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.4) + +project(radian VERSION 1.0 LANGUAGES CXX) + +file( + GLOB_RECURSE SOURCES CONFIGURE_DEPENDS + "${PROJECT_SOURCE_DIR}/include/*.hpp" + "${PROJECT_SOURCE_DIR}/src/*.cpp" +) +file( + GLOB_RECURSE PUBLIC_HEADERS CONFIGURE_DEPENDS + "${PROJECT_SOURCE_DIR}/include/*.hpp" +) + +configure_file( + "${PROJECT_SOURCE_DIR}/include/radian.hpp.in" + "${PROJECT_SOURCE_DIR}/include/radian.hpp" +) + +add_library(radian SHARED ${SOURCES}) +target_compile_options(radian PUBLIC -Wall -Wextra -pedantic) +target_include_directories(radian PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +set_target_properties(radian PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED TRUE CXX_EXTENSIONS FALSE) +set_target_properties(radian PROPERTIES PUBLIC_HEADER ${PUBLIC_HEADERS}) + +install( + TARGETS radian + LIBRARY DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/lib" + PUBLIC_HEADER DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/include" +) diff --git a/new_structure/engine/Makefile b/new_structure/radian/Makefile similarity index 100% rename from new_structure/engine/Makefile rename to new_structure/radian/Makefile diff --git a/new_structure/radian/README.md b/new_structure/radian/README.md new file mode 100644 index 0000000..912703a --- /dev/null +++ b/new_structure/radian/README.md @@ -0,0 +1,11 @@ +# Radian + +```bash +$ sudo apt install libspdlog-dev +``` + +```bash +$ cmake -B build . +$ make -C build +$ ./build/app +``` diff --git a/new_structure/engine/include/radian.hpp b/new_structure/radian/include/radian.hpp similarity index 94% rename from new_structure/engine/include/radian.hpp rename to new_structure/radian/include/radian.hpp index f4a726b..dded460 100644 --- a/new_structure/engine/include/radian.hpp +++ b/new_structure/radian/include/radian.hpp @@ -1,6 +1,9 @@ #ifndef __RADIAN__ #define __RADIAN__ +#define VERSION_MAJOR 1 +#define VERSION_MINOR 0 + #include #include diff --git a/new_structure/radian/include/radian.hpp.in b/new_structure/radian/include/radian.hpp.in new file mode 100644 index 0000000..33ce0ac --- /dev/null +++ b/new_structure/radian/include/radian.hpp.in @@ -0,0 +1,43 @@ +#ifndef __RADIAN__ +#define __RADIAN__ + +#define VERSION_MAJOR @radian_VERSION_MAJOR@ +#define VERSION_MINOR @radian_VERSION_MINOR@ + +#include +#include + +#include "tools/logger.hpp" + +namespace Radian { + class Exception : public std::exception { + public: + virtual ~Exception() {} + virtual const char* what() const noexcept = 0; + }; + + + class Application { + public: + std::unique_ptr logger; + + Application(); + virtual ~Application(); + virtual void startup() = 0; + virtual void run() = 0; + virtual void shutdown() = 0 ; + }; + + + class Engine { + private: + std::unique_ptr _app; + + public: + void run(std::unique_ptr); + }; + + static std::unique_ptr engine = std::make_unique(); +} + +#endif diff --git a/new_structure/engine/include/tools/exception.hpp b/new_structure/radian/include/tools/exception.hpp similarity index 100% rename from new_structure/engine/include/tools/exception.hpp rename to new_structure/radian/include/tools/exception.hpp diff --git a/new_structure/engine/include/tools/logger.hpp b/new_structure/radian/include/tools/logger.hpp similarity index 100% rename from new_structure/engine/include/tools/logger.hpp rename to new_structure/radian/include/tools/logger.hpp diff --git a/new_structure/engine/src/radian.cpp b/new_structure/radian/src/radian.cpp similarity index 100% rename from new_structure/engine/src/radian.cpp rename to new_structure/radian/src/radian.cpp diff --git a/new_structure/engine/src/tools/logger.cpp b/new_structure/radian/src/tools/logger.cpp similarity index 100% rename from new_structure/engine/src/tools/logger.cpp rename to new_structure/radian/src/tools/logger.cpp diff --git a/new_structure/sandbox/CMakeLists.txt b/new_structure/sandbox/CMakeLists.txt new file mode 100644 index 0000000..8c8ecfa --- /dev/null +++ b/new_structure/sandbox/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.4) + +project(app LANGUAGES CXX) + +file( + GLOB_RECURSE SOURCES CONFIGURE_DEPENDS + "${PROJECT_SOURCE_DIR}/src/*.cpp" + "${PROJECT_SOURCE_DIR}/include/*.hpp" +) + +# TODO: Find a better way to add a main project +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../radian/include) + +add_executable(${CMAKE_PROJECT_NAME} ${SOURCES}) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../radian ${CMAKE_CURRENT_BINARY_DIR}/radian) +target_link_libraries(${CMAKE_PROJECT_NAME} radian) +target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC -Wall -Wextra -pedantic) +set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED TRUE CXX_EXTENSIONS FALSE) diff --git a/new_structure/sandbox/application.cpp b/new_structure/sandbox/src/application.cpp similarity index 100% rename from new_structure/sandbox/application.cpp rename to new_structure/sandbox/src/application.cpp