From dce84d24a40df1a5bb84118c5749bc2aa56c29a8 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Sun, 26 Sep 2021 23:24:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8E=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 + CMakeLists.txt | 41 ++++++ CMakeSettings.json | 15 +++ Redcraft.Core/CMakeLists.txt | 23 ++++ Redcraft.Core/Source/Public/CoreMinimal.h | 3 + Redcraft.Core/Source/Public/CoreTypes.h | 4 + Redcraft.Core/Source/Public/HAL/Platform.h | 122 ++++++++++++++++++ .../Source/Public/Misc/CoreDefines.h | 19 +++ Redcraft.Debug/CMakeLists.txt | 22 ++++ Redcraft.Debug/Source/Main.cpp | 12 ++ 10 files changed, 267 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 CMakeSettings.json create mode 100644 Redcraft.Core/CMakeLists.txt create mode 100644 Redcraft.Core/Source/Public/CoreMinimal.h create mode 100644 Redcraft.Core/Source/Public/CoreTypes.h create mode 100644 Redcraft.Core/Source/Public/HAL/Platform.h create mode 100644 Redcraft.Core/Source/Public/Misc/CoreDefines.h create mode 100644 Redcraft.Debug/CMakeLists.txt create mode 100644 Redcraft.Debug/Source/Main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3842ae8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Visual Studio cache directory +.vs/ + +# CMake generated files +Build/ +Install/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e595634 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required (VERSION 3.8) + +# Main project +project ("Redcraft") + +# Reset the binary file directory +set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Build") +set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Build") +set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Binaries") + +# Configure compile options +set (BUILD_SHARED_LIBS true) +set (CMAKE_CXX_STANDARD 20) + +# Define platform macros +add_compile_definitions ("PLATFORM_NAME=${CMAKE_SYSTEM_NAME}") +if (CMAKE_SYSTEM_NAME MATCHES "Windows") + add_compile_definitions ("PLATFORM_WINDOWS=1") +elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") + add_compile_definitions ("PLATFORM_LINUX=1") +else () + add_compile_definitions ("PLATFORM_UNKNOWN=1") +endif () + +# Define configuration type macros +add_compile_definitions ("BUILD_TYPE=${CMAKE_BUILD_TYPE}") +if (CMAKE_BUILD_TYPE MATCHES "Debug") + add_compile_definitions ("BUILD_DEBUG=1") +endif () + +# Add subproject +file (GLOB PROJECT_FOLDERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*") +foreach (PROJECT_SUBDIRECTORY ${PROJECT_FOLDERS}) + if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SUBDIRECTORY}") + file (GLOB PROJECT_CMAKELISTS "${PROJECT_SUBDIRECTORY}/CMakeLists.txt") + if (NOT "${PROJECT_CMAKELISTS}" STREQUAL "") + message (STATUS "Add subdirectory: " ${PROJECT_SUBDIRECTORY}) + add_subdirectory (${PROJECT_SUBDIRECTORY}) + endif () + endif () +endforeach () diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000..607fd69 --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\Build\\${name}", + "installRoot": "${projectDir}\\Install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "" + } + ] +} \ No newline at end of file diff --git a/Redcraft.Core/CMakeLists.txt b/Redcraft.Core/CMakeLists.txt new file mode 100644 index 0000000..d50e3cc --- /dev/null +++ b/Redcraft.Core/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required (VERSION 3.8) + +# Set module name. +set (MODULE_NAME "Redcraft.Core") + +# Add target. +file (GLOB_RECURSE MODULE_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*") +add_library (${MODULE_NAME} ${MODULE_SOURCE_FILES}) +target_compile_definitions (${MODULE_NAME} PRIVATE "MODULE_NAME=${MODULE_NAME}") + +# Add include directories. +target_include_directories (${MODULE_NAME} PUBLIC "Source/Public") +target_include_directories (${MODULE_NAME} PRIVATE "Source/Private") + +# Define API macro. +string (TOUPPER ${MODULE_NAME} MODULE_API) +string (REGEX REPLACE "[^A-Z ^0-1]" "" MODULE_API ${MODULE_API}) +set (MODULE_API "${MODULE_API}_API") +target_compile_definitions (${MODULE_NAME} PRIVATE "${MODULE_API}=DLLEXPORT") +target_compile_definitions (${MODULE_NAME} INTERFACE "${MODULE_API}=DLLIMPORT") + +# Add project dependencies +#target_link_libraries (${MODULE_NAME} PRIVATE Redcraft.Core) diff --git a/Redcraft.Core/Source/Public/CoreMinimal.h b/Redcraft.Core/Source/Public/CoreMinimal.h new file mode 100644 index 0000000..f5278b3 --- /dev/null +++ b/Redcraft.Core/Source/Public/CoreMinimal.h @@ -0,0 +1,3 @@ +#pragma once + +#include "CoreTypes.h" diff --git a/Redcraft.Core/Source/Public/CoreTypes.h b/Redcraft.Core/Source/Public/CoreTypes.h new file mode 100644 index 0000000..362211b --- /dev/null +++ b/Redcraft.Core/Source/Public/CoreTypes.h @@ -0,0 +1,4 @@ +#pragma once + +#include "HAL/Platform.h" +#include "Misc/CoreDefines.h" diff --git a/Redcraft.Core/Source/Public/HAL/Platform.h b/Redcraft.Core/Source/Public/HAL/Platform.h new file mode 100644 index 0000000..e2afd42 --- /dev/null +++ b/Redcraft.Core/Source/Public/HAL/Platform.h @@ -0,0 +1,122 @@ +#pragma once + +#include "Misc/CoreDefines.h" + +#include +#include + +NS_REDCRAFT_BEGIN + +// Function type macros. +#if PLATFORM_WINDOWS + + #define VARARGS __cdecl + #define CDECL __cdecl + #define STDCALL __stdcall + #define FORCEINLINE __forceinline + #define FORCENOINLINE __declspec(noinline) + #define RESTRICT __restrict + +#elif PLATFORM_LINUX + + #define VARARGS + #define CDECL + #define STDCALL + #define FORCENOINLINE __attribute__((noinline)) + #define RESTRICT __restrict + + #if BUILD_DEBUG + #define FORCEINLINE inline + #else + #define FORCEINLINE inline __attribute__ ((always_inline)) + #endif + +#else + + #define VARARGS + #define CDECL + #define STDCALL + #define FORCEINLINE + #define FORCENOINLINE + #define RESTRICT __restrict + +#endif + +// Alignment. +#if defined(__clang__) + + #define GCC_PACK(n) __attribute__((packed,aligned(n))) + #define GCC_ALIGN(n) __attribute__((aligned(n))) + + #if defined(_MSC_VER) + #define MS_ALIGN(n) __declspec(align(n)) + #endif + +#else + + #define GCC_PACK(n) + #define GCC_ALIGN(n) + #define MS_ALIGN(n) __declspec(align(n)) + +#endif + +// DLL export and import definitions +#if PLATFORM_WINDOWS + + #define DLLEXPORT __declspec(dllexport) + #define DLLIMPORT __declspec(dllimport) + +#elif PLATFORM_LINUX + + #define DLLEXPORT __attribute__((visibility("default"))) + #define DLLIMPORT __attribute__((visibility("default"))) + +#else + + #define DLLEXPORT + #define DLLIMPORT + +#endif + +// Unsigned base types. +typedef std::uint8_t uint8; +typedef std::uint16_t uint16; +typedef std::uint32_t uint32; +typedef std::uint64_t uint64; + +// Signed base types. +typedef std::int8_t int8; +typedef std::int16_t int16; +typedef std::int32_t int32; +typedef std::int64_t int64; + +// Character types. +typedef char ANSICHAR; +typedef wchar_t WIDECHAR; +typedef WIDECHAR TCHAR; + +// Pointer types +typedef std::uintptr_t uintptr_t; +typedef std::intptr_t intptr_t; +typedef std::size_t size_t; +typedef intptr_t ssize_t; + +// Null types +typedef decltype(NULL) null_t; +typedef std::nullptr_t nullptr_t; + +#if PLATFORM_LINUX + #define PLATFORM_TCHAR_IS_CHAR16 1 +#else + #define PLATFORM_TCHAR_IS_CHAR16 0 +#endif + +// Define the TEXT macro. +#if PLATFORM_TCHAR_IS_CHAR16 + #define TEXT_PASTE(x) u ## x +#else + #define TEXT_PASTE(x) L ## x +#endif +#define TEXT(x) TEXT_PASTE(x) + +NS_REDCRAFT_END diff --git a/Redcraft.Core/Source/Public/Misc/CoreDefines.h b/Redcraft.Core/Source/Public/Misc/CoreDefines.h new file mode 100644 index 0000000..0c608ae --- /dev/null +++ b/Redcraft.Core/Source/Public/Misc/CoreDefines.h @@ -0,0 +1,19 @@ +#pragma once + +#define NS_REDCRAFT RFur +#define NS_REDCRAFT_BEGIN namespace NS_REDCRAFT { +#define NS_REDCRAFT_END } +#define NS_REDCRAFT_USING using namespace NS_REDCRAFT; + +#define NS_STD_BEGIN namespace std { +#define NS_STD_END } +#define NS_STD_USING using namespace std; + +NS_REDCRAFT_BEGIN + +enum { INDEX_NONE = -1 }; +enum { UNICODE_BOM = 0xfeff }; + +enum EForceInit { ForceInit }; + +NS_REDCRAFT_END diff --git a/Redcraft.Debug/CMakeLists.txt b/Redcraft.Debug/CMakeLists.txt new file mode 100644 index 0000000..4611768 --- /dev/null +++ b/Redcraft.Debug/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required (VERSION 3.8) + +# Set module name. +set (MODULE_NAME "Redcraft.Debug") + +# Add target. +file (GLOB_RECURSE MODULE_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*") +add_executable(${MODULE_NAME} ${MODULE_SOURCE_FILES}) +target_compile_definitions (${MODULE_NAME} PRIVATE "MODULE_NAME=${MODULE_NAME}") + +# Add include directories. +target_include_directories (${MODULE_NAME} PRIVATE "Source") + +# Define API macro. +string (TOUPPER ${MODULE_NAME} MODULE_API) +string (REGEX REPLACE "[^A-Z ^0-1]" "" MODULE_API ${MODULE_API}) +set (MODULE_API "${MODULE_API}_API") +target_compile_definitions (${MODULE_NAME} PRIVATE "${MODULE_API}=DLLEXPORT") +target_compile_definitions (${MODULE_NAME} INTERFACE "${MODULE_API}=DLLIMPORT") + +# Add project dependencies +target_link_libraries (${MODULE_NAME} PRIVATE Redcraft.Core) diff --git a/Redcraft.Debug/Source/Main.cpp b/Redcraft.Debug/Source/Main.cpp new file mode 100644 index 0000000..cbf1de9 --- /dev/null +++ b/Redcraft.Debug/Source/Main.cpp @@ -0,0 +1,12 @@ +#include "CoreMinimal.h" + +#include +#include + +NS_STD_USING +NS_REDCRAFT_USING + +int main() +{ + return 0; +}