Exclude files per-platform with Projucer?


#1

Very similar to this thread which got no responses: Different cpp/h for platform in introjucer

Is there any way to exclude certain files per-platform within Projucer? I have a feature that only works in OSX using source file libraries that reference OSX-specific APIs, so I want to exclude the relevant files in WIndows builds. I could see an interface for this living in the Files tab of Projucer in the Group view.

Is there a recommended way to do something like this? I see a few options:

  • Wrap the library code in #ifdefs (pretty gross to custom edit a library)
  • Maintain multiple Projucer projects (not ideal)
  • Create a post-Projucer script that I run to edit the generated project files and delete the unwanted files (unfortunate to add this extra step)

I could also compile the libraries down to lib files and only link them in for the desired platforms, and then platform #ifdef out the calls into them, but I like having them as code. Maybe that’s my problem, though, and I should go that way.


Platform-dependent compilation of source files
#2

Not really, after trying many different systems over the years, I found that to be the best way in practice as long as you do it cleanly.

If you just have a small amount of platform-specific code, just using inlined #ifs to enable bits of it is both simplest and clearest. If you have really large amounts, then putting it in different files and including them conditionally is a good approach, e.g. https://github.com/julianstorer/JUCE/blob/master/modules/juce_gui_basics/juce_gui_basics.cpp#L260


#3

Quite simple:

Disable the lib .cpp file compile by unchecking the file when its directory is selected in the Projucer

Then create a 2nd .cpp file that selectively #includes the first file depending on your platform.


#4

Excellent, I like this #include wrapper approach, it allows me to #ifdef the library code out without actually editing the library code. Thanks for the advice!