From 6e3c008936718b71ebd506c12ece0a7a70e8f401 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Tue, 5 Oct 2021 23:36:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9F=BA=E7=A1=80=E6=96=AD?= =?UTF-8?q?=E8=A8=80=20=E6=B7=BB=E5=8A=A0=20Release=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++ CMakeSettings.json | 36 +++++++++++-- Redcraft.Core/Source/Private/HAL/Memory.cpp | 6 +-- Redcraft.Core/Source/Public/CoreMinimal.h | 1 + Redcraft.Core/Source/Public/HAL/Platform.h | 34 ++++++++++++ .../Source/Public/Misc/AssertionMacros.h | 52 +++++++++++++++++++ Redcraft.Debug/Source/Main.cpp | 6 +-- 7 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 Redcraft.Core/Source/Public/Misc/AssertionMacros.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e595634..d3a445d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,10 @@ endif () add_compile_definitions ("BUILD_TYPE=${CMAKE_BUILD_TYPE}") if (CMAKE_BUILD_TYPE MATCHES "Debug") add_compile_definitions ("BUILD_DEBUG=1") +elseif (CMAKE_BUILD_TYPE MATCHES "Release") + add_compile_definitions ("BUILD_RELEASE=1") +else () + add_compile_definitions ("BUILD_UNKNOWN=1") endif () # Add subproject diff --git a/CMakeSettings.json b/CMakeSettings.json index aa69c5b..f04ffb5 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -9,8 +9,18 @@ "cmakeCommandArgs": "", "buildCommandArgs": "", "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64_x64" ], - "variables": [] + "inheritEnvironments": [ "msvc_x64_x64" ] + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ] }, { "name": "Linux-GCC-Debug", @@ -29,8 +39,26 @@ "remoteCopySources": true, "rsyncCommandArgs": "-t --delete --delete-excluded", "remoteCopyBuildOutput": false, - "remoteCopySourcesMethod": "rsync", - "variables": [] + "remoteCopySourcesMethod": "rsync" + }, + { + "name": "Linux-GCC-Release", + "generator": "Ninja", + "configurationType": "Release", + "cmakeExecutable": "cmake", + "remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ], + "cmakeCommandArgs": "-D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "linux_x64" ], + "remoteMachineName": "${defaultRemoteMachineName}", + "remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src", + "remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}", + "remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}", + "remoteCopySources": true, + "rsyncCommandArgs": "-t --delete --delete-excluded", + "remoteCopyBuildOutput": false, + "remoteCopySourcesMethod": "rsync" } ] } \ No newline at end of file diff --git a/Redcraft.Core/Source/Private/HAL/Memory.cpp b/Redcraft.Core/Source/Private/HAL/Memory.cpp index 01add4d..45b73c3 100644 --- a/Redcraft.Core/Source/Private/HAL/Memory.cpp +++ b/Redcraft.Core/Source/Private/HAL/Memory.cpp @@ -2,7 +2,7 @@ #include "Templates/Alignment.h" -#ifdef PLATFORM_WINDOWS +#if PLATFORM_WINDOWS #include #endif @@ -15,7 +15,7 @@ void* Malloc(size_t Count, uint32 Alignment) void* Result = nullptr; -#ifdef PLATFORM_WINDOWS +#if PLATFORM_WINDOWS if (Count != 0) Result = _aligned_malloc(Count, Alignment); #else void* Ptr = SystemMalloc(Count + Alignment + sizeof(void*) + sizeof(size_t)); @@ -36,7 +36,7 @@ void* Realloc(void* Ptr, size_t Count, uint32 Alignment) if (Ptr && Count) { -#ifdef PLATFORM_WINDOWS +#if PLATFORM_WINDOWS return _aligned_realloc(Ptr, Count, Alignment); #else void* Result = Malloc(Count, Alignment); diff --git a/Redcraft.Core/Source/Public/CoreMinimal.h b/Redcraft.Core/Source/Public/CoreMinimal.h index f5278b3..641b5c9 100644 --- a/Redcraft.Core/Source/Public/CoreMinimal.h +++ b/Redcraft.Core/Source/Public/CoreMinimal.h @@ -1,3 +1,4 @@ #pragma once #include "CoreTypes.h" +#include "Misc/AssertionMacros.h" diff --git a/Redcraft.Core/Source/Public/HAL/Platform.h b/Redcraft.Core/Source/Public/HAL/Platform.h index 8e4d478..18fcb1a 100644 --- a/Redcraft.Core/Source/Public/HAL/Platform.h +++ b/Redcraft.Core/Source/Public/HAL/Platform.h @@ -9,6 +9,40 @@ NS_REDCRAFT_BEGIN +// Build information macro. + +#ifndef PLATFORM_NAME + #define PLATFORM_NAME Unknown +#endif + +#ifndef PLATFORM_WINDOWS + #define PLATFORM_WINDOWS 0 +#endif + +#ifndef PLATFORM_LINUX + #define PLATFORM_LINUX 0 +#endif + +#ifndef PLATFORM_UNKNOWN + #define PLATFORM_UNKNOWN 0 +#endif + +#ifndef BUILD_TYPE + #define BUILD_TYPE Unknown +#endif + +#ifndef BUILD_DEBUG + #define BUILD_DEBUG 0 +#endif + +#ifndef BUILD_RELEASE + #define BUILD_RELEASE 0 +#endif + +#ifndef BUILD_UNKNOWN + #define BUILD_UNKNOWN 0 +#endif + // Function type macros. #if PLATFORM_WINDOWS diff --git a/Redcraft.Core/Source/Public/Misc/AssertionMacros.h b/Redcraft.Core/Source/Public/Misc/AssertionMacros.h new file mode 100644 index 0000000..8c4fe1e --- /dev/null +++ b/Redcraft.Core/Source/Public/Misc/AssertionMacros.h @@ -0,0 +1,52 @@ +#pragma once + +#include "CoreTypes.h" + +#include + +NS_REDCRAFT_BEGIN + +NS_PRIVATE_BEGIN + +class FRecursionScopeMarker +{ +public: + + FRecursionScopeMarker(uint8& InCounter) : Counter(InCounter) { ++Counter; } + ~FRecursionScopeMarker() { --Counter; } + +private: + + uint8& Counter; + +}; + +NS_PRIVATE_END + +#if BUILD_DEBUG + + #define check_code(InCode) do { InCode; } while (false) + #define check(InExpr) assert(InExpr) + #define checkf(InExpr, InFormat, ...) assert(InExpr) + #define check_no_entry() checkf(false, "Enclosing block should never be called.") + #define check_no_reentry() { static bool bBeenHere##__LINE__ = false; checkf(!bBeenHere##__LINE__, "Enclosing block was called more than once."); bBeenHere##__LINE__ = true; } + #define check_no_recursion() static uint8 RecursionCounter##__LINE__ = 0; checkf(RecursionCounter##__LINE__ == 0, "Enclosing block was entered recursively."); const NS_PRIVATE::FRecursionScopeMarker ScopeMarker##__LINE__(RecursionCounter##__LINE__) + #define verify(InExpr) assert(InExpr) + #define verifyf(InExpr, InFormat, ...) assert(InExpr) + #define unimplemented() check(false, "Unimplemented function called.") + +#else + + #define check_code(...) + #define check(InExpr) + #define checkf(InExpr, InFormat, ...) + #define check_no_entry() + #define check_no_reentry() + #define check_no_recursion() + #define verify(InExpr) { if(InExpr) { } } + #define verifyf(InExpr, InFormat, ...) { if(InExpr) { } } + #define unimplemented() + +#endif + +NS_REDCRAFT_END diff --git a/Redcraft.Debug/Source/Main.cpp b/Redcraft.Debug/Source/Main.cpp index deb8567..5544ed8 100644 --- a/Redcraft.Debug/Source/Main.cpp +++ b/Redcraft.Debug/Source/Main.cpp @@ -10,9 +10,7 @@ NS_REDCRAFT_USING int main() { - int32* Ptr = new int32; - *Ptr = 13; - cout << *Ptr << endl; - delete Ptr; + check_no_entry(); + cout << "Done!" << endl; return 0; }