diff options
| author | Karuro Chari <[email protected]> | 2026-05-23 17:40:15 +0100 |
|---|---|---|
| committer | Karuro Chari <[email protected]> | 2026-05-23 17:40:53 +0100 |
| commit | e7b60233274b11de23879cea22766588e1c95bbc (patch) | |
| tree | 34660b4f499c31479b89bc644f3a5c6549b58f66 /xmake/modules/lib/detect/check_alignof.lua | |
| parent | aff68423976e2c8a4feb97f19edf6716d271f0f0 (diff) | |
Introduced detection mechanisms to pick the best `alignof` keyword based on language, version and toolchain.
Diffstat (limited to 'xmake/modules/lib/detect/check_alignof.lua')
| -rw-r--r-- | xmake/modules/lib/detect/check_alignof.lua | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/xmake/modules/lib/detect/check_alignof.lua b/xmake/modules/lib/detect/check_alignof.lua index d8b1561f4..10914b3a8 100644 --- a/xmake/modules/lib/detect/check_alignof.lua +++ b/xmake/modules/lib/detect/check_alignof.lua @@ -24,13 +24,28 @@ import("lib.detect.check_cxxsnippets") local binary_match_pattern = 'INFO:align%[(%d+)%]' local check_alignof_template = [[ -#define ALIGN (alignof(${TYPE})) +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define ALIGNOF(type) alignof(type) + #endif +#elif __STDC_VERSION__ >= 202311L + #define ALIGNOF(type) alignof(type) +#elif __STDC_VERSION__ >= 201112L + #define ALIGNOF(type) _Alignof(type) +#elif defined(_MSC_VER) + #define ALIGNOF(type) __alignof(type) +#elif defined(__GNUC__) || defined(__clang__) + #define ALIGNOF(type) __alignof__(type) +#else + #error No known support of alignment detection for your toolchain +#endif + static char info_align[] = {'I', 'N', 'F', 'O', ':', 'a','l','i','g','n','[', - ('0' + ((ALIGN / 10000)%10)), - ('0' + ((ALIGN / 1000)%10)), - ('0' + ((ALIGN / 100)%10)), - ('0' + ((ALIGN / 10)%10)), - ('0' + (ALIGN % 10)), + ('0' + ((ALIGNOF(${TYPE}) / 10000)%10)), + ('0' + ((ALIGNOF(${TYPE}) / 1000)%10)), + ('0' + ((ALIGNOF(${TYPE}) / 100)%10)), + ('0' + ((ALIGNOF(${TYPE}) / 10)%10)), + ('0' + (ALIGNOF(${TYPE}) % 10)), ']', '\0'}; |
