How to have a project that can compile on multiple platforms



  • I'm developing an app that is supposed to run on Windows, Mac and Linux.
    As every now and then I would like to verify everything on all platforms, I have done the following to enable me to just compile it (the code is in a shared folder):

    • disabled shadow builds
    • added the following to my .pro file:
      @
      win32 {
      DESTDIR = ../build-Win32
      MOC_DIR = ../build-Win32/moc
      OBJECTS_DIR = ../build-Win32/obj
      }
      macx {
      DESTDIR = ../build-OSX
      MOC_DIR = ../build-OSX/moc
      OBJECTS_DIR = ../build-OSX/obj
      }
      unix:!macx {
      DESTDIR = ../build-Linux
      MOC_DIR = ../build-Linux/moc
      OBJECTS_DIR = ../build-Linux/obj
      }
      @
      This seems to work.

    The problem I'm facing is with the user settings file.
    I don't know how to control that (it seems to be autogenerated), and because I can't use the same one on my different platforms I have to say no (which means don't use) when opening the project and it complains that the user settings is not compatible, so it creates a new one which I have to tweak every time I open the project in a different platform.

    Can this be handled more gracefully?


  • Moderators

    Have you tried shadow building (building outside the source tree) instead of this hackery?

    E.g.:
    @
    mkdir qt-creator-linux-build
    cd qt-creator-linux-build
    qmake ../qt-creator/qt-creator.pro
    @
    Note that the build directory currently has to be the same distance from the root as the source directory (so it has to be next to the source).

    Qt Creator will support you with setting this up.



  • How would that be setup in QtCreator (because I tried and that's what I ended up with my solution).

    But even if it works, I don't think it will resolve the issue with user settings file, as it seems to be platform specific.



  • What we do here, we develop on one platform and we delegate building to controlled environment (buildbox, like cruisecontrol).
    This way, you an independant status of your project, on all platforms that you want to support which reflects exact status of your configuration management.
    Another solution is to build using command line, which doesn't care about "user preferences", which are for QtCreator only:
    @
    qmake -r
    make (or nmake on windows/VC)
    @

    Hope this helps,



  • How do you distribute your code between the different platforms?

    Your xxx.pro.user problem is only an issue, if you copy complete directories or use a shared directory (probably via a network volume/drive). Both are a Bad Idea™...



  • I am using a network drive, since it is part of a very thorough backup policy. Why is that a bad idea?



  • Because you easily can mess up things, let alone modifying one source file on two editors simultaneously.

    I strongly suggest using some (distributed) source code management system for synchronizing things. I personally use mercurial for this, but git and bazaar do the trick too. I would avoid introducing subversion or even CVS on new projects nowadays. They all work on filesystems too. So you can use the network drive as a kind of "central repository" where the actual exchange happens.

    This way you have the advantage that no .pro.user files are checked in and you can manage them on their respective platforms.

    And as a minor advantage: With distributed source control management, you have (at least paratial) backups on every machine involved.

    And everyone wants to have their source code in a SCM anyways, won't they? :-)



  • I guess you're right, even though I'm the only one working on this project.
    So in this scenario, I'd keep my .pro as it is, and just not check in the .pro.user files?



  • [quote author="hsfougaris" date="1301672624"]I guess you're right, even though I'm the only one working on this project.
    So in this scenario, I'd keep my .pro as it is, and just not check in the .pro.user files?[/quote]

    Yep! That's exactly what I do here too.



  • [quote author="Volker" date="1301673063"][quote author="hsfougaris" date="1301672624"]I guess you're right, even though I'm the only one working on this project.
    So in this scenario, I'd keep my .pro as it is, and just not check in the .pro.user files?[/quote]

    Yep! That's exactly what I do here too.[/quote]

    How exactly do you configure Qt on the "other" computers to use the distributed SCM?
    I installed mercurial on my main development PC, created a repository, configured it in QtCreator, and everything works fine...
    I run hg serve on this PC.
    I can pull from the command line of the other PC the project, but what would I specify so it does all this automating pulling/committing (when requested) to the remote repository?
    (I'm new to this so forgive me if this is a stupid question)



  • You could write a script, that is called before make start. But I do not recommend this. Some time you will eventually end up with having modified the sources on both machines. In my opinion, syncing manually is a more reliable approach in this case (think of merge conflicts that need manual resolution).

    On Windows, I use "TortoiseHg":http://tortoisehg.bitbucket.org/ - command line tools on Windows are... ahm.. suboptimal to use :-) They have a Mac OS X port too, but I never tried this - OS X command line (bash to be precise) is a joy to work with.



  • Agreed with Volker : pre build hook to sync your files can lead to madness.

    My advice, if you really want to have a per-commit build on all platforms : put cruise control (or any other continuus integration tool) in place and let it listen to your repository.

    This way, each time you commit (or on demand), you can trigger a build on all your platforms, with an environment which is under better control.

    On a side note, compared to using shared environment on a folder, using a version control manager allows you to revert mistakes :-)



  • The Mercurial/Creator specific part has been moved to "this thread":http://developer.qt.nokia.com/forums/viewthread/4932/


Log in to reply
 

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