Building Qt-4.8.7 x64 on OS X 10.11 with Xcode 7.x

This is an update to my previous “Building Qt-4.8.6 x64 on OS X 10.10 with Xcode 6.x so that it works on OS X 10.6+” with the small difference that I don’t try to support 10.6 anymore (it might still work?). Also note that openssl has been deprecated for a while on Mac OS X and the OS X 10.11 SDK does not ship with the openssl headers anymore. Therefor, openssl support will be disabled by default when you compile with Xcode 7. I have a workaraound for that to restore openssl support.

I set up 3 folders:

Steps:

> cd qt-4.8.7-src
> patch -p1 < ../qt-patches/qt-4.8.7-mac.patch
> cd ../qt-4.8.7-build
> export PATH=/usr/bin:/bin:/usr/sbin:/sbin
> ../qt-4.8.7-src/configure -debug-and-release -nomake examples -no-qt3support -prefix /usr/local/Qt-4.8.7 -arch x86_64 -I "$PWD/../qt-patches/mac_openssl_include"

Notes:

  • the extra include path just point to the openssl headers, now missing from the system.
  • not all examples build, so I disable them.

Build and install:

> make -j3
> sudo make install

Done!

testo – A minimal C++ unit test framework.

For many years, I’ve been using cppunit for my unit tests. It is cross-platform and easy to use. I’ve been quite happy with the results.

Recently, I wanted a tool that would also measure regression in performance, so do some timing of tests, not only give a failed / pass result. I thought of adding that in my current cppunit tests, as some kind of extension, but decided to have a look around, at other unit test frameworks and their review. I was a bit surprise to see the lack of love for cppunit, most review complaining how verbose it is to write new tests.

Here’s a test suite with cppunit:

#include <cppunit/extensions/HelperMacros.h>

class my_test_suite : public CppUnit::TestFixture
{
  CPPUNIT_TEST_SUITE( my_test_suite );
  CPPUNIT_TEST( test_case_1 );
  CPPUNIT_TEST( test_case_2 );
  CPPUNIT_TEST_SUITE_END();

  void test_case_1()
  {
    CPPUNIT_ASSERT( some test );
  }
  void test_case_2()
  {
    CPPUNIT_ASSERT( some more test );
  }
};

CPPUNIT_TEST_SUITE_REGISTRATION( my_test_suite );

To be frank, it is verbose. You have to derive from a base class and use 4 macros just to have a test suite, then declare each test and register them with yet another macro. On the other hand, since I was serious about having unit tests, all my work environments had a test suite template ready to use, usually with a keyboard shortcut, so I rarely, if ever, typed this code, one keystroke and I had a new test suite ready to be filled.

Most of the other unit test frameworks were not as verbose, but they rely on hiding the code in even more complex macros to the point where the code does not look like C++ anymore (see boost.test or googletest for example).

I don’t like macros and I was wondering if I could do better, do a C++ unit test framework that would 1) be as minimal as possible in its syntax, 2) not rely on macros (as much as possible) and 3) record performance of some tests. It has to produce result similar to what I was getting with my simple usage of cppunit.

Introducing testo.

Here the same example as before with testo:

#include <testo/testo.h>

struct my_test_suite
{
  void test_case_1()
  {
    TEST_ASSERT( some test );
  }
  void test_case_2()
  {
    TEST_ASSERT( some more test );
  }
};

REGISTER_TESTS( my_test_suite,
            test_case_1,
            test_case_2 );

Notice: no base class to inherit from, only 1 macro to register all. That’s it! The test runner will pick this up and give exactly the same result as with cppunit.

Why still some macros ? Well, I could get rid of the REGISTER_TESTS macro, but it would make test suite registration much more verbose, something like:


REGISTER_TESTS< my_test_suite >(
         &my_test_suite::test_case_1, "test_case_1",
         &my_test_suite::test_case_2, "test_case_2" );

So I’ll live with it for now. If proposal N3951 for adding reflection to C++ is ever accepted, I will be able to get rid of it, but that’s for a distant future.

TEST_ASSERT & cie are still macros so that they can expand the __FILE__ and __LINE preprocessor value when compiling.

Other implemented features:

  • the test suite can have a setup() and/or teardown() method. setup() will be called before each tests and teardown() will be called after each tests.
  • a test method’s name must start with « test_ » or « timedtest_ ». The method name is the name of the test in the output. timedtest have their performance recorded.
  • the name of the class is taken as the test suite name, unless the class implement a name() const method. If so, the return value of name() is used.

