chore(*): add Development build type to allow debugging in optimization-enabled mode

This commit is contained in:
_Redstone_c_ 2022-04-20 23:38:29 +08:00
parent ecbf6480ac
commit 63b63ef0b4
4 changed files with 84 additions and 28 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 3.8) cmake_minimum_required (VERSION 3.8)
# Main project # Main project
string(REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}) string (REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR})
project (${CURRENT_FOLDER}) project (${CURRENT_FOLDER})
message (STATUS "Configuring project: " ${CURRENT_FOLDER}) message (STATUS "Configuring project: " ${CURRENT_FOLDER})
@ -25,13 +25,18 @@ else ()
endif () endif ()
# Define configuration type macros # Define configuration type macros
add_compile_definitions ("BUILD_TYPE=${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE MATCHES "Debug") if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_definitions ("BUILD_DEBUG=1") add_compile_definitions ("BUILD_DEBUG=1")
add_compile_definitions ("BUILD_TYPE=Debug")
elseif (CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
add_compile_definitions ("BUILD_DEVELOPMENT=1")
add_compile_definitions ("BUILD_TYPE=Development")
elseif (CMAKE_BUILD_TYPE MATCHES "Release") elseif (CMAKE_BUILD_TYPE MATCHES "Release")
add_compile_definitions ("BUILD_RELEASE=1") add_compile_definitions ("BUILD_RELEASE=1")
add_compile_definitions ("BUILD_TYPE=Release")
else () else ()
add_compile_definitions ("BUILD_UNKNOWN=1") add_compile_definitions ("BUILD_UNKNOWN=1")
add_compile_definitions ("BUILD_TYPE=${CMAKE_BUILD_TYPE}")
endif () endif ()
# Add subproject # Add subproject

View File

@ -11,6 +11,17 @@
"ctestCommandArgs": "", "ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ] "inheritEnvironments": [ "msvc_x64_x64" ]
}, },
{
"name": "x64-Development",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
},
{ {
"name": "x64-Release", "name": "x64-Release",
"generator": "Ninja", "generator": "Ninja",
@ -41,6 +52,25 @@
"remoteCopyBuildOutput": false, "remoteCopyBuildOutput": false,
"remoteCopySourcesMethod": "rsync" "remoteCopySourcesMethod": "rsync"
}, },
{
"name": "Linux-GCC-Development",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"cmakeExecutable": "cmake",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "-D CMAKE_C_COMPILER=gcc-11 -D CMAKE_CXX_COMPILER=g++-11",
"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"
},
{ {
"name": "Linux-GCC-Release", "name": "Linux-GCC-Release",
"generator": "Ninja", "generator": "Ninja",

View File

@ -1,19 +1,19 @@
cmake_minimum_required (VERSION 3.8) cmake_minimum_required (VERSION 3.8)
# Set module name. # Set module name
string(REGEX REPLACE ".*/(.*)" "\\1" MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR}) string (REGEX REPLACE ".*/(.*)" "\\1" MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR})
message (STATUS "Configuring module: " ${MODULE_NAME}) message (STATUS "Configuring module: " ${MODULE_NAME})
# Add target. # Add target
file (GLOB_RECURSE MODULE_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*") file (GLOB_RECURSE MODULE_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*")
add_library (${MODULE_NAME} ${MODULE_SOURCE_FILES}) add_library (${MODULE_NAME} ${MODULE_SOURCE_FILES})
target_compile_definitions (${MODULE_NAME} PRIVATE "MODULE_NAME=${MODULE_NAME}") target_compile_definitions (${MODULE_NAME} PRIVATE "MODULE_NAME=${MODULE_NAME}")
# Add include directories. # Add include directories
target_include_directories (${MODULE_NAME} PUBLIC "Source/Public") target_include_directories (${MODULE_NAME} PUBLIC "Source/Public")
target_include_directories (${MODULE_NAME} PRIVATE "Source/Private") target_include_directories (${MODULE_NAME} PRIVATE "Source/Private")
# Define API macro. # Define API macro
string (TOUPPER ${MODULE_NAME} MODULE_API) string (TOUPPER ${MODULE_NAME} MODULE_API)
string (REGEX REPLACE "[^A-Z ^0-1]" "" MODULE_API ${MODULE_API}) string (REGEX REPLACE "[^A-Z ^0-1]" "" MODULE_API ${MODULE_API})
set (MODULE_API "${MODULE_API}_API") set (MODULE_API "${MODULE_API}_API")

View File

