How to set up TravisCI for Qt apps

When I started GitQlient and GitQlientPlugin one of the first things I wanted was to setup TravisCI for Qt apps. The main reason is, of course, to have a system that checks a clean build of both projects.

The other reason, however, is that I think its a quite nice environment to deploy your build in GitHub. Locally, your system can be messed up with versions and old objects that are not cleared, etc. By doing it in this way, one is allowed to have a clean build in a really controlled environment. In addition, you can run as much versions and they are deploy independently.

This is post is more a remind me in the future rather than a how to, although I hope people find it useful.

The script

The real script can be found here, but it looks as follows:

I don’t remember exactly where, but I found that splitting the script in install and build scripts is really useful, so you can have platform specific code using the environment variable $TRAVIS_OS_NAME provided by TravisCI.

I use OSX and Linux (since Windows is handled by AppVeyor) so I can test clang and gcc. Apart from that is quite straight-forward:

  • In the install script on Linux, I install all the necessary dependencies but not Qt, the version depends on the distro and I want to select my own version. For MaxOSX I install everything.
  • The build script is really easy to understand since it only sets the necessary environment variables and triggers qmake and then make.
    • After that I copy the generated file since it could be deployed depending on the conditions will see next.

Qt libraries for Linux builds

If you have checked the build script for Linux I have in my repo you will have noticed that I’m getting Qt with wget. The main reason for that is that the images of Linux that Travis has install their own version of Qt.

Since I want a specific version I need to install that by my own. What I’ve done is to pack all the necessary binaries in a zip file and store it somewhere. After that I just need to download the file and set the paths to the correct folder.

By doing this I can achieve building the app with several versions at the same time. The only problem is the size of the zip file: ~75 MB. The structure is everything in a folder and inside it the following tree structure:

  • bin: contains moc, qmake, qt.conf, rcc and uic
  • include: I only need QtCore, QtGui, QtWidgets, QtNetwork & QtConcurrent (because I use QtSingleApplication) and QtTest (for the future)
  • lib: all the libi*, and libQt5 of the above includes
  • mspecks: I included everything but in theory you just need linux-g++
  • phrasebooks, plugins, qml, resources and translations: I need to clean up this folders since I’m pretty sure I don’t need all of them

Install and run TravisCI for Qt

To be able to deploy using TravisCI, it’s necessary to create a token on GitHub. This process wasn’t as intuitive as I expected and that’s the main reason of this post.

The first thing you need to do is to install the TravisCI client. You download id using ruby and following the instructions you can find here. Once that is done, we can create the deployment step in our script.

Deploying on GitHub from TravisCI

As you can see in my script, there is a section called before_deploy and deploy. The first one contains the configuration I set on Git so I can deploy with my normal user info.

The deploy section contains information about what to use to deploy, what to deploy and in which cases. The what is defined by the field file and it’s important that you set the skip_cleanup to true.

At the moment of writing this post, I’m deploying with the prereleases option activated. That means that despite it will appear in the release section of the project on GitHub, it will be marked as pre-release. The last important section is the “on:“. There is where I defined in which case it should deploy: specific condition (linux), if its only when tagging, which repo and branch.

Setting the OAuth key on travis

In the “deploy:” section there is a api_key field that is filled with an encrypted key. That is generated by Travis and that’s why I installed the client. To create a encrypted token that will be added into your script, you just need to log in travis call the commands:

$ travis login
$ travis setup releases

That will modify your script with several options the client will ask you in the terminal.


Djuro says:

I was thinking of doing the same for some of my hobby projects. I never actually tried to set it up, but from what I found out it might also be possible to just run a docker image where you can have all your environment set up once.

Also there appears to be a new service from GitHub that does something similar to TravisCI, but I haven’t been able to figure out what you need to do to setup Qt development environment on it, but it might also be an alternative…

Leave a Reply