https://github.com/friendlyanon/check-type-align
Check the alignment requirement of a type in CMake
https://github.com/friendlyanon/check-type-align
Last synced: 5 months ago
JSON representation
Check the alignment requirement of a type in CMake
- Host: GitHub
- URL: https://github.com/friendlyanon/check-type-align
- Owner: friendlyanon
- Created: 2022-01-23T22:03:11.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-31T01:28:06.000Z (about 1 year ago)
- Last Synced: 2025-08-01T20:13:17.730Z (5 months ago)
- Language: CMake
- Size: 49.8 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CheckTypeAlign
This CMake module works similarly to [CheckTypeSize][1], with the addition of
the `CHECK_TYPE_ALIGN_USE_EXTENSION` cache variable. This can be set to
something like `__alignof__` on Clang or `__alignof` on MSVC to skip detection
or to provide an extension that is not known by the module. Check the
[`CheckTypeAlign.c.in`](cmake/CheckTypeAlign.c.in#L33) source file for known
compilers and their extensions. If you can help expanding the list, please open
an issue.
The only real difference from [CheckTypeSize][1] is due to the way `alignof` is
specified by the C++ and C standards; it cannot accept an expression as its
argument, only a `type-id`. The compiler extensions all support the former,
however the main target is the standard way, so the tests do not cover
expressions. In C++ mode, you can still use `decltype` to convert an expression
to a type.
This module requires CMake >= 3.9.
# Usage
This module is usable as a proper CMake package:
```
find_package(CheckTypeAlign REQUIRED)
check_type_align(int ALIGNOF_INT)
```
Make sure [`find_package`][2] can find it when configuring your project.
[1]: https://cmake.org/cmake/help/latest/module/CheckTypeSize.html
[2]: https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure