For doing a demonstrating project, I’d like to create code that can be used as a VST2 and a VST3.
While JUCE hides most of the complexity from the user, in certain points I need to compile different code for VST2 vs VST3.
I supposed there would be #define some variable that could be used for deciding this.
I found e.g. “JucePlugin_Build_VST3”.
But when deleting the build folder and then building for either “VST” or “VST3”, in both cases, #if JucePlugin_Build_VST3 is true.
I am not knowledgeable enough regarding CBuild to easily find out what the detailed effect of requesting either build setting in VS Code.
Any help ?

To keep compile times low, all the code shared between the different formats is only compiled once into a static library. So at the time when the shared code target gets compiled there is no such define you are looking for. The compilation of the format specific targets is then performed afterwards and the shared library is linked to each of them.

To achieve what you are trying, you basically have two options here:

  1. Creating two projects from the same codebase, each only for one format and set different defines in both. If you are working with the Projucer, it means you need to keep two individual projects in sync. If you are using CMake this is more straightforward, simply create two format specific targets in the same project and apply the same settings to both.
  2. Use runtime conditions instead of compile time conditions to take format specific code paths. The runtime impact might be relatively low compared to compile time branching, just go and profile it to see if you can see any difference at all in a release build. This way you have shorter compile times and only a single project to maintain, which is handy especially if you are using the Projucer.

I see.
so I’ll do
(3) use my own #define macro in the processor header file :slight_smile:

So what exactly workflow do you have in mind when you say

? Are you planing to manually set it there before compiling either VST or VST3?

Seems to be the only way.
Not a big deal as this is just a Demo projects for others to see how to do certain things using Juce.

Use runtime conditions instead of compile time conditions to take format specific code paths.

How can I detect if I’m a Vst2 vs a VST3 in runtime, so that I can show a message if it was not compied as desired.

You can check the wrapperType public member of your AudioProcessor once it has been created

Great. Thanks, I’ll check out ASAP