Code/project management for cross-platform oF project

Howdy,

I’m currently working on a project that I’d like to target for desktop (OSX, Windows), iOS, and Android, and am looking for advice on code and project management practices.

What I’m hoping to do is maintain project files for different platforms (e.g. XCode for Mac/iOS, VS for Windows, and Eclipse for Android). I don’t foresee the project settings change that much over time in terms of included Addons etc, but it would be nice to make changes to the basic ofApp code and propagate the changes to each platform-specific project without manually copy+pasting code each time. My current solution is to have the same ofApp files, but with #ifdef TARGET blocks that contain platform specific code. (This raises a minor issue with the iOS version where they are .mm files and not .cpp, I guess…).

At this point this project is not so complicated that manually copy+pasting chunks of updated code for each deployment is out of the question, but it would be nice to think about scaling things up in the long run. (and I guess then project file generation becomes a consideration as well).

If anyone else has any general comments, alternative solutions, or links they can point me to, I’d love your input!

Thanks in advance,

Johnty

3 Likes

For the code, A way of doing it is keeping your main oF app free of OS/Environment calls and use a OS Specific upper layer to communicate with such things. Then create a OS specific layer above this core oF App, that contains OS Specific calls as well as a member which is your oF App. This OS Specific layer can then forward on all events down to your oF app. Then you need a way for the oF App to communicate with this layer (you can use ofEvent).

The above idea eliminates the need for .mm files breaking your android builds as you can use the iOS layer as such to do all of the objective-c calls.

Have a look at how the core manages this for some ideas.

Heres a breakdown of above

  1. main.cpp/main.mm - using preprocessor commands here to target right OS layer app to run
  2. osLayeriOS.mm/osLayerAndroid.cpp/osLayerOSX etc- OS Specific Layer App (passes all events down to the target app, creates the app as well) (You will need to create one of these for each target architecture)
  3. Your app. Communicates with above using ofEvent or direct access ptr. (pure c++)

For the Data, bin/data is okay for most platforms, until you get to Android, where the clean script will delete the whole bin/ folder. So be careful of that. There has been some ideas and solutions to this, I just make sure to have all my project data committed to git before cleaning, but as a good practice, if you are targeting android, put a copy of your bin/data in a /data folder and copy it over.

4 Likes

awesome. thank you very much!!

use google drive

download the master repository drag it in your google drive folder and you will have the same CORE in both Windows and Macintosh/linux

I always modify the core, so last thing I need is linking and copy pasting while writing code.

just copy the master branch and go to master/scripts/ there you will find templates for Visual Studio Codeblocks Xcode etc.

duplicate them and create your project as you please
(following what danoli3 wonderfully describes)

Your goal is
any modifications you make to the core or your code, to be INSTANTLY available and linked in multiple machines and platforms so that
with a single click - be able to compile and test your code.

stay away from git,
you will loose data.

Basically you should have your entire program organized like openFrameworks and linked properly in all platforms that you just then implement inside your ofApp.cpp / ofApp.mm etc,

something like
like:

void ofApp::draw(){
myAwesomeProject.draw();
}

pro tip:

backup your code in an offline drive weekly or daily (before you start working - while you drink your coffee) backup your source code folder
also
make sure when you edit your code in one platform let’s say Codeblocks you have Xcode closed. otherwise you will have duplicates/conflicts . but you will never loose data.

1 Like

Hi there, this is all really interesting stuff.
At the stage I’m at now i have a rudimental app that works universally on iOS and on OS X. I’m going through the process of getting it to work on windows and android.
Heres my main.mm, instead of doing ofRunApp(new ofApp); for all of them like I’ve done below, should i be doing that with an os specific instance? I’m not sure what that would look like

int main() {
#ifdef _WIN32
    //define something for Windows (32-bit and 64-bit, this part is common)
    ofSetupOpenGL(768, 1024, OF_FULLSCREEN);
    ofRunApp(new ofApp);
#ifdef _WIN64
    //define something for Windows (64-bit only)
    ofSetupOpenGL(768, 1024, OF_FULLSCREEN);
    ofRunApp(new ofApp);
#endif
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
    ofAppiOSWindow * iOSWindow = new ofAppiOSWindow();
    iOSWindow->enableRendererES2();
    iOSWindow->enableRetina();
    iOSWindow->enableHardwareOrientation();
    iOSWindow->setOrientation(OF_ORIENTATION_90_RIGHT);
    ofSetupOpenGL(iOSWindow, 768, 1024, OF_FULLSCREEN);
    ofRunApp(new ofApp);

    // iOS Simulator
#elif TARGET_OS_IPHONE
    ofAppiOSWindow * iOSWindow = new ofAppiOSWindow();
    iOSWindow->enableRendererES2();
    iOSWindow->enableRetina();
    iOSWindow->enableHardwareOrientation();
    iOSWindow->setOrientation(OF_ORIENTATION_90_RIGHT);
    ofSetupOpenGL(iOSWindow, 768, 1024, OF_FULLSCREEN);
    ofRunApp(new ofApp);

    // iOS device
#elif TARGET_OS_MAC
    ofSetupOpenGL(1024, 768, OF_WINDOW);
    ofRunApp(new ofApp());
#else
    // Unsupported platform
#endif
#elif __linux
    // linux
#elif __unix // all unices not caught above
    // Unix
#elif __posix
    // POSIX
#endif
}
1 Like