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 | |
| parent | aff68423976e2c8a4feb97f19edf6716d271f0f0 (diff) | |
Introduced detection mechanisms to pick the best `alignof` keyword based on language, version and toolchain.
| -rw-r--r-- | xmake/core/package/package.lua | 2 | ||||
| -rw-r--r-- | xmake/includes/check/check_alignof.lua | 27 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/check_alignof.lua | 27 |
3 files changed, 43 insertions, 13 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 81efad731..2a263f65b 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2679,7 +2679,7 @@ function _instance:check_sizeof(typename, opt) return sandbox_module.import("lib.detect.check_sizeof", {anonymous = true})(typename, opt) end --- check the aligment of type +-- check the alignment of type -- -- @param typename the typename -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} diff --git a/xmake/includes/check/check_alignof.lua b/xmake/includes/check/check_alignof.lua index 1c97883c9..11b94965d 100644 --- a/xmake/includes/check/check_alignof.lua +++ b/xmake/includes/check/check_alignof.lua @@ -31,13 +31,28 @@ 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'}; 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'}; |
