Difference between revisions of "HowtoQt"

From WebOS Internals
Jump to navigation Jump to search
m
Line 179: Line 179:
  
  
 +
=== 3.4 Cross-compile ===
  
---------------------- patch transformed driver
 
  
 +
Now we can configure and cross-compile Qt. The lines below configure Qt to install in ~/qte-48:
  
 +
# '''cd ~/qt-everywhere-opensource-src-4.8.0'''
 +
# '''./configure -v -prefix ~/qte-48 -embedded arm -platform qws/linux-x86-g++ -xplatform qws/linux-webos -depths 16,24,32 -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-nis -no-iconv -no-dbus -no-cups -no-largefile -no-accessibility -no-gtkstyle -no-qt3support -qt-gfx-vnc -plugin-gfx-vnc -no-glib -qtlibinfix 48 -xmlpatterns -exceptions -opensource -make libs -nomake tools -nomake demo -nomake examples -nomake docs -webkit -javascript-jit -script -scripttools -declarative -openssl -qt-gfx-transformed'''
 +
# '''make -j4'''
 +
# '''make install'''
  
 +
Hopefully you've made it so far without problems! You now have Qt in ~/qte-48.
  
To do:
 
# V Get and untar the source
 
# Set-up the mkspecs
 
# Get the webos plugins/gfxdrivers -> credit original author -> link to the updated version
 
# modify the build stuff
 
# patch the transformed driver (?)
 
# ./configure command line
 
# make make install
 
# something on what's the outcome
 
  
=== 3.x WebOS gfxdrivers ===
+
== 4. Compiling Qt apps ==
 
 
== 4. apps ==
 
  
 
== 5. deploy ==
 
== 5. deploy ==

Revision as of 23:13, 7 February 2012

This document is not yet complete - stay tuned

Qt and QML on WebOS devices