Hopefully, some more features coming. For instance, I’d like to record all result in a local database and also have some web UI visualisation tool. More customisable output. etc.

Anyway, it is complete enough now and has fully replace cppunit in all my unit tests.

Code on github.

Building Qt-5.3.2 on Windows with VS2013 so that it works on WinXP+

Since VS requires all C++ libraries to be compiled with the same version, this is a complicated one. To get everything out of Qt, we need to compile openssl and icu ourselves, all with the WinXP SDK. Let’s start.

For this, I have a folder C:\Qt where all I need is installed (python, perl, icu, ruby and jom). I uncompress Qt as C:\Qt\qt-5.3.2-src, I will build from C:\Qt\qt-5.3.2-build and install in C:\Qt\qt-5.3.2. Adjust all paths to your convenience, if you want both a 32 bits and 64 bits builds, you’ll need a different build and install folder (like C:\Qt\qt-5.3.2-buildx64 and C:\Qt\qt-5.3.2-x64).

First, open the VS2013 Command Promt, 32 or 64 bits depending on which you want to build.
Set SDK for WinXP (Note: there is a Bin64 and Lib64 for 64 bits builds, shown here are the paths for a 32 bits build).

> set INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Include;%INCLUDE%
> set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib;%LIB%
> set PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Bin;%PATH%
> set CL=/D_USING_V110_SDK71_

Then, you need icu and you need cygwin to build icu. So from the VS2013 cmd-line, add cygwin and compile icu:

> set PATH=%PATH%;C:\cygwin64\bin;
> cd icu-src
> bash ./runConfigureICU Cygwin/MSVC --prefix=C:/Qt/icu
> make
> make install

Note: I’m installing icu in C:/Qt/icu, if you do both 32 and 64 bits build you’ll need to install in 2 different folders (like icu32 and icu64).

Now, remove cygwin from path:

> set PATH=%PATH:C:\cygwin64\bin;=%

Need perl, python and ruby, just install them. Make sure they’re in your PATH.

> set PATH=C:\Qt\Perl64\bin;%PATH%
> set PATH=C:\Qt\Python27;%PATH%
> set PATH=C:\Qt\Ruby193\bin;%PATH%

Need openssl, to compile it:

> cd openssl-src-folder
> perl Configure VC-WIN32 no-asm --prefix=C:\Qt\openssl
> ms\do_ms
> nmake -f ms\ntdll.mak
> nmake -f ms\ntdll.mak install
> set INCLUDE=C:\Qt\openssl\include;%INCLUDE%

Note: I install openssl in C:\Qt\openssl, like for icu, take care of not mixing 32 and 64 bits builds.

Need icu’s include, bin and lib (or bin64, lib64 if a 64 bit build).

> set PATH=C:\Qt\icu\bin;%PATH%
> set PATH=C:\Qt\icu\lib;%PATH%
> set INCLUDE=C:\Qt\icu\include;%INCLUDE%
> set LIB=C:\Qt\icu\lib;%LIB%

Add some qt tools:

> set PATH=C:\Qt\qt-5.3.2-src\gnuwin32\bin;%PATH%

Configure and compile:

> cd C:\Qt\qt-5.3.2-build
> ..\qt-5.3.2-src\configure.bat -icu -debug-and-release -nomake examples -prefix c:\Qt\qt-5.3.2 -platform win32-msvc2013 -force-debug-info -target xp
> jom
> jom install
> jom generate_docs
> jom qch_docs
> jom install_qch_docs

Note: -target xp will make an XP compatible build, -force-debug-info will give us .pdb files even for the release dlls.

Done!

The resulting Qt 5.3.2 can be deployed on Windows XP or better.

Building Qt-5.3.2 x64 on Mac OS X 10.10 with Xcode 6.x so that it works on 10.6+

The problem with deploying on Mac OS X 10.6 is that it does not have libc++ installed. Therefor, you have to avoid enabling C++11 in the build of Qt itself.
We will do a shadow build, the sources are in qt-5.3.2 and we’ll build in qt-5.3.2-build.

Remove non-Apple tools from your PATH (I have macports installed):
> export PATH=/usr/bin:/bin:/usr/sbin:/sbin

Configure:
> cd qt-5.3.2-build
> ../qt-5.3.2/configure -debug-and-release -prefix /usr/local/Qt-5.3.2 -nomake examples -sdk macosx10.9 -no-c++11

