Qt, QMake and Mac Os X SDKs after the Xcode 4.3 update

March 20, 2012

Mac Os X finally gained the capability to automatically manage and update Xcode installations with the Xcode 4.3 update. A couple of changes are introduced by the new version that caused problems reported all over the place. Read more for the various things that need to be taken care of for a smooth Qt-on-Mac development experience 🙂

There are a couple of changes that we ran into so far and that may require some intervention. With the update the developer tools that previously were installed in /Developer are now  located in a path relative to the Xcode app bundle. The command line tools are installed and updated from within Xcode. The xcodebuild tool used for command line builds needs to be reconfigured to reflect this. With the location of the Developer directory, the path to the Mac OS X SDKs which is often referenced in QMake .pro files has changed.

Xcode 4.3, installation and follow-up steps

When installing Xcode 4.3, it will offer to clean up existing previous Xcode installations. This is recommended, since before 4.3, the Xcode package installed elements of itself in various locations on the file system. If those are left behind they may be detected erroneously later on and create conflicts. Once this step is complete, the /Developer directory will be gone. This is where the trouble starts if, for example, the Mac OSX SDK was selected in QMake .pro files by its path, as recommended here.

Before that can be fixed, the Unix command line tools need to be installed. Previously, those were an optional part of the Xcode installation. They now need to be installed from within Xcode. The upside is that Xcode will also automatically check for updates to the tools now, which it did not do before. After the installation is complete, run Xcode, go to Preferences->Downloads, and in the Components tab install the command line tools. You now have a make tool again.

MacPorts, xcodebuild and the Developer directory

The xcodebuild command line tool is used to build Xcode projects without needing to run the IDE. It is used in MacPorts to build some of the native Mac projects. When trying to self-update the MacPorts installation after installing Xcode 4.3, it will complain that xcodebuild fails:

mirko@silberpfeil: >sudo port selfupdate
Warning: xcodebuild exists but failed to execute
---> Updating MacPorts base sources using rsync
MacPorts base version 2.0.4 installed,
MacPorts base version 2.0.4 downloaded.
---> Updating the ports tree
---> MacPorts base is already the latest version

To fix it, use the xcode-select command to point xcode-build to where the Developer directory is now located. It is in the Xcode application bundle at /Contents/Developer. Run “sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer”. After that, MacPorts should stop complaining:

mirko@silberpfeil: >sudo port selfupdate
---> Updating MacPorts base sources using rsync
MacPorts base version 2.0.4 installed,
MacPorts base version 2.0.4 downloaded.
---> Updating the ports tree
---> MacPorts base is already the latest version

QMake .pro files and the Mac OSX SDK

When we tried to rebuild our projects in Qt Creator after the Xcode update, everything went horribly wrong because all the Mac OSX SDK headers could not be found anymore. The reason was the following line in our QMake project file:

macx:QMAKE_MAC_SDK = /Developer/SDKs/MacOSX10.6.sdk

Qt all the way to version 4.8 still does not fully support the OSX Lion (10.7) SDK. It issues compiler warnings when trying to use it. Because of that it is recommended to explicitly specify the target OSX SDK version to be 10.6 (or earlier, if the project requires backward compatibility). Since the line above silently failed when the SDK is not installed at that location, it was changed to the following:

macx {
    MAC_SDK  = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk
    if( !exists( $$MAC_SDK) ) {
        error("The selected Mac OSX SDK does not exist at $$MAC_SDK!")
    }
    macx:QMAKE_MAC_SDK = $$MAC_SDK
}

Assuming the location of the SDK does not change too often, this should be good for a while. QMake will now fail if a SDK is specified that is not installed, too.

Standalone command line tools installation for Qt Creator

At last, for those who only work on Macs with Qt in Qt Creator, a full Xcode installation is not required anymore. Besides the fact that this will save each of us a whooping $5.00 for the Xcode license in the App Store, only installing the command line tools is a much smaller download. The downside is that this package does not provide update notifications. To only install the command line tools, download and install the package from https://developer.apple.com/downloads/index.action.

Hope this helps. If there are other issues with the Xcode 4.3 update and Qt, feel free to comment.

@mirkoboehm • Mirko on LinkedIn • @Endocode

Image credit: Yuko Honda, MacOS, license