OrangesGeneratePlatformHeader¶
This module provides the function oranges_generate_platform_header()
and an extensive set of cache variables describing the current target platform.
The header generation command¶
- oranges_generate_platform_header¶
oranges_generate_platform_header (<targetName> [BASE_NAME <baseName>] [HEADER <headerName>] [LANGUAGE <CXX|C|OBJCXX|OBJC|Fortran|ASM>] [SCOPE <PUBLIC|PRIVATE|INTERFACE>] [INSTALL_COMPONENT <componentName>] [REL_PATH <installRelPath>])
Generates a header file containing various platform identifying macros for the current target platform.
The value of each macro in the generated header file will be set from a corresponding cache variable, which allows the user a high level of configurability, and the ability to override specific details about the current platform as needed. The entire set of cache variables used to store platform attributes is initialized when this module is first included. Thus, you can use this module’s cache variables in your CMake scripts without actually generating a header file.
Options:
BASE_NAME
Prefix to use for all macros in the generated header file. Defaults to
<targetName>
.HEADER
Name of the header file to be generated. Defaults to
<baseName>_platform.h
.LANGUAGE
Some of the platform introspection requires specifying a language, because some features may be compiler-specific. For these options, the cache variables are suffixed with
<lang>
(wherelang
is the language in all-uppercase), so that multiple settings can be saved (and overridden) for different languages. Defaults to the value of thePLAT_DEFAULT_TESTING_LANGUAGE
variable.SCOPE
Scope with which the generated header will be added to the target. Defaults to
INTERFACE
for interface library targets,PRIVATE
for executables, andPUBLIC
for all other target types.INSTALL_COMPONENT
An install component the generated header will be added to. This command will not create the install component.
REL_PATH
Path below
CMAKE_INSTALL_INCLUDEDIR
where the generated file will be installed to. Defaults to<targetName>
.
Macros¶
The generated file will contain the following macros, where <baseName>
and <lang>
are all uppercase:
Macro name |
Cache variable |
Value |
Notes |
---|---|---|---|
<baseName>_UNIX |
PLAT_UNIX |
0 or 1 |
|
<baseName>_POSIX |
PLAT_POSIX |
0 or 1 |
|
<baseName>_WINDOWS |
PLAT_WIN |
0 or 1 |
|
<baseName>_MINGW |
PLAT_MINGW |
0 or 1 |
|
<baseName>_LINUX |
PLAT_LINUX |
0 or 1 |
|
<baseName>_APPLE |
PLAT_APPLE |
0 or 1 |
True if the target platform is any Apple OS |
<baseName>_OSX |
PLAT_MACOSX |
0 or 1 |
True if the target platform is desktop MacOS. |
<baseName>_IOS |
PLAT_IOS |
0 or 1 |
True for any iOS-like OS (iOS, tvOS, or watchOS) |
<baseName>_ANDROID |
PLAT_ANDROID |
0 or 1 |
|
<baseName>_MOBILE |
PLAT_MOBILE |
0 or 1 |
True for iOS, watchOS, or Android |
<baseName>_EMBEDDED |
PLAT_EMBEDDED |
0 or 1 |
True if the target is an embedded platform. This defaults to true if CMAKE_SYSTEM_NAME is Generic. |
<baseName>_OS_TYPE |
PLAT_OS_TYPE |
String literal |
A string literal describing the OS type being run. Defaults to one of ‘MacOSX’, ‘iOS’, ‘tvOS’, ‘watchOS’, ‘Windows’, ‘Linux’, or ‘Android’. |
Macro name |
Cache variable |
Value |
Notes |
---|---|---|---|
<baseName>_CLANG |
PLAT_CLANG_<lang> |
0 or 1 |
True if the compiler is Clang or AppleClang |
<baseName>_GCC |
PLAT_GCC_<lang> |
0 or 1 |
|
<baseName>_MSVC |
PLAT_MSVC_<lang> |
0 or 1 |
|
<baseName>_INTEL_COMPILER |
PLAT_INTEL_COMPILER_<lang> |
0 or 1 |
|
<baseName>_CRAY_COMPILER |
PLAT_CRAY_COMPILER_<lang> |
0 or 1 |
|
<baseName>_ARM_COMPILER |
PLAT_ARM_COMPILER_<lang> |
0 or 1 |
|
<baseName>_COMPILER_TYPE |
PLAT_COMPILER_TYPE_<lang> |
String literal |
A string literal describing the compiler used. Either Clang, GCC, MSVC, Intel, ARM, Cray, or Unknown |
Macro name |
Cache variable |
Value |
Notes |
---|---|---|---|
<baseName>_COMPILER_VERSION_MAJOR |
PLAT_COMPILER_VERSION_MAJOR_<lang> |
Numeric literal |
Number representing the compiler’s major version, if available; otherwise, 0. |
<baseName>_COMPILER_VERSION_MINOR |
PLAT_COMPILER_VERSION_MINOR_<lang> |
Numeric literal |
Number representing the compiler’s minor version, if available; otherwise, 0. |
<baseName>_COMPILER_VERSION_PATCH |
PLAT_COMPILER_VERSION_PATCH_<lang> |
Numeric literal |
Number representing the compiler’s patch version, if available; otherwise, 0. |
<baseName>_COMPILER_VERSION |
PLAT_COMPILER_VERSION_<lang> |
String literal |
A string literal describing the version of the compiler being used |
Macro name |
Cache variable |
Value |
Notes |
---|---|---|---|
<baseName>_ARM |
PLAT_ARM |
0 or 1 |
|
<baseName>_INTEL |
PLAT_INTEL |
0 or 1 |
|
<baseName>_CPU_TYPE |
PLAT_CPU_TYPE |
String literal |
A string literal describing the CPU. Either ARM, Intel, or Unknown |
<baseName>_32BIT |
PLAT_32BIT |
0 or 1 |
|
<baseName>_64BIT |
PLAT_64BIT |
0 or 1 |
|
<baseName>_BIG_ENDIAN |
PLAT_BIG_ENDIAN_<lang> |
0 or 1 |
|
<baseName>_LITTLE_ENDIAN |
PLAT_LITTLE_ENDIAN_<lang> |
0 or 1 |
Macro name |
Cache variable |
Value |
---|---|---|
<baseName>_ARM_NEON |
PLAT_ARM_NEON |
0 or 1 |
<baseName>_AVX |
PLAT_AVX |
0 or 1 |
<baseName>_AVX512 |
PLAT_AVX512 |
0 or 1 |
<baseName>_SSE |
PLAT_SSE |
0 or 1 |
Note
Each macro used by this header file will always be defined to a value, so you should use #if
to check their values, and not #ifdef
.
Cache variables¶
- PLAT_DISABLE_SIMD¶
If on, all SIMD-related macros are initialized to 0, instead of attempting to detect features present with the current toolchain and target platform. Defaults to OFF
.
- PLAT_DEFAULT_TESTING_LANGUAGE¶
The language that will be used to initialize the values of language- or compiler-specific variables the first time this module is included. Defaults to CXX
.
See also
- Module
OrangesGenerateStandardHeaders
An aggregate module that includes this one