Krita/Emergebuild

From KDE Community Wiki
Revision as of 23:40, 5 November 2015 by Miabrahams (talk | contribs)

What is Emerge?

  • There are no binary releases of KDE Frameworks libraries for Windows. KDE Frameworks is required for Krita. Therefore the only option is to build these libraries from source.
  • KDE Frameworks depend on Qt and the Linux Standard Base, and Krita has other dependencies as well. Like KDE Frameworks, many of these dependencies have to be compiled too, so might as well do the entire set of libraries from source. That is what Emerge does.
  • To be flexible enough for this massive build task, Emerge is written in Python. Python is very easy to pick up.
  • General instructions for using Emerge can be found on the Techbase Wiki.
  • You will need approximately 20GB of free space for the whole thing. Doing a separate debug/release build will require another 15GB, and the entire process must be repeated. Fortunately, hard drives are cheap these days.
  • If you do not have qualms with Windows Powershell, I recommend it over cmd.exe, since it has saner interactive features. If you wish, you can get pretty good Bash-like keyboard shortcuts using PSReadline.

Preparing Emerge

cd c:\kderoot
git clone kde:emerge
  • When configuring kdesettings.ini, choose KDECOMPILER = msvc2015 and Architecture = x64.
  • There is an option to use a preinstalled Qt instead of building it from source. I have not tried to do this before, it may be worth investigating. Qt 5 has recently become much better at not breaking MSVC builds, so it's mostly a matter of whether you have an extra hour to kill to compile Qt.
  • The instructions for each particular package are contained in the .\emerge\portage subfolder. This is where you should expect to spend time fiddling with things.
  • Use emerge -v to give verbose output. This can be helpful for diagnosing problems.
  • Choose carefully whether you want to do a debug build or release build. You have to do the whole thing from scratch if you want to have both. Windows does not allow linking debug and release libraries together.
  • If you do want to do both a debug and release build, e.g. C:\kde_debug\ and C:\kde_release\, you can use symlinks for the C:\kde_XXX\emerge and C:\kde_XXX\download\ folders. That way, your build tweaks in the emerge folder, and the massive amount of downloaded files and cloned git repositories, can be shared between the debug and release paths.
  • A few other settings in kdesettings.ini are not necessary but will make the process nicer. This will build with 12 jobs (you can adjust that number to whatever is appropriate for your system), pop up a notification whenever a build process completes, and alias the base directory to r:\.
EMERGE_OPTIONS = make.makeOptions=-j12
EMERGE_USE_NOTIFY = Toaster
EMERGE_USE_SHORT_PATH = True

Building Krita's Dependencies

Qt

  • Step 1: emerge qt
  • Step 2: go get a cup of a coffee.


Krita dependencies

Many dependencies will be straightforward and unproblematic:

emerge pkg-config
emerge coreutils
emerge eigen3
emerge lcms2
emerge exiv2
emerge tiff
emerge lcms2
emerge exiv2
emerge soprano
emerge libcurl
emerge libwpd
emerge ilmbase

A few were can be difficult, although Emerge contains patches for most of them. You may need to manually disable tests for some libraries.

emerge vc
emerge eigen3 
emerge ocio
emerge breakpad
emerge gsl

Boost was rather challenging, and I could not figure out a reasonable upstream patch. Commenting out win32libs/boost-regex and win32libs/boost-iostreams from portage/win32libs/boost/boost.py to turn off those dependencies helped building.

emerge boost

Finally there were some optional dependencies that can be put aside for the time being if they are not cooperating. FFTW is straightforward to install by following the instructions from their website instead of using Emerge.

emerge FFTW
emerge openexr
emerge png2ico
emerge librdf-src
emerge shared-mime-info

Frameworks

The goal here is to build as few as possible, because they can be rickety. The necessary frameworks are listed in CMakeLists.txt in the Krita repo.

emerge kdewin-lib
emerge karchive
emerge kconfig
emerge kcoreaddons
emerge kguiaddons
emerge ki18n
emerge kitemmodels
emerge kitemviews
emerge kwidgetsaddons
emerge kcompletion

Build Krita

To configure Git and clone, follow these instructions, replacing "calligra" with "krita" in the name of the repo. https://community.kde.org/Calligra/Building_Calligra_on_Windows#Getting_the_source_code

Here is a cmake configure command which worked for me. I was very finicky here and not all the flags may be necessary. If you can build without them, please note that here. Do not try to build the tests, such an endeavor would be dangerous for your mental health.

cmake ..\src\ -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=r:\ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="/Gm /MD /Zi" -DCMAKE_MODULE_LINKER_FLAGS ="/machine:x64" -DCMAKE_EXE_LINKER_FLAGS="/machine:x64 /LTCG" -DCMAKE_SHARED_LINKER_FLAGS="/machine:x64" -DCMAKE_STATIC_LINKER_FLAGS="/machine:x64"-DCMAKE_RC_COMPILER="C:/Program Files (x86)/Windows Kits/8.0/bin/x64/rc.exe"

Boost problems

The CMake find_library call in Krita was also unable to locate Boost automatically. I believe there is a way inside Emerge to do this, but I have not pursued that. Instead the following hack in the base CMakeLists.txt fixed things.

-add_definitions(-DBOOST_ALL_NO_LIB)
+set(BOOST_INCLUDEDIR "r:/include")
+set(BOOST_LIBRARYDIR "r:/lib")
+set(BOOST_ROOT "r:")
+set(Boost_DEBUG "ON")

gokde.ps1

This was a little wrapper script I called gokde.ps1 to set up a few aliases for a Krita build environment. Feel free to use it as a guide with appropriate configurations. In particular, some of the environment variables may not be necessary on Windows. The cmdlet add-pathvariable is from the PowerShell Community Extensions.

D:\kde_qt5\emerge\kdeenv.ps1
cd r:
Set-Alias krita r:\bin\krita.exe
function global:install-krita {
   Stop-Process -processname Krita -ErrorAction SilentlyContinue
   ninja -C r:\build\calligra install
}

function global:build-krita {
   Stop-Process -processname Krita -ErrorAction SilentlyContinue
   ninja -C r:\build\calligra
}

function global:run-krita {
   install-krita
   if ($LASTEXITCODE -eq 0) {
       krita
   }
}

Add-PathVariable r:\bin
Add-PathVariable r:\lib\krita
$env:XDG_DATA_HOME = "r:\share"
$env:XDG_DATA_DIRS = $env:XDG_DATA_HOME
$env:XDG_CONFIG_HOME = "r:\config"
$env:XDG_CONFIG_DIRS = $env:XDG_CONFIG_HOME
$env:KDE_DEBUG_NOAREANAME=1
$env:KDEDIRS = "r:"
$env:KDEHOME = "r:\share\.kde"
$env:OPENSSL_ROOT_DIR="r:"
$env:EDITOR = "notepad"