Note: if you remove the ‘-no-c++11’ it will link against libc++ and require 10.7+.

Build & install with documentation:
> make
> sudo make install
> make generate_docs
> make qch_docs
> sudo make install_qch_docs

Done!

Note that with such a build, you can use C++11 language constructs in your code, it’s just the Standard Library that will not be up to C++11 standard.
i.e. language construct like this will work:
for ( auto it : vec ){}
but any new classes or methods from STL will not be available (like std::thread, etc).

Building Qt-4.8.6 x64 on Windows with VS2013 so that it works on Win7+

Easy one. I don’t need WinXP support for 64 bits, so it’s straight forward. You’ll need VS2013 and perl install (I use ActivePerl 64 bits). We’ll do a shadow build, for this I have Qt 4.8.6 sources in C:\Qt\qt-4.8.6-src, I’ll build in C:\Qt\qt-4.8.6-build and install C:\Qt\qt-4.8.6-x64.

Start the VS2013 x64 Command Prompt.

Remove cygwin from PATH:
> set PATH=%PATH:C:\cygwin\bin;=%

We need perl for shadow build:
> set PATH=C:\Qt\Perl64\bin;%PATH%

Configure, build and install:

Building Qt-4.8.6 x32 on Windows with VS2013 so that it works on WinXP+

You will need VS2013 (express works fine) and the Windows SDK v7.1A. You also need perl, I use ActivePerl 64 bits and my qt-4.8.6-win.patch (can be found here https://github.com/sandym/qt-patches). We’ll do a shadow build, for this I have Qt 4.8.6 sources in C:\Qt\qt-4.8.6, I’ll build in C:\Qt\qt-4.8.6-build and install C:\Qt\qt-4.8.6-x32.

First patch the source code, I do that from a cygwin shell:

> cd /cygdrive/c/Qt/qt-4.8.6
> patch -p1 --binary < ../qt-4.8.6-win.patch

Start the VS2013 x86 Native Tools Command Prompt.
Remove cygwin from PATH.

> set PATH=%PATH:C:\cygwin\bin;=%

Set SDK for WinXP.

> set INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Include;%INCLUDE%
> set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib;%LIB%
> set PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Bin;%PATH%
> set CL=/D_USING_V110_SDK71_

We need perl for shadow build:

> set PATH=C:\Qt\Perl64\bin;%PATH%

Configure, note that this is the configuration I use and know to work, you might have some luck with something different, but some do fail. You’re on your own if you do it differently.
> cd C:\Qt\qt-4.8.6-build
> ..\qt-4.8.6\configure.exe -prefix C:\Qt\qt-4.8.6-x32 —debug-and-release -no-qt3support -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-libtiff -no-libmng -no-dbus -no-nis -webkit -platform win32-msvc2013

Build and install:
> jom.exe
> jom.exe install

Done!

Building Qt-4.8.6 x64 on OS X 10.10 with Xcode 6.x so that it works on OS X 10.6+

Mostly for my own benefit, but might be useful to others.

First, you will need the latest Xcode and the latest Qt 4 release source code from http://www.qt.io, at the time I wrote this, it’s Xcode 6.1.1 and Qt 4.8.6. You will also need my patch to Qt (qt-4.8.6-mac.patch, can be found here https://github.com/sandym/qt-patches).

We will do a shadow build, that is we build out of the Qt source tree.  For this, I decompress Qt in a folder named qt-4.8.6 and I create a folder named qt-4.8.6-build next to it. So I have 2 folders, qt-4.8.6 (the sources) and qt-4.8.6-build (empty, where we will build) and a file (qt-4.8.6-mac.patch). Let’s start.

From the Terminal, first apply the patch to the source tree:
> cd qt-4.8.6
> patch -p1 < ../qt-4.8.6-mac.patch

You should make sure to remove all non-Apple tools you might have installed (like Macports in my case):
> export PATH=/usr/bin:/bin:/usr/sbin:/sbin

Configure, note that this is the configuration I use and know to work, you might have some luck with something different, but some do fail. You’re on your own if you do it differently.
> cd ../qt-4.8.6-build
> ../qt-4.8.6/configure -debug-and-release -no-qt3support -prefix /usr/local/Qt-4.8.6 -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-libtiff -no-libmng -no-dbus -no-nis -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -arch x86_64

Build and install:
> make -j3
> sudo make install

Done!