Getting Started/Build/Windows/Cross-Compiling: Difference between revisions

    From KDE TechBase
    (19 intermediate revisions by 8 users not shown)
    Line 4: Line 4:
    ==Basic tools==
    ==Basic tools==
    ===MinGw===
    ===MinGw===
    Install mingw for linux, on debian the packages are called mingw32, mingw32-binutils, mingw32-runtime, you need to install mingw32 with gcc/g++ 3 and not 4 since that doesn't work with kdelibs, debian testing/unstable has gcc 4 so i've installed mingw32 package from ubuntu repository
    Install mingw for linux
     
    On debian the packages are called mingw32, mingw32-binutils, mingw32-runtime, you need to install mingw32 with gcc/g++ 3 and not 4 since that doesn't work with kdelibs, debian testing/unstable has gcc 4 so i've installed mingw32 package from ubuntu repository.
     
    On gentoo, you need to do the following: "emerge crossdev; crossdev mingw32".
     
    ===Qt4 Kdesupport and dependencies===
    ===Qt4 Kdesupport and dependencies===
    You can install these dependencies(aspell, boost, dbus, qca etc..) from windows with the kdewin installer or manually download them from [http://sourceforge.net/project/showfiles.php?group_id=214730 sourceforge mirrors]
    You can install these dependencies(aspell, boost, dbus, qca etc..) from windows with the kdewin installer or manually download them from [http://sourceforge.net/project/showfiles.php?group_id=214730 sourceforge mirrors]
    Line 10: Line 15:
    You also need to have Qt4 and KDE4 already installed on linux, to use moc/uic/kde4automoc etc...
    You also need to have Qt4 and KDE4 already installed on linux, to use moc/uic/kde4automoc etc...
    ===Cmake===
    ===Cmake===
    To cross compile kde you need cmake >= 2.5, you can get the last version from [http://cmake.org/HTML/Download.html#cvs CVS]
    To cross compile KDE you need CMake >= 2.5, you can get the last version from [http://cmake.org/HTML/Download.html#cvs CVS]


    * Create two files Toolchain-mingw32.cmake and mingw32-kdelibs.cmake with this contents and place them somewhere i.e. in your home
    * Create two files Toolchain-mingw32.cmake and mingw32-kdelibs.cmake with this contents and place them somewhere i.e. in your home
    ====Toolchain-mingw32.cmake====
    ====Toolchain-mingw32.cmake====
    <code scheme>
    <syntaxhighlight lang="scheme">
    set(KDE_PREFIX    /windows/kde4)
    set(KDE4_SRC_DIR  /home/kdeuser/kde/src)
     
    # the name of the target operating system
    # the name of the target operating system
    SET(CMAKE_SYSTEM_NAME Windows)
    SET(CMAKE_SYSTEM_NAME Windows)
    Line 23: Line 31:


    # here is the target environment located
    # here is the target environment located
    SET(CMAKE_FIND_ROOT_PATH  /usr/i586-mingw32msvc /windows/kde4 )
    SET(CMAKE_FIND_ROOT_PATH  /usr/i586-mingw32msvc ${KDE_PREFIX} )


    # adjust the default behaviour of the FIND_XXX() commands:
    # adjust the default behaviour of the FIND_XXX() commands:
    Line 33: Line 41:


    # FindQt4.cmake querys qmake to get information, this doesn't work when crosscompiling
    # FindQt4.cmake querys qmake to get information, this doesn't work when crosscompiling
    set(KDE4_INSTALL_DIR    /windows/kde4)
    set(QT_BINARY_DIR  ${KDE4_SRC_DIR}/qt-copy/bin)
    set(QT_BINARY_DIR  /home/kdeuser/kde/src/qt-copy/bin)
    set(QT_LIBRARY_DIR  ${KDE_PREFIX}/lib)
    set(QT_LIBRARY_DIR  ${KDE4_INSTALL_DIR}/lib)
    set(QT_QTCORE_LIBRARY  ${KDE_PREFIX}/lib/libQtCore4.a)
    set(QT_QTCORE_LIBRARY  ${KDE4_INSTALL_DIR}/lib/libQtCore4.a)
    set(QT_QTCORE_INCLUDE_DIR ${KDE_PREFIX}/include/QtCore)
    set(QT_QTCORE_INCLUDE_DIR ${KDE4_INSTALL_DIR}/include/QtCore)
    set(QT_MKSPECS_DIR  ${KDE_PREFIX}/mkspecs)
    set(QT_MKSPECS_DIR  ${KDE4_INSTALL_DIR}/mkspecs)
    set(QT_MOC_EXECUTABLE  ${QT_BINARY_DIR}/moc)
    set(QT_MOC_EXECUTABLE  ${QT_BINARY_DIR}/moc)
    set(QT_QMAKE_EXECUTABLE  ${QT_BINARY_DIR}/qmake)
    set(QT_QMAKE_EXECUTABLE  ${QT_BINARY_DIR}/qmake)
    set(QT_UIC_EXECUTABLE  ${QT_BINARY_DIR}/uic)
    set(QT_UIC_EXECUTABLE  ${QT_BINARY_DIR}/uic)
    </code>
    </syntaxhighlight>
     
    ====mingw32-kdelibs.cmake====
    ====mingw32-kdelibs.cmake====
    <code scheme>
    <syntaxhighlight lang="scheme">
    set(KDE4_INSTALL_DIR   /windows/kde4)
    set(KDE_PREFIX   /windows/kde4)
    set(KDE4_BIN_DIR    /home/kdeuser/kde/bin)
    set(KDE4_BIN_DIR    /home/kdeuser/kde/bin)


    # this one is used by FindKDE4.cmake to load FindKDE4Internal.cmake:
    # this one is used by FindKDE4.cmake to load FindKDE4Internal.cmake:
    set(KDE4_DATA_DIR    /windows/kde4/share/apps CACHE PATH "points to the apps directory of installed kdelibs")
    set(KDE4_DATA_DIR    ${KDE_PREFIX}/share/apps CACHE PATH "points to the apps directory of installed kdelibs")


    # not sure about this one:
    # not sure about this one:
    set(KDEWIN_DIR ${KDE4_INSTALL_DIR} CACHE PATH "what is it ?")
    set(KDEWIN_DIR ${KDE_PREFIX} CACHE PATH "what is it ?")


    # disable some things:
    # disable some things:
    Line 63: Line 71:
    set(WITH_OpenEXR OFF CACHE BOOL "Disabled")
    set(WITH_OpenEXR OFF CACHE BOOL "Disabled")


    # use the binaries from native KDE4
    set(KDE4_KCFGC_EXECUTABLE ${KDE4_BIN_DIR}/kconfig_compiler CACHE PATH "")
    set(KDE4_KCFGC_EXECUTABLE ${KDE4_BIN_DIR}/kconfig_compiler CACHE PATH "")
    set(KDE4_AUTOMOC_EXECUTABLE ${KDE4_BIN_DIR}/kde4automoc CACHE PATH "")
    set(KDE4_AUTOMOC_EXECUTABLE ${KDE4_BIN_DIR}/kde4automoc CACHE PATH "")
    set(KDE4_MEINPROC_EXECUTABLE ${KDE4_BIN_DIR}/meinproc4 CACHE PATH "")
    set(KDE4_MEINPROC_EXECUTABLE ${KDE4_BIN_DIR}/meinproc4 CACHE PATH "")
    </code>
    </syntaxhighlight>
    <br/>
    adjust the values according to your setup
    adjust the values according to your setup


    ==Build kdelibs==
    ==Build kdelibs==
    <code bash>
    <syntaxhighlight lang="bash">
    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdelibs
    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdelibs
    cd kdelibs
    cd kdelibs
    mkdir build
    mkdir build
    cd build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake ..
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake ..
    </code>
    </syntaxhighlight>
    * you have to make a link to your kde4automoc for linux in the bin directory
    * you have to make a link to your kde4automoc and kconfig_compiler for linux in the bin directory
    <code bash>
    <syntaxhighlight lang="bash">
    ln -s /path/to/kde4automoc bin/
    ln -s /path/to/kde4automoc bin/
    ln -s /path/to/kconfig_compiler bin/
    ln -s /path/to/kconfig_compiler bin/
    </code>
    </syntaxhighlight>
    * since linux is case sensitive you have to make symbolic links for some headers
    * since linux is case sensitive you have to make symbolic links for some headers
    <code bash>
    <syntaxhighlight lang="bash">
    cd /windows/kde4/include
    cd /windows/kde4/include
    ln -s soprano Soprano
    ln -s soprano Soprano
    </code>
    </syntaxhighlight>
    * You will get a linker error on kjsembed so from the build directory cd into kjsembed/kjsembed and make VERBOSE=1 2>/dev/null
    copy the last command i.e.
    /usr/bin/i586-mingw32msvc-g++    -Wl,--export-all-symbols -Wl,--disable-auto-import -shared -o ../../bin/libkjsembed.dll -Wl,--out-implib,../../bin/libkjsembed.dll.a -Wl,--major-image-version,4,--minor-image-version,1 CMakeFiles/kjsembed.dir/kjsembed_automoc.cpp.obj CMakeFiles/kjsembed.dir/kjseglobal.cpp.obj CMakeFiles/kjsembed.dir/binding_support.cpp.obj CMakeFiles/kjsembed.dir/static_binding.cpp.obj CMakeFiles/kjsembed.dir/variant_binding.cpp.obj CMakeFiles/kjsembed.dir/object_binding.cpp.obj CMakeFiles/kjsembed.dir/builtins.cpp.obj CMakeFiles/kjsembed.dir/fileio.cpp.obj CMakeFiles/kjsembed.dir/jseventmapper.cpp.obj CMakeFiles/kjsembed.dir/eventproxy.cpp.obj CMakeFiles/kjsembed.dir/slotproxy.cpp.obj CMakeFiles/kjsembed.dir/jseventutils.cpp.obj CMakeFiles/kjsembed.dir/qobject_binding.cpp.obj CMakeFiles/kjsembed.dir/kjsembed.cpp.obj CMakeFiles/kjsembed.dir/value_binding.cpp.obj CMakeFiles/kjsembed.dir/iosupport.cpp.obj CMakeFiles/kjsembed.dir/qwidget_binding.cpp.obj CMakeFiles/kjsembed.dir/qaction_binding.cpp.obj CMakeFiles/kjsembed.dir/qlayout_binding.cpp.obj CMakeFiles/kjsembed.dir/qpainter_binding.cpp.obj CMakeFiles/kjsembed.dir/settings.cpp.obj CMakeFiles/kjsembed.dir/svg_binding.cpp.obj CMakeFiles/kjsembed.dir/filedialog_binding.cpp.obj CMakeFiles/kjsembed.dir/application.cpp.obj CMakeFiles/kjsembed.dir/color.cpp.obj CMakeFiles/kjsembed.dir/dom.cpp.obj CMakeFiles/kjsembed.dir/font.cpp.obj CMakeFiles/kjsembed.dir/image.cpp.obj CMakeFiles/kjsembed.dir/pen.cpp.obj CMakeFiles/kjsembed.dir/pixmap.cpp.obj CMakeFiles/kjsembed.dir/point.cpp.obj CMakeFiles/kjsembed.dir/rect.cpp.obj CMakeFiles/kjsembed.dir/size.cpp.obj CMakeFiles/kjsembed.dir/url.cpp.obj CMakeFiles/kjsembed.dir/bind_qlcdnumber.cpp.obj CMakeFiles/kjsembed.dir/bind_qtimer.cpp.obj CMakeFiles/kjsembed.dir/brush.cpp.obj CMakeFiles/kjsembed.dir/QBrush_bind.cpp.obj CMakeFiles/kjsembed.dir/quiloader_binding.cpp.obj -L/windows/kde4/bin -L/windows/kde4/lib ../../bin/libkdecore.dll.a /windows/kde4/lib/libQtCore4.a /windows/kde4/lib/libQtUiTools.a /windows/kde4/lib/libQtGui4.a /windows/kde4/lib/libQtSvg4.a ../../bin/libkjs.dll.a /windows/kde4/lib/libQtNetwork4.a /windows/kde4/lib/libQtDBus4.a /windows/kde4/lib/libz.dll.a /windows/kde4/lib/libkdewin32.dll.a -luser32 -lshell32 -lws2_32 -lnetapi32 -luserenv /windows/kde4/lib/libQtXml4.a /windows/kde4/bin/bzip2.dll /windows/kde4/lib/libintl.dll.a /windows/kde4/bin/libpcre.dll /windows/kde4/bin/libpcreposix.dll


    you need to remove
    * You will get an error in klauncher.moc about slotKDEInitData so go into kinit and do something like this(you need wine)
    /windows/kde4/lib/libQtCore4.a
    <syntaxhighlight lang="bash">
    from this command and add
    -lQtCore4
    execute the modified command and continue with the normal building
     
    * You will get another error in klauncher.moc about slotKDEInitData so go into kinit and do something like this(you need wine)
    <code bash>
    make clean
    rm *.moc
    rm *.moc
    ../bin/kde4automoc.exe /home/kdeuser/kde/src/KDE/kdelibs/build/kinit/kdeinit_klauncher_automoc.cpp /home/kdeuser/kde/src/KDE/kdelibs/kinit /home/kdeuser/kde/src/KDE/kdelibs/build/kinit /windows/kde4/bin/moc.exe
    ../bin/kde4automoc.exe /home/kdeuser/kde/src/KDE/kdelibs/build/kinit/klauncher_automoc.cpp /home/kdeuser/kde/src/KDE/kdelibs/kinit /home/kdeuser/kde/src/KDE/kdelibs/build/kinit /windows/kde4/bin/moc.exe
    </code>
    </syntaxhighlight>
    and then do make as usual
    and then do make as usual


    Line 111: Line 111:
    ==Build kdepimlibs==
    ==Build kdepimlibs==
    This is easy :)
    This is easy :)
    <code bash>
    <syntaxhighlight lang="bash">
    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepimlibs
    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepimlibs
    cd kdepimlibs
    cd kdepimlibs
    mkdir build
    mkdir build
    cd build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake  ..
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake -C ~/mingw32-kdelibs.cmake  ..
    make
    make
    make install
    make install
    </code>
    </syntaxhighlight>
     
    ==Build kdebase==
    ==Build kdebase==
    This is easy :)
    This is easy :)
    <code bash>
    <syntaxhighlight lang="bash">
    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdebase
    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdebase
    cd kdebase
    cd kdebase
    mkdir build
    mkdir build
    cd build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake ..
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake -C ~/mingw32-kdelibs.cmake ..
    make
    make
    make install
    make install
    </code>
    </syntaxhighlight>
     
    == Icecream ==
     
    One of the joys of cross-compiling is the possibility to use an icecream cluster to speed up compilation.
     
    For Debian Etch, you can get an icecream environment from here:
     
    ftp://ftp.kdab.com/gpg4win/devtools/debian-etch-mingw32-icecream-env.tar.gz
     
    (If you want to create your own environment: icecc-create-env does a good job except that it packages the wrong as. /usr/bin/i586-mingw32msvc-as is needed)
     
    The bin/ dir with symlinks from i586-mingw32msvc-* to /usr/bin/icecc:
     
    ftp://ftp.kdab.com/gpg4win/devtools/icecc-mingw-bin.tar.bz2
     
    Untar icecc-mingw-bin.tar.bz2 to icecc-mingw-bin
     
    Then set the following environment variables:
     
    <syntaxhighlight lang="bash">
    export PATH=/path/to/icecc-mingw-bin/bin:$PATH
    export ICECC_CC=i586-mingw32msvc-gcc
    export ICECC_CXX=i586-mingw32msvc-g++
    export ICECC_VERSION=i686:/path/to/debian-etch-mingw32-icecream-env.tar.gz,x86_64:/path/to/debian-etch-mingw32-icecream-env.tar.gz
    </syntaxhighlight>
     
    (Re-)run cmake and have fun.

    Revision as of 14:28, 8 February 2013

    Warning
    This section needs improvements: Please help us to

    cleanup confusing sections and fix sections which contain a todo


    cross compiling is still unstable
    Tip
    Note: This page is about KDE 4. It isn't applicable for KDE 3 development.

    Basic tools

    MinGw

    Install mingw for linux

    On debian the packages are called mingw32, mingw32-binutils, mingw32-runtime, you need to install mingw32 with gcc/g++ 3 and not 4 since that doesn't work with kdelibs, debian testing/unstable has gcc 4 so i've installed mingw32 package from ubuntu repository.

    On gentoo, you need to do the following: "emerge crossdev; crossdev mingw32".

    Qt4 Kdesupport and dependencies

    You can install these dependencies(aspell, boost, dbus, qca etc..) from windows with the kdewin installer or manually download them from sourceforge mirrors

    Qt4 and KDE4 for linux

    You also need to have Qt4 and KDE4 already installed on linux, to use moc/uic/kde4automoc etc...

    Cmake

    To cross compile KDE you need CMake >= 2.5, you can get the last version from CVS

    • Create two files Toolchain-mingw32.cmake and mingw32-kdelibs.cmake with this contents and place them somewhere i.e. in your home

    Toolchain-mingw32.cmake

    set(KDE_PREFIX    /windows/kde4)
    set(KDE4_SRC_DIR  /home/kdeuser/kde/src)
    
    # the name of the target operating system
    SET(CMAKE_SYSTEM_NAME Windows)
    
    # which compilers to use for C and C++
    SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
    SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
    
    # here is the target environment located
    SET(CMAKE_FIND_ROOT_PATH  /usr/i586-mingw32msvc ${KDE_PREFIX} )
    
    # adjust the default behaviour of the FIND_XXX() commands:
    # search headers and libraries in the target environment, search
    # programs in the host environment
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    
    # FindQt4.cmake querys qmake to get information, this doesn't work when crosscompiling
    set(QT_BINARY_DIR   ${KDE4_SRC_DIR}/qt-copy/bin)
    set(QT_LIBRARY_DIR  ${KDE_PREFIX}/lib)
    set(QT_QTCORE_LIBRARY   ${KDE_PREFIX}/lib/libQtCore4.a)
    set(QT_QTCORE_INCLUDE_DIR ${KDE_PREFIX}/include/QtCore)
    set(QT_MKSPECS_DIR  ${KDE_PREFIX}/mkspecs)
    set(QT_MOC_EXECUTABLE  ${QT_BINARY_DIR}/moc)
    set(QT_QMAKE_EXECUTABLE  ${QT_BINARY_DIR}/qmake)
    set(QT_UIC_EXECUTABLE  ${QT_BINARY_DIR}/uic)
    

    mingw32-kdelibs.cmake

    set(KDE_PREFIX    /windows/kde4)
    set(KDE4_BIN_DIR    /home/kdeuser/kde/bin)
    
    # this one is used by FindKDE4.cmake to load FindKDE4Internal.cmake:
    set(KDE4_DATA_DIR    ${KDE_PREFIX}/share/apps CACHE PATH "points to the apps directory of installed kdelibs")
    
    # not sure about this one:
    set(KDEWIN_DIR ${KDE_PREFIX} CACHE PATH "what is it ?")
    
    # disable some things:
    set(WITH_AVAHI OFF   CACHE BOOL "Disabled")
    set(WITH_DNSSD OFF   CACHE BOOL "Disabled")
    set(WITH_ENCHANT OFF CACHE BOOL "Disabled")
    set(WITH_FAM OFF     CACHE BOOL "Disabled")
    set(WITH_GSSAPI OFF  CACHE BOOL "Disabled")
    set(WITH_HSPELL OFF  CACHE BOOL "Disabled")
    set(WITH_OpenEXR OFF CACHE BOOL "Disabled")
    
    # use the binaries from native KDE4
    set(KDE4_KCFGC_EXECUTABLE ${KDE4_BIN_DIR}/kconfig_compiler CACHE PATH "")
    set(KDE4_AUTOMOC_EXECUTABLE ${KDE4_BIN_DIR}/kde4automoc CACHE PATH "")
    set(KDE4_MEINPROC_EXECUTABLE ${KDE4_BIN_DIR}/meinproc4 CACHE PATH "")
    


    adjust the values according to your setup

    Build kdelibs

    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdelibs
    cd kdelibs
    mkdir build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake ..
    
    • you have to make a link to your kde4automoc and kconfig_compiler for linux in the bin directory
    ln -s /path/to/kde4automoc bin/
    ln -s /path/to/kconfig_compiler bin/
    
    • since linux is case sensitive you have to make symbolic links for some headers
    cd /windows/kde4/include
    ln -s soprano Soprano
    
    • You will get an error in klauncher.moc about slotKDEInitData so go into kinit and do something like this(you need wine)
    rm *.moc
    ../bin/kde4automoc.exe /home/kdeuser/kde/src/KDE/kdelibs/build/kinit/klauncher_automoc.cpp /home/kdeuser/kde/src/KDE/kdelibs/kinit /home/kdeuser/kde/src/KDE/kdelibs/build/kinit /windows/kde4/bin/moc.exe
    

    and then do make as usual

    • Another error in kdewidgets because wine doesn't find some dll to run makekdewidgets.exe so either run the linux version manually like this
    makekdewidgets -o /home/kdeuser/kde/src/KDE/kdelibs/build/kdewidgets/kdewidgets.cpp /home/kdeuser/kde/src/KDE/kdelibs/kdewidgets/kde.widgets
    

    or symlink those missing library in your wine system32 folder(i haven't tested it but it should work)

    Build kdepimlibs

    This is easy :)

    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepimlibs
    cd kdepimlibs
    mkdir build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake -C ~/mingw32-kdelibs.cmake  ..
    make
    make install
    

    Build kdebase

    This is easy :)

    svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdebase
    cd kdebase
    mkdir build
    cd build
    cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake -C ~/mingw32-kdelibs.cmake ..
    make
    make install
    

    Icecream

    One of the joys of cross-compiling is the possibility to use an icecream cluster to speed up compilation.

    For Debian Etch, you can get an icecream environment from here:

    ftp://ftp.kdab.com/gpg4win/devtools/debian-etch-mingw32-icecream-env.tar.gz

    (If you want to create your own environment: icecc-create-env does a good job except that it packages the wrong as. /usr/bin/i586-mingw32msvc-as is needed)

    The bin/ dir with symlinks from i586-mingw32msvc-* to /usr/bin/icecc:

    ftp://ftp.kdab.com/gpg4win/devtools/icecc-mingw-bin.tar.bz2

    Untar icecc-mingw-bin.tar.bz2 to icecc-mingw-bin

    Then set the following environment variables:

    export PATH=/path/to/icecc-mingw-bin/bin:$PATH
    export ICECC_CC=i586-mingw32msvc-gcc
    export ICECC_CXX=i586-mingw32msvc-g++
    export ICECC_VERSION=i686:/path/to/debian-etch-mingw32-icecream-env.tar.gz,x86_64:/path/to/debian-etch-mingw32-icecream-env.tar.gz
    

    (Re-)run cmake and have fun.