Conditional Defines
The Elements compiler provides the following defines that can be used with {$IF}
(Oxygene) and #ifdef
(C# and Swift) and related Compiler Directives to do conditional compilation based on compiler version or target platform. The defines listed here are provided intrinsically by the compiler, but they can be joined by further user defines set up in the Project Properties or defined in code via the {$DEFINE}
(Oxygene) or #define
(C# and Swift) Compiler Directive.
The ELEMENTS
Define
The ELEMENTS
define can and should be used to conditionally compile for Oxygene, RemObjects C# and Silver vs. other Pascal, C#, Swift or Java dialects:
ELEMENTS
- Version 7.0 and up, recommendedOXYGENE
- Version 3.0 and up, for all languages, despite the nameADRENOCHROME
- Legacy, version 1.0 and upCHROME
- Legacy, version 1.0 and up
Versions
The following defines are available to check for specific compiler versions. As a general rule of thumb, the defines ending with a version number are only defined for this version and will disappear for future major versions, while defines ending in UP
will remain forever, and can be used to check for "version x and later".
ELEMENTSxxxx
- Where xxxx is the current build number (.2601 and later)ELEMENTS100
- Version 10 onlyELEMENTS90
- Version 9.x onlyELEMENTS80
- Version 8.x onlyELEMENTS70
- Version 7.x onlyELEMENTS100UP
- Version 10 and upELEMENTS90UP
- Version 9.0 and upELEMENTS83UP
- Version 8.3 and upELEMENTS80UP
- Version 8.0 and upELEMENTS70UP
- Version 7.0 and upOXYGENE100
- Version 10 onlyOXYGENE90
- Version 9.x onlyOXYGENE80
- Version 8.x onlyOXYGENE70
- Version 7.x onlyOXYGENE60
- Version 6.x onlyOXYGENE50
- Version 5.x onlyOXYGENE100UP
- Version 10 and upOXYGENE90UP
- Version 9.0 and upOXYGENE80UP
- Version 8.0 and upOXYGENE70UP
- Version 7.0 and upOXYGENE60UP
- Version 6.0 and upOXYGENE50UP
- Version 5.0 and upOXYGENE40UP
- Version 4.0 and upOXYGENE30UP
- Version 3.0 and upVER100
- Version 10 onlyVER90
- Version 9.x onlyVER80
- Version 8.x onlyVER70
- Version 7.x onlyVER60
- Version 6.x onlyVER50
- Version 5.x onlyVER100UP
- Version 10 and upVER90UP
- Version 9.0 and upVER80UP
- Version 8.0 and upVER70UP
- Version 7.0 and upVER60UP
- Version 6.0 and upVER50UP
- Version 5.0 and upVER40UP
- Version 4.0 and upVER30UP
- Version 3.0 and up
Platforms
One of the following will be defined, depending on the target platform.
CLR
- for .NETCOCOA
- for CocoaJAVA
&JVM
- for Java and Java-based Android SDKISLAND
- for Island
Also, defines based on the internal edition code names will be defined as well:
ECHOES
- for .NETTOFFEE
- for CocoaCOOPER
- for Java and Java-based Android SDKISLAND
- for Island
Sub-Platforms
One (or more) of the following will be defined, depending on the sub-platform of your target:
-
For .NET:
NET
– for Classic (non-Core) .NETNETSTANDARD
– for .NET StandardNETCOREAPP
– for .NET Core
-
For Cocoa (Toffee and Island/Darwin)
MACOS
IOS
TVOS
WATCHOS
SIMULATOR
– defined along with one of the above, when building for the iOS, tvOS or watchOS Simulator instead of for a physical device.MACCATALYST
– defined along withIOS
andMACOS
, when building an iOS app for Mac Catalyst.DARWIN
– for all Cocoa projectsTOFFEEV2
– in ToffeeV2 mode
-
For Java:
ANDROID
– defined when building against the Android SDK (i.e.android.jar
instead of the regular JDK).
-
For Island:
LINUX
– for the Linux and Android sub-platformsWINDOWS
– for the Windows sub-platformDARWIN
– for the Apple sub-platforms (macOS, iOS, tvOS, watchOS)ANDROID
– for the Android sub-platformWEBASSEMBLY
– for the WebAssembly sub-platform
Note that ANDROID
will be defined both in Java-based and NDK-based Android projects!
Features
GENERICS
- Defined if Generics are supported, currently on .NET 2.0 and higher, Java, Island and as of Elements 7.1 also for Cocoa.GC
- Defined if the platform uses Garbage Collection, i.e. on .NET and Java on Version 6 and up, as well as on Island.ARC
- Defined if the platform uses Automated Reference Counting, i.e. on Cocoa.
Compiler Platform
On .NET projects only, the following two defines can be
used to distinguish whether the project is being compiled on the
Microsoft .NET platform (DOTNET
) or on Mono (MONO
). Note that
this define only indicates what platform the compiler is being run on,
since no distinction is made between .NET, Mono or other CLR
implementations for the target output.
-
DOTNET
- On .NET only, if the compiler is running on Windows on the Microsoft .NET runtime -
MONO
- On .NET only, if the compiler is running on the Mono runtime
Framework-driven Defines
On Elements for Cocoa, the following defines are
passed to or defined by FXGen and will thus be available via the imported
SDK's rtl.fx
reference. It is important to note
that none of the defines below (in contrast to COCOA
and TOFFEE
) are
defined by the compiler; in theory, a different
rtl.fx
(such as a custom-import with FXGen) could
provide different defines.
__LITTLE_ENDIAN__
__APPLE__
__APPLE_CC__
__MACH__
__OBJC__
__OBJC2__
__TOFFEE__
JSC_OBJC_API_ENABLED
Mac OS X (64-bit)
__X86_64__
– when building for Intel__ARM64__
– when building for Apple\ Silicon__SSE__
__SSE2__
__LP64__
OSX
MACOS
iOS (32-bit)
__ARM__
IOS
iOS (64-bit)
__ARM__
__ARM64__
__LP64__
IOS
iOS Simulator (32-bit)
__I386__
__SSE__
__SSE2__
IOS
IOSSIMULATOR
SIMULATOR
iOS Simulator (64-bit)
__X86_64__
__SSE__
__SSE2__
__LP64__
IOS
IOSSIMULATOR
SIMULATOR
watchOS (32-bit)
__ARM__
WATCHOS
watchOS Simulator (32-bit)
__I386__
__SSE__
__SSE2__
WATCHOS
WATCHOSSIMULATOR
SIMULATOR
tvOS (64-bit)
__ARM__
__ARM64__
__LP64__
TVOS
tvOS Simulator (64-bit)
__X86_64__
__SSE__
__SSE2__
__LP64__
TVOS
TVOSSIMULATOR
SIMULATOR
Note that the above list might change or expand for future SDK versions or for different future platform combinations (such as they did for 64-bit iOS, and may for a future ARM-based Mac OS X).
In addition, any value-less #define
s and any #define
s with a value of "1
" that are present in the Objective-C headers will also be defined if the respective namespaces are in use.
For example, TARGET_OS_IPHONE
and TARGET_IPHONE_SIMULATOR
are two handy defines to check for iOS (vs. macOS), and TARGET_OS_WATCH
can be used to check for watchOS, just as TARGET_OS_TV
can be used for tvOS. Caveat: TARGET_OS_MAC
is also defined on iOS and watchOS, and TARGET_OS_IPHONE
is also on watchOS and tvOS!
Architecture Based Defines
On the Cocoa and Island and platforms, defines are provided for the CPU architecture being built for
I386
– 32-bit Intel (Windows only)X86_64
– 64-bit Intel/AMD (Windows, Linux, macOS and Simulators)ARM64
– 64-bit ARM (macOS, Windows, Linux)