Platform compiler directives¶
Include: Built-in (no Use statement required)
Platform compiler directives are boolean conditional-compilation symbols that identify the target platform at compile time. Use them with #IFDEF, #IFNDEF, #IF, #ELSE, and #ENDIF to include or exclude code for a specific platform before the program is compiled.
Compiler directives are resolved once, when the code is compiled. This is different from RuntimePlatformId, which resolves at run time and lets a single cross-platform build branch its behavior per platform. Use a compiler directive when code must not be compiled at all for a given target (for example, code that calls a Windows-only external DLL); use RuntimePlatformId when the same compiled program needs to behave differently depending on where it is currently running.
Directives¶
| Directive | True when |
|---|---|
IS$CROSS_PLATFORM |
The code is compiled for the cross-platform runtime. Not defined when compiling with the DataFlex Windows toolchain. |
IS$PLATFORM_WEBASSEMBLY |
The code is compiled for WebAssembly. |
IS$PLATFORM_LINUX |
The code is compiled for Linux. |
IS$PLATFORM_MACOS |
The code is compiled for macOS. |
IS$PLATFORM_WINDOWS |
The code is compiled for Windows on the cross-platform runtime. |
IS$PLATFORM_UNIX |
The code is compiled for Unix / FreeBSD. |
IS$PLATFORM_WINDOWS is not the same directive as IS$WINDOWS. IS$WINDOWS is the opposite of IS$WEBAPP on the DataFlex Windows toolchain — it distinguishes a Windows desktop client build from a Workspace (WebApp) build, not the target operating system.
Example¶
#IFDEF IS$CROSS_PLATFORM
// Techstack specific code here
#ELSE
// Windows runtime code here
#ENDIF
Directives can also be nested to branch per target platform within the cross-platform runtime:
#IFDEF IS$CROSS_PLATFORM
#IFDEF IS$PLATFORM_MACOS
// Code that only compiles into a macOS cross-platform build
#ENDIF
#IFDEF IS$PLATFORM_WEBASSEMBLY
// Code that only compiles into a WebAssembly build
#ENDIF
#ELSE
// Code that only compiles with the DataFlex Windows toolchain
#ENDIF