Platform-dependent compilation of source files


#1

Hi, we’re working on a project that contains platform-specific implementation of a class. The Linux variant needs some extra .c library source files to be compiled, but not the others.

Including these .c source files in the Projucer project, we can compile the code fine on a Linux machine. But these files don’t compile on other platforms, so we really can’t just do it this way.

A few posts here mention this or something similar:
Exclude files per-platform with Projucer?
Different cpp/h for platform in introjucer
(There is actually another link, see comments)

From what I can gather there are three “solutions” here:

  • Inlcuding the .c files in the main project, and manually disable compiling of these files per platform.
    • This is very inconvenient, since we want to keep the Projucer project file version-controlled with the project.
  • Editing each .c file and wrapping them with #ifdef statements.
    • Again, inconvenient, since it involves editing all the library source files.
  • Creating a special .h file, include the .c files, and wrap them with #ifdef. Then include this file in an appropriate place in the project.
    • Not really a fan of this, since this means we’re compiling those .c files with g++, which in most cases is fine, but can sometimes be a pain, and is not recommended.

What I’d like to be able to do, is to add sources in the Linux part of the Config tab in Projucer. This would include compilation of the platform-specific source files in the Makefile, but not to XCode and VS project files.

For reference, our project structure looks something like this:

Project folder
    Builds
        MacOSX
            XCode project files
            Platform-specific source code (.h and .mm files)
        LinuxMakefile
            Makefile
            Platform-specific source code (.h and .c files)
    Source
        Common source files (.h and .cpp files)
    JUCE project file (.jucer)

#2

Can’t put more than two links in the post (?!?!?), so here is the third one: Build-specific source files


#3

Could you put some of your files in a custom JUCE module? Here you can specify platform specific compilation based on the filename:


#4

Thanks, I’ll check this out!

Although this method seems to involve including all the .c files in one .c or .cpp file.


#5

I’ve not tried this myself, but if you read the two paragraphs above the marked line you’ll see that you can have multiple source files.


#6

Thanks, I’ve got it set up this way now. While my module surely does not follow the JUCE guidelines for keeping the filecount small, it’s working.

I haven’t tried compiling it for OSX yet, but having a look at the XCode project file generated by the Projecuer it looks OK.


#7

Thanks for the tip, this is something I’d missed, one of my long-term projects could do with being reorganised into modules in this way.