diff --git a/CMakeLists.txt b/CMakeLists.txt index 205caa4..69323cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,9 +39,24 @@ else () add_compile_definitions ("BUILD_TYPE=${CMAKE_BUILD_TYPE}") endif () +# Define compiler macros +if (CMAKE_C_COMPILER_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + add_compile_definitions ("PLATFORM_COMPILER_MSVC=1") + add_compile_definitions ("PLATFORM_COMPILER_NAME=MSVC") +elseif (CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_definitions ("PLATFORM_COMPILER_GCC=1") + add_compile_definitions ("PLATFORM_COMPILER_NAME=GCC") +elseif (CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_definitions ("PLATFORM_COMPILER_CLANG=1") + add_compile_definitions ("PLATFORM_COMPILER_NAME=Clang") +else () + add_compile_definitions ("PLATFORM_COMPILER_UNKNOWN=1") + add_compile_definitions ("PLATFORM_COMPILER_NAME=${CMAKE_C_COMPILER_ID}/${CMAKE_CXX_COMPILER_ID}") +endif () + # Add subproject file (GLOB PROJECT_FOLDERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*") -foreach (PROJECT_SUBDIRECTORY ${PROJECT_FOLDERS}) +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 "") diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/Platform.h b/Redcraft.Utility/Source/Public/Miscellaneous/Platform.h index 70dc24e..2c2b60b 100644 --- a/Redcraft.Utility/Source/Public/Miscellaneous/Platform.h +++ b/Redcraft.Utility/Source/Public/Miscellaneous/Platform.h @@ -14,7 +14,7 @@ NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) -// Build information macro +// Platform information macro #ifndef PLATFORM_NAME # error "PLATFORM_NAME must be defined." @@ -32,6 +32,8 @@ NAMESPACE_MODULE_BEGIN(Utility) # define PLATFORM_UNKNOWN 0 #endif +// Build information macro + #ifndef BUILD_TYPE # error "BUILD_TYPE must be defined." #endif @@ -52,7 +54,29 @@ NAMESPACE_MODULE_BEGIN(Utility) # define BUILD_UNKNOWN 0 #endif -// Whether the CPU is x86/x64 (i.e. both 32 and 64-bit variants) +// Compiler information macro + +#ifndef PLATFORM_COMPILER_NAME +# error "COMPILER_NAME must be defined." +#endif + +#ifndef PLATFORM_COMPILER_MSVC +# define PLATFORM_COMPILER_MSVC 0 +#endif + +#ifndef PLATFORM_COMPILER_CLANG +# define PLATFORM_COMPILER_CLANG 0 +#endif + +#ifndef PLATFORM_COMPILER_GCC +# define PLATFORM_COMPILER_GCC 0 +#endif + +#ifndef PLATFORM_COMPILER_UNKNOWN +# define PLATFORM_COMPILER_UNKNOWN 0 +#endif + +// Architecture information macro #ifndef PLATFORM_CPU_X86_FAMILY # if (defined(_M_IX86) || defined(__i386__) || defined(_M_X64) || defined(__amd64__) || defined(__x86_64__)) @@ -62,8 +86,6 @@ NAMESPACE_MODULE_BEGIN(Utility) # endif #endif -// Whether the CPU is AArch32/AArch64 (i.e. both 32 and 64-bit variants) - #ifndef PLATFORM_CPU_ARM_FAMILY # if (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || defined(_M_ARM64)) # define PLATFORM_CPU_ARM_FAMILY 1 @@ -72,6 +94,22 @@ NAMESPACE_MODULE_BEGIN(Utility) # endif #endif +#ifndef PLATFORM_CPU_UNKNOWN_FAMILY +# define PLATFORM_CPU_UNKNOWN_FAMILY (!(PLATFORM_CPU_X86_FAMILY || PLATFORM_CPU_ARM_FAMILY)) +#endif + +// CPU bits information macro + +#ifndef PLATFORM_CPU_BITS +# if (defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64)) +# define PLATFORM_CPU_BITS 64 +# elif (defined(_M_IX86) || defined(__i386__) || defined(__arm__) || defined(_M_ARM)) +# define PLATFORM_CPU_BITS 32 +# else +# define PLATFORM_CPU_BITS 0 +# endif +#endif + // Function type macros #if PLATFORM_WINDOWS