[SOLVED] Managing cross-platform code repositories



  • Hi everyone,

    This thread was lost during the server crash so if you're reading this again, you aren't experiencing deja vu :P

    I've been developing an application predominantly on Windows, but now want to start the port to Linux. However, certain GUI elements need tweaking for the new platform.

    What I'd like to know is what you reckon the "best practice" approach would be for keeping the core functionality in sync and avoiding duplication, while also managing the code that is unique to each platform?

    Before the previous thread disappeared into the ether, someone suggested compilation directives (which I'm not averse to). However, what I'd like to know is what the best way is to do this and with that I mean (1) if there is a way to add the #define to the Qt project file or (2) if one should use some kind of globalinclude.h file where you set your defines?

    Alternatively, is there a way to do it with version control techniques? I'm using Mercurial and initially considered branching, but realised that that would not solve the "duplicate shared code" problem as I'll then still have to update two or more separate branches whenever core functionality changes.

    Your input is appreciated.

    Thanks!


  • Lifetime Qt Champion

    Hi,

    Here are multiple things that can be done. For little pieces of code you can simply use the
    @#if defined(Q_OS_WIN)
    #elif defined(Q_OS_MACX)
    #elif etc...
    #endif@

    construct.

    If you have bigger "implementation details" you can separate things in different cpp files one for each platform i.e. :
    mycoolwidget.cpp <- common implementation
    mycoolwidget_win.cpp <- windows specific stuff
    mycoolwidget_unix.cpp <- linux/os x stuff if both can use the same code
    etc...

    Then in your pro file, use scopes to build the correct set of files.
    If you need your own defines for a platform theres the DEFINES variable

    As for version control, I would avoid branches for that use case, you will indeed end with some code fragmentation unless you're adding a new platform, then it's best to start a new branch for that and once stable get it back in your main branch.

    You can also look at the Qt sources, since they do that for several platforms

    Hope it helps



  • Thanks a lot! This is exactly the entry point I was looking for.


  • Lifetime Qt Champion

    You're welcome !

    Don't forget to update the thread's title to solved so other forum users may know that you have found what you were looking for :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.