Compiler Directive

Hi all, long shot, but don’t ask, don’t get.

Is it all possible to have a

#if build-a Then
// compile this code
#endif

#if build-b Then
// compile this code
#endif

Issue being I have some code that’s used across multiple projects but some code is reliant on other stuff being in the project - would be good to somehow get the compiler not to include these via a directive…

Regards,
Dave.

You can use any included or custom Constant for Conditional compilation in Xojo.

1 Like

Thank you so much Ricardo!

1 Like

Here’s what I do:

  1. Create a module called BuildSwitches
  2. Put protected Boolean constants in there for features you want to turn on or off (let’s say for example kProFeature)

Now your code can be

#if BuildSwitches.kProFeature
    // run pro code
#EndIf

You can change these constants at build time by using a build script:

ConstantValue("BuildSwitches.kProFeature") = "False"

5 Likes