Core/Misc: Changed compiler detection to better support compilers that pretend to be something else, such as clang-cl is both msvc and clang at the same time

This commit is contained in:
Shauren
2026-05-10 14:40:49 +02:00
parent 648343e7a4
commit e49105cb68
28 changed files with 75 additions and 45 deletions
+39 -9
View File
@@ -30,19 +30,49 @@
# define TRINITY_PLATFORM TRINITY_PLATFORM_UNIX # define TRINITY_PLATFORM TRINITY_PLATFORM_UNIX
#endif #endif
#define TRINITY_COMPILER_MICROSOFT 0 #define TRINITY_COMPILER_MICROSOFT_FLAG(on) ((on) << 0)
#define TRINITY_COMPILER_GNU 1 #define TRINITY_COMPILER_GCC_FLAG(on) ((on) << 1)
#define TRINITY_COMPILER_INTEL 2 #define TRINITY_COMPILER_CLANG_FLAG(on) ((on) << 2)
#define TRINITY_COMPILER_INTEL_FLAG(on) ((on) << 3)
#ifdef _MSC_VER #ifdef _MSC_VER
# define TRINITY_COMPILER TRINITY_COMPILER_MICROSOFT # define TRINITY_COMPILER_MICROSOFT_DETECTED 1
#elif defined( __INTEL_COMPILER )
# define TRINITY_COMPILER TRINITY_COMPILER_INTEL
#elif defined( __GNUC__ )
# define TRINITY_COMPILER TRINITY_COMPILER_GNU
# define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else #else
# define TRINITY_COMPILER_MICROSOFT_DETECTED 0
#endif
#ifdef __GNUC__
# define TRINITY_COMPILER_GCC_DETECTED 1
#else
# define TRINITY_COMPILER_GCC_DETECTED 0
#endif
#ifdef __clang__
# define TRINITY_COMPILER_CLANG_DETECTED 1
#else
# define TRINITY_COMPILER_CLANG_DETECTED 0
#endif
#ifdef __INTEL_COMPILER
# define TRINITY_COMPILER_INTEL_DETECTED 1
#else
# define TRINITY_COMPILER_INTEL_DETECTED 0
#endif
#define TRINITY_COMPILER \
( TRINITY_COMPILER_MICROSOFT_FLAG(TRINITY_COMPILER_MICROSOFT_DETECTED) \
| TRINITY_COMPILER_GCC_FLAG(TRINITY_COMPILER_GCC_DETECTED) \
| TRINITY_COMPILER_CLANG_FLAG(TRINITY_COMPILER_CLANG_DETECTED) \
| TRINITY_COMPILER_INTEL_FLAG(TRINITY_COMPILER_INTEL_DETECTED) )
#if TRINITY_COMPILER == 0
# error "FATAL ERROR: Unknown compiler." # error "FATAL ERROR: Unknown compiler."
#endif #endif
#define TRINITY_COMPILER_IS(compiler) (((TRINITY_COMPILER) & (compiler)) != 0)
#define TRINITY_COMPILER_IS_MICROSOFT TRINITY_COMPILER_IS(TRINITY_COMPILER_MICROSOFT_FLAG(1))
#define TRINITY_COMPILER_IS_GCC TRINITY_COMPILER_IS(TRINITY_COMPILER_GCC_FLAG(1))
#define TRINITY_COMPILER_IS_CLANG TRINITY_COMPILER_IS(TRINITY_COMPILER_CLANG_FLAG(1))
#define TRINITY_COMPILER_IS_INTEL TRINITY_COMPILER_IS(TRINITY_COMPILER_INTEL_FLAG(1))
#endif #endif
+1 -1
View File
@@ -33,7 +33,7 @@
terminates the application. terminates the application.
*/ */
#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT #if TRINITY_COMPILER_IS_MICROSOFT
#define Unreachable() (__assume(false)) #define Unreachable() (__assume(false))
#else #else
#define Unreachable() (__builtin_unreachable()) #define Unreachable() (__builtin_unreachable())
+1 -1
View File
@@ -52,7 +52,7 @@ namespace Trinity
} }
} // namespace Trinity } // namespace Trinity
#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT #if TRINITY_COMPILER_IS_MICROSOFT
#define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127)) #define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127))
#define ASSERT_END __pragma(warning(pop)) #define ASSERT_END __pragma(warning(pop))
#else #else
+6 -6
View File
@@ -20,7 +20,7 @@
#include "CompilerDefs.h" #include "CompilerDefs.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
# if !defined(__STDC_FORMAT_MACROS) # if !defined(__STDC_FORMAT_MACROS)
# define __STDC_FORMAT_MACROS # define __STDC_FORMAT_MACROS
# endif # endif
@@ -72,17 +72,17 @@
# define TRINITY_INLINE # define TRINITY_INLINE
#endif //!COREDEBUG #endif //!COREDEBUG
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
# define ATTR_PRINTF(F, V) __attribute__ ((__format__ (__printf__, F, V))) # define ATTR_PRINTF(F, V) __attribute__ ((__format__ (__printf__, F, V)))
#else //TRINITY_COMPILER != TRINITY_COMPILER_GNU #else //TRINITY_COMPILER_IS_GCC
# define ATTR_PRINTF(F, V) # define ATTR_PRINTF(F, V)
#endif //TRINITY_COMPILER == TRINITY_COMPILER_GNU #endif //TRINITY_COMPILER_IS_GCC
#ifdef TRINITY_API_USE_DYNAMIC_LINKING #ifdef TRINITY_API_USE_DYNAMIC_LINKING
# if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT # if TRINITY_COMPILER_IS_MICROSOFT
# define TC_API_EXPORT __declspec(dllexport) # define TC_API_EXPORT __declspec(dllexport)
# define TC_API_IMPORT __declspec(dllimport) # define TC_API_IMPORT __declspec(dllimport)
# elif TRINITY_COMPILER == TRINITY_COMPILER_GNU # elif TRINITY_COMPILER_IS_GCC
# define TC_API_EXPORT __attribute__((visibility("default"))) # define TC_API_EXPORT __attribute__((visibility("default")))
# define TC_API_IMPORT # define TC_API_IMPORT
# else # else
+1 -1
View File
@@ -165,7 +165,7 @@ class TC_COMMON_API Log
#ifdef PERFORMANCE_PROFILING #ifdef PERFORMANCE_PROFILING
#define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) ((void)0) #define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) ((void)0)
#elif TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS #elif !TRINITY_COMPILER_IS_MICROSOFT
#define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ## __VA_ARGS__) #define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ## __VA_ARGS__)
#else #else
#define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) \ #define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) \
+2 -2
View File
@@ -22,7 +22,7 @@
#include <concepts> #include <concepts>
#include <memory> #include <memory>
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-attributes" #pragma GCC diagnostic ignored "-Wignored-attributes"
#endif #endif
@@ -167,7 +167,7 @@ inline std::unique_ptr<T, Impl::stateless_unique_ptr_deleter<Ptr, Del>> make_uni
} }
} }
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
+2 -2
View File
@@ -75,7 +75,7 @@ public:
{ {
ASSERT(!my_child, "Process started already!"); ASSERT(!my_child, "Process started already!");
#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT #if TRINITY_COMPILER_IS_MICROSOFT
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4297) #pragma warning(disable:4297)
/* /*
@@ -89,7 +89,7 @@ public:
#endif #endif
bp::ipstream outStream; bp::ipstream outStream;
bp::ipstream errStream; bp::ipstream errStream;
#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT #if TRINITY_COMPILER_IS_MICROSOFT
#pragma warning(pop) #pragma warning(pop)
#endif #endif
+1 -1
View File
@@ -174,7 +174,7 @@ namespace Trinity::Impl::StringConvertImpl
} }
}; };
#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT #if TRINITY_COMPILER_IS_MICROSOFT
template <typename T> template <typename T>
struct For<T, std::enable_if_t<std::is_floating_point_v<T>>> struct For<T, std::enable_if_t<std::is_floating_point_v<T>>>
{ {
+1 -1
View File
@@ -437,7 +437,7 @@ variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, f
return variablesMap; return variablesMap;
} }
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #if TRINITY_COMPILER_IS_MICROSOFT
#include "WheatyExceptionReport.h" #include "WheatyExceptionReport.h"
// must be at end of file because of init_seg pragma // must be at end of file because of init_seg pragma
INIT_CRASH_HANDLER(); INIT_CRASH_HANDLER();
+2 -2
View File
@@ -371,14 +371,14 @@ class TC_GAME_API BaseEntity
inline BaseEntity* UF::UpdateFieldHolder::GetOwner() inline BaseEntity* UF::UpdateFieldHolder::GetOwner()
{ {
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GNU
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof" #pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif #endif
return reinterpret_cast<BaseEntity*>(reinterpret_cast<std::byte*>(this) - offsetof(BaseEntity, m_values)); return reinterpret_cast<BaseEntity*>(reinterpret_cast<std::byte*>(this) - offsetof(BaseEntity, m_values));
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GNU
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
} }
@@ -27,7 +27,7 @@
// This file is automatically generated, DO NOT EDIT // This file is automatically generated, DO NOT EDIT
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
#else #else
@@ -10535,7 +10535,7 @@ void PlayerInitiativeComponentData::ClearChangesMask()
} }
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#else #else
#pragma warning(pop) #pragma warning(pop)
+1 -1
View File
@@ -37,7 +37,7 @@ EndScriptData */
#include "World.h" #include "World.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -33,7 +33,7 @@
#include "RBAC.h" #include "RBAC.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -36,7 +36,7 @@ EndScriptData */
#include "Util.h" #include "Util.h"
#include <iomanip> #include <iomanip>
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -38,7 +38,7 @@ EndScriptData */
#include "WorldSession.h" #include "WorldSession.h"
#include <sstream> #include <sstream>
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -49,7 +49,7 @@
#include "World.h" #include "World.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -37,7 +37,7 @@
#include "RBAC.h" #include "RBAC.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -41,7 +41,7 @@ EndScriptData */
using namespace Trinity::ChatCommands; using namespace Trinity::ChatCommands;
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -51,7 +51,7 @@ EndScriptData */
#include "WaypointManager.h" #include "WaypointManager.h"
#include "World.h" #include "World.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -37,7 +37,7 @@ EndScriptData */
#include "World.h" #include "World.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -27,7 +27,7 @@
#include "RBAC.h" #include "RBAC.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -47,7 +47,7 @@ EndScriptData */
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <numeric> #include <numeric>
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -35,7 +35,7 @@ EndScriptData */
#include "World.h" #include "World.h"
#include "WorldSession.h" #include "WorldSession.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU #if TRINITY_COMPILER_IS_GCC
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
+1 -1
View File
@@ -734,7 +734,7 @@ variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, f
return vm; return vm;
} }
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #if TRINITY_COMPILER_IS_MICROSOFT
#include "WheatyExceptionReport.h" #include "WheatyExceptionReport.h"
// must be at end of file because of init_seg pragma // must be at end of file because of init_seg pragma
INIT_CRASH_HANDLER(); INIT_CRASH_HANDLER();
+1 -1
View File
@@ -1576,7 +1576,7 @@ int main(int argc, char * arg[])
return 0; return 0;
} }
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #if TRINITY_COMPILER_IS_MICROSOFT
#include "WheatyExceptionReport.h" #include "WheatyExceptionReport.h"
// must be at end of file because of init_seg pragma // must be at end of file because of init_seg pragma
INIT_CRASH_HANDLER(); INIT_CRASH_HANDLER();
+1 -1
View File
@@ -509,7 +509,7 @@ int main(int argc, char** argv)
return 0; return 0;
} }
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #if TRINITY_COMPILER_IS_MICROSOFT
#include "WheatyExceptionReport.h" #include "WheatyExceptionReport.h"
// must be at end of file because of init_seg pragma // must be at end of file because of init_seg pragma
INIT_CRASH_HANDLER(); INIT_CRASH_HANDLER();
+1 -1
View File
@@ -112,7 +112,7 @@ Optional<int> HandleArgs(int argc, char* argv[], std::string* src, std::string*
return {}; return {};
} }
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #if TRINITY_COMPILER_IS_MICROSOFT
#include "WheatyExceptionReport.h" #include "WheatyExceptionReport.h"
// must be at end of file because of init_seg pragma // must be at end of file because of init_seg pragma
INIT_CRASH_HANDLER(); INIT_CRASH_HANDLER();
+1 -1
View File
@@ -736,7 +736,7 @@ int main(int argc, char ** argv)
return 0; return 0;
} }
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #if TRINITY_COMPILER_IS_MICROSOFT
#include "WheatyExceptionReport.h" #include "WheatyExceptionReport.h"
// must be at end of file because of init_seg pragma // must be at end of file because of init_seg pragma
INIT_CRASH_HANDLER(); INIT_CRASH_HANDLER();