@ -10,10 +10,10 @@ NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_MODULE_BEGIN(Utility)
// Build information macro. // Build information macro
#ifndef PLATFORM_NAME #ifndef PLATFORM_NAME
# error "PLATFORM_NAME must be defined" # error "PLATFORM_NAME must be defined."
#endif #endif
#ifndef PLATFORM_WINDOWS #ifndef PLATFORM_WINDOWS
@ -29,13 +29,17 @@ NAMESPACE_MODULE_BEGIN(Utility)
#endif #endif
#ifndef BUILD_TYPE #ifndef BUILD_TYPE
# error "BUILD_TYPE must be defined" # error "BUILD_TYPE must be defined."
#endif #endif
#ifndef BUILD_DEBUG #ifndef BUILD_DEBUG
# define BUILD_DEBUG 0 # define BUILD_DEBUG 0
#endif #endif
#ifndef BUILD_DEVELOPMENT
# define BUILD_DEVELOPMENT 0
#endif
#ifndef BUILD_RELEASE #ifndef BUILD_RELEASE
# define BUILD_RELEASE 0 # define BUILD_RELEASE 0
#endif #endif
@ -64,7 +68,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
# endif # endif
#endif #endif
// Function type macros. // Function type macros
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
@ -86,7 +90,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
# if BUILD_DEBUG # if BUILD_DEBUG
# define FORCEINLINE inline # define FORCEINLINE inline
# else # else
# define FORCEINLINE inline __attribute__ ((always_inline)) # define FORCEINLINE inline __attribute__((always_inline))
# endif # endif
#else #else
@ -100,40 +104,57 @@ NAMESPACE_MODULE_BEGIN(Utility)
#endif #endif
// DLL export and import definitions. // DLL export and import macros
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
# define DLLEXPORT __declspec(dllexport) # define DLLEXPORT __declspec(dllexport)
# define DLLIMPORT __declspec(dllimport) # define DLLIMPORT __declspec(dllimport)
#elif PLATFORM_LINUX #elif PLATFORM_LINUX
# define DLLEXPORT __attribute__((visibility("default"))) # define DLLEXPORT __attribute__((visibility("default")))
# define DLLIMPORT __attribute__((visibility("default"))) # define DLLIMPORT __attribute__((visibility("default")))
#else #else
# error "DLL export and import macros must be defined."
# define DLLEXPORT
# define DLLIMPORT
#endif #endif
// Unsigned base types. // Optimization macros
#if !defined(__clang__)
# define PRAGMA_DISABLE_OPTIMIZATION_ACTUAL _Pragma("optimize(\"\", off)")
# define PRAGMA_ENABLE_OPTIMIZATION_ACTUAL _Pragma("optimize(\"\", on)")
#elif defined(_MSC_VER)
# define PRAGMA_DISABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize off")
# define PRAGMA_ENABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize on")
#elif defined(__GNUC__ )
# define PRAGMA_DISABLE_OPTIMIZATION_ACTUAL _Pragma("GCC push_options") _Pragma("GCC optimize (\"O0\")")
# define PRAGMA_ENABLE_OPTIMIZATION_ACTUAL _Pragma("GCC pop_options")
#else
# define PRAGMA_DISABLE_OPTIMIZATION_ACTUAL
# define PRAGMA_ENABLE_OPTIMIZATION_ACTUAL
#endif
#if BUILD_DEBUG
# define PRAGMA_DISABLE_OPTIMIZATION
# define PRAGMA_ENABLE_OPTIMIZATION
#else
# define PRAGMA_DISABLE_OPTIMIZATION PRAGMA_DISABLE_OPTIMIZATION_ACTUAL
# define PRAGMA_ENABLE_OPTIMIZATION PRAGMA_ENABLE_OPTIMIZATION_ACTUAL
#endif
// Unsigned base types
typedef NAMESPACE_STD::uint8_t uint8; typedef NAMESPACE_STD::uint8_t uint8;
typedef NAMESPACE_STD::uint16_t uint16; typedef NAMESPACE_STD::uint16_t uint16;
typedef NAMESPACE_STD::uint32_t uint32; typedef NAMESPACE_STD::uint32_t uint32;
typedef NAMESPACE_STD::uint64_t uint64; typedef NAMESPACE_STD::uint64_t uint64;
// Signed base types. // Signed base types
typedef NAMESPACE_STD::int8_t int8; typedef NAMESPACE_STD::int8_t int8;
typedef NAMESPACE_STD::int16_t int16; typedef NAMESPACE_STD::int16_t int16;
typedef NAMESPACE_STD::int32_t int32; typedef NAMESPACE_STD::int32_t int32;
typedef NAMESPACE_STD::int64_t int64; typedef NAMESPACE_STD::int64_t int64;
// Character types. // Character types
typedef char chara; typedef char chara;
typedef wchar_t charw; typedef wchar_t charw;
@ -142,7 +163,7 @@ typedef char8_t char8;
typedef char16_t char16; typedef char16_t char16;
typedef char32_t char32; typedef char32_t char32;
// Pointer types. // Pointer types
typedef NAMESPACE_STD::uintptr_t uintptr; typedef NAMESPACE_STD::uintptr_t uintptr;
typedef NAMESPACE_STD::intptr_t intptr; typedef NAMESPACE_STD::intptr_t intptr;
@ -150,7 +171,7 @@ typedef NAMESPACE_STD::ptrdiff_t ptrdiff;
typedef NAMESPACE_STD::size_t size_t; typedef NAMESPACE_STD::size_t size_t;
typedef intptr_t ssize_t; typedef intptr_t ssize_t;
// Null types. // Null types
typedef decltype(NULL) null_t; typedef decltype(NULL) null_t;
typedef NAMESPACE_STD::nullptr_t nullptr_t; typedef NAMESPACE_STD::nullptr_t nullptr_t;
@ -161,7 +182,7 @@ typedef NAMESPACE_STD::nullptr_t nullptr_t;
# define PLATFORM_TCHAR_IS_CHAR16 0 # define PLATFORM_TCHAR_IS_CHAR16 0
#endif #endif
// Define the TEXT macro. // Define the TEXT macro
#if PLATFORM_TCHAR_IS_CHAR16 #if PLATFORM_TCHAR_IS_CHAR16
# define TEXT_PASTE(x) u ## x # define TEXT_PASTE(x) u ## x