This document explains how to set-up Qt 4.8 (Trolltech/Nokia's cross-platform application and UI framework) on WebOS devices, and then how to cross-compile Qt or QML apps.

This guide assumes:

  • a Linux development environment (here Kubuntu 11.10 running in virtualbox on a win7 host)
  • Qt 4.8 (the process for Qt 4.7.x is mostly identical; no idea for Qt 5)
  • OpenSSH running on the webos device to scp files to it
  • The reasonable development tools

The steps include:

  1. Getting and setting-up the Palm PDK
  2. Optionally: completing the PDK with some missing includes
  3. Getting Qt 4.8, setting it up for cross-compilation
  4. Cross-compilation of Qt 4.8
  5. Updated webos port of Qt
  6. Application tweaks to look for libs in the right places

1. Getting and setting up the Palm PDK

Qt is cross-compiled with the official Palm PDK. The PDK plays nice: it can be installed alongside the webos internals WIDK without conflicts; there is no need to modify paths or environment variables.

Note that I haven't "fully" installed the PDK. In particular I haven't set-up the emulator. The basic stuff needed are: the arm gcc toolchain, and novacom to communicate with the device. VirtualBox can be skipped. Java may be necessary.

  1. Read about the Palm SDK 3.05 and the installation procedure. Follow the instructions on there. But essentially this boils down to:
  2. Download novacom from that page
  3. Download the SDK from that page
  4. Install novacom and the SDK following the instructions. I.e.:
    1. sudo dpkg -i palm-sdk_3.0.5-svn528736-pho676_i386.deb
    2. sudo dpkg -i palm-novacom_1.0.80_i386.deb
  5. The SDK is now in /opt/PalmPDK

You may check that all is fine so far (or skip this - this is simply to step-by-step see if all is ok):

  1. You can invoke gcc or g++ from the PDK arm toolchain to compile some test program. E.g. /opt/PalmPDK/arm-gcc/bin/arm-none-linux-gnueabi-g++ hello.cpp -o hello
  2. You can copy this file to the usb drive on the device: scp hello root@ip.address.of.device:/media/internal
  3. You can go log on the device with novaterm: novaterm
  4. You can run your test program: /media/internal/hello

If that works then on to the next steps.


2. Optional: completing the PDK with some missing includes

The Palm PDK contains an arm toolchain which can be used as-is to cross-compile Qt. This step can be skipped, unless you want maximum performance with JavaScript in WebKit.

There is one issue with the Palm PDK. The Qt configuration script relies on the existence of one include file - /opt/PalmPDK/include/asm/hwcap.h (actually more includes in the /opt/PalmPDK/include/asm directory are needed) - to know whether programs can identify the characteristics of the CPU, such as the availability of Neon instructions.

Without these includes, Qt will cross-compile and work, but the just-in-time JavaScript compiler in WebKit will be deactivated. This decreases JavaScript performance by a factor ~3.

Therefore the recommended approach is to provide the missing include files. These files can be found in the CodeSourcery arm toolchain.

  1. Download the arm toolchain "Sourcery G++ Lite 2009q3-67 for ARM GNU/Linux" from Mentor Graphics' website. You need to register to download, but it's free. Make sure you get the ARM GNU/Linux Release (not the ARM EABI release!). The file you get should be called arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  2. Untar this file: tar xvfj arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  3. Copy the entire include/asm directory to the PalmPDK: cp -r arm-2009q3/arm-none-linux-gnueabi/libc/usr/include/asm /opt/PalmPDK/include

You're set!

3. Getting Qt 4.8, setting it up for cross-compilation

This step gets the Qt 4.8 sources, and sets-up Qt for cross-compilation using the Palm PDK.

3.1 Get the Qt sources

  1. Cd to your home directory: cd ~
  2. Get the Qt 4.8 sources: http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.8.0.tar.gz
  3. Untar: tar xvfz qt-everywhere-opensource-src-4.8.0.tar.gz

3.2 Qt mkspecs for WebOS

We set-up the mkspecs for WebOS (compiler parameters required for cross-compilation):

  1. Cd to the qws mkspecs: cd ~/qt-everywhere-opensource-src-4.8.0/mkspecs/qws
  2. The WebOS mkspecs are mostly the same as the linux-arm-gnueabi-g++ mkspecs. So we copy them and modify them afterwards: cp -r linux-arm-gnueabi-g++ linux-webos
  3. Edit the linux-webos mkspecs to set-up the cross-compiler path and other build parameters. E.g. vi ~/qt-everywhere-opensource-src-4.8.0/mkspecs/qws/linux-webos/qmake.conf. This file must look like this:


 
#
# qmake configuration for WebOS builds with arm-linux-g++
#

#for 4.7.4:
#include(../../common/g++.conf)
#include(../../common/linux.conf)
#include(../../common/qws.conf)

# for 4.8
include(../../common/linux.conf)
include(../../common/gcc-base-unix.conf)
include(../../common/g++-unix.conf)
include(../../common/qws.conf)

# modifications to g++.conf
#Toolchain

#Base directory of gcc toolchain

GCCBASE                 = /opt/PalmPDK/arm-gcc/bin
TSLIB_INCDIR            = /opt/PalmPDK/include
TSLIB_LIBDIR            = /opt/PalmPDK/device/lib


#Compiler Flags to take advantage of the ARM architecture
QMAKE_CFLAGS_RELEASE    = -O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize
QMAKE_CFLAGS_DEBUG      = -O0 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp

QMAKE_CXXFLAGS_RELEASE  = -O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize
QMAKE_CXXFLAGS_DEBUG    = -O0 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp

# For official pdk
QMAKE_CC                = $$GCCBASE/arm-none-linux-gnueabi-gcc
QMAKE_CXX               = $$GCCBASE/arm-none-linux-gnueabi-g++
QMAKE_LINK              = $$QMAKE_CXX
QMAKE_LINK_SHLIB        = $$QMAKE_CXX
QMAKE_RANLIB            = $$GCCBASE/arm-none-linux-gnueabi-ranlib

# modifications to linux.conf
QMAKE_AR                = $$GCCBASE/arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY           = $$GCCBASE/arm-none-linux-gnueabi-objcopy
QMAKE_STRIP             = $$GCCBASE/arm-none-linux-gnueabi-strip


QMAKE_INCDIR = $$TSLIB_INCDIR 
QMAKE_LIBDIR = $$TSLIB_LIBDIR 
QMAKE_LIBS   += -lrt -lz 

QMAKE_LFLAGS += -Wl,--allow-shlib-undefined 

load(qt_config)


3.3 gfxdrivers plugin for WebOS

Qt embedded needs a gfxdrivers plugin which allows Qt to show things on a screen, get keyboard input and mouse events. This step gets the WebOS Qt gfxdrivers plugin.

The initial plugin version was written by Darron Black [1,2] and it uses SDL for graphics. With the changes in WebOS 2.x, that plugin doesn't work anymore: it uses root access to read the keyboard, but recent PDK apps are not running as root anymore but in jails. Therefore an extended version is required that handles keyboard input for "non-root" users. That version is available from Qt gfxdrivers plugin for WebOS on Google Code. It has also tentative support for screen rotation.

  1. Cd to the Qt gfxdrivers directory: cd ~/qt-everywhere-opensource-src-4.8.0/src/plugins/gfxdrivers
  2. Get the WebOS gfxdrivers plugin from the svn repository: svn checkout http://qt-webos.googlecode.com/svn/trunk/ webos
  3. Edit ~/qt-everywhere-opensource-src-4.8.0/src/plugins/gfxdrivers/gfxdrivers.pro to add the line: contains(gfx-plugins, webos) :SUBDIRS += webos
  4. In order to support screen rotation we need to patch the "transformed" screen driver. This driver is provided by Qt to do screen rotation or offsetting and it uses as back-end the driver doing the actual access to the pixels (that would be our webos qgfxdrivers). Unfortunately the transformed driver doesn't allow to "notify" SDL when pixels are changed. A quick hack is to patch ~/qt-everywhere-opensource-src-4.8.0t/src/gui/embedded/qscreentransformed_qws.cpp. In this patch we hijack the functionality of the "blank" method (which is supposed to blank the screen) to notify the WebOS gfxdrivers before and after pixels are modified. So edit qscreentransformed_qws.cpp around lines 430 and add the two lines marked with the comments below:
.
.
.
    screen()->blank(true);                        // ADD THIS FOR WEBOS
    QWSDisplay::grab();
    for (int i = 0; i < rects.size(); ++i) {
        const QRect r = rects.at(i) & bound;

        QPoint dst;
        switch (trans) {
        case Rot90:
            dst = mapToDevice(r.topRight(), QSize(w, h));
            break;
        case Rot180:
            dst = mapToDevice(r.bottomRight(), QSize(w, h));
            break;
        case Rot270:
            dst = mapToDevice(r.bottomLeft(), QSize(w, h));
            break;
        default:
            break;
        }
        func(this, image, r.translated(-topLeft), dst);
    }
    QWSDisplay::ungrab();
    screen()->blank(false);                       // ADD THIS FOR WEBOS
.
.
.


3.4 Cross-compile

Now we can configure and cross-compile Qt. The lines below configure Qt to install in ~/qte-48:

  1. cd ~/qt-everywhere-opensource-src-4.8.0
  2. ./configure -v -prefix ~/qte-48 -embedded arm -platform qws/linux-x86-g++ -xplatform qws/linux-webos -depths 16,24,32 -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-nis -no-iconv -no-dbus -no-cups -no-largefile -no-accessibility -no-gtkstyle -no-qt3support -qt-gfx-vnc -plugin-gfx-vnc -no-glib -qtlibinfix 48 -xmlpatterns -exceptions -opensource -make libs -nomake tools -nomake demo -nomake examples -nomake docs -webkit -javascript-jit -script -scripttools -declarative -openssl -qt-gfx-transformed
  3. make -j4
  4. make install

Hopefully you've made it so far without problems! You now have Qt in ~/qte-48.


4. Compiling Qt apps

5. deploy

A. Links

[1] Qt on the Palm Pre [2] Qt port to webOS by Darron Black on gitorious