Development · Krita · planet

Windows Krita Development

Prerequisities

I needed to patch Qt on Windows, so I had to leave my comfortable Tusooa’s script development environment based on pre-built dependencies taken from the KDE Build Factory and make an actual proper Windows Krita development environment. Since I’m gonna need to make another one very soon and very quickly, I decided to write down my experiences before I forget it all.

List of things to download and install (for details go to https://phabricator.kde.org/source/krita/browse/master/3rdparty/README.md, which is also a place I took versions information and some sentences from):

I created a new directory: C:/qtdev (kritadev was taken). Inside I have two directories: krita and env-dev. I cloned Krita’s code repository into krita directory:

git clone git@invent.kde.org:kde/krita.git krita

Scripts

In env-dev I made a few scripts that helped me with build.cmd script without having to fight with cmd too much. This file is called env.bat:

set OLDPATH=%PATH%
set PATH=%PATH:C:\Perl64\bin\;=%
set PATH=%PATH:C:\Strawberry\c\bin;=%
set PATH=%PATH:C:\Strawberry\perl\site\bin;=%
set PATH=%PATH:C:\Strawberry\perl\bin;=%
set PATH=%PATH%;C:\mingw64\mingw64\bin;C:\%ProgramFiles%\Python36

set BUILDROOT=c:\qtdev\env-dev
set PATH=%BUILDROOT%\i\bin\;%BUILDROOT%\i\lib;%PATH%
set "WindowsSdkDir=%ProgramFiles(x86)%\Windows Kits\10"
set "WindowsSdkVerBinPath=%ProgramFiles(x86)%\Windows Kits\10\bin\10.0.18362.0"

Next one is buildall.bat:

set MINGW_BIN_DIR=c:\mingw64\mingw64\bin\
..\krita\build-tools\windows\build.cmd  --no-interactive --download-dir .\d\ --deps-build-dir .\b_deps\ --deps-install-dir .\i\ --krita-build-dir .\b\ --krita-install-dir .\i\

Then buildkrita.bat:

set MINGW_BIN_DIR=c:\mingw64\mingw64\bin\
..\krita\build-tools\windows\build.cmd --no-interactive --skip-deps --download-dir .\d\ --deps-build-dir .\b_deps\ --deps-install-dir .\i\ --krita-build-dir .\b\ --krita-install-dir .\i\

Last one, justcmd.bat, actually untested yet in time of writing, but should be working just fine:

set MINGW_BIN_DIR=c:\mingw64\mingw64\bin\
..\krita\build-tools\windows\build.cmd --no-interactive --cmd --download-dir .\d\ --deps-build-dir .\b_deps\ --deps-install-dir .\i\ --krita-build-dir .\b\ --krita-install-dir .\i\

Notes about all of those scripts:

  • env.bat
    • Usage: once for every new cmd.exe window, before any attempt in building Krita or dependencies.
    • It is just used to make sue I don’t have anything misleading in my PATH (I installed Strawberry Perl, which of course installed a bunch of c++ compilers – and yes, this werid stuff actually does what I think it does and does remove those paths from PATH; if you want to adjust it to your needs, make sure earlier that t does remove everything you want it to remove! If you just use set, you won’t break your system, so you can play with setting PATH how much you want) and to actually put there stuff that I didn’t have in PATH before (Mingw and Python).
    • You need to adjust it to your needs, especially the Windows SDK version/location and unwanted paths.
  • buildall.bat
    • Usage: it will download source code for all dependencies to download directory, put it in /b/ext_X/s/ directories, then run cmake, make and make install on it. It will take a few hours. Also note that if you want to hack on Qt, it will replace your code and your git repository you made in /b/ext_X/s/ with a clean version of Qt, so be careful to not lose your changes.
    • Options:
      • –no-interactive – don’t ask about anything
      • –download-dir – location to put .zip archives with dependencies source code
      • –deps-build-dir – directory to build dependencies in
      • –deps-install-dir – directory to install dependencies into – to make it easier, keep it the same as Krita’s install directory!
      • –krita-build-dir – directory to build Krita in
      • –krita-install-dir – directory to install Krita into – later you’d need to go there and then ./bin/krita.exe will be your executable to run
  • buildkrita.bat
    • Usage: it will run cmake and then make and make install on just Krita.
  • justcmd.bat, my new baby, will run build.cmd in –cmd mode, which is a very hacky way get access to commands that make those scripts above practically obsolete.
    • cmake-deps – run cmake on dependencies (see warning in buildall.bat section!).
    • make-deps – run make and make install on dependencies.
    • cmake-krita – run cmake on Krita.
    • make-krita – run make and make install on Krita.

Ordered list of things to do

To sum up, here is the list of things to do in order:

  1. Install all things on the list.
  2. Clone Krita’s repository.
  3. Create directory c:/qtdev/env-dev/ (the rest should be created by build.cmd).
  4. Adjust env.bat to your needs. Save all scripts to c:/qtdev/env-dev/.
  5. Open cmd.exe – unfortunately, since build.cmd script is in cmd, you can’t escape it…
  6. Go to c:/qtdev/env-dev/. Yes, that is important, very important. You want to run build.cmd script from inside your build directory and *not* from inside your source code directory. (Even if you were running build.cmd directly, without my script that clearly uses “./”, the suggested paths would be in source code, and providing custom path is so tedious without a bash completion…)
  7. Run env.bat. You only need to run it once per cmd.exe window.
  8. If you didn’t build anything yet, just run buildall.bat. It will take care of everything. Go for a walk, watch a movie, call your grandma – it will take some time…
  9. For any subsequent build, just run justcmd.bat and later use command make-krita to build Krita.

Making patches to Qt

If you want to hack on Qt, there is some more things you’d want to remember:

  1. Just after you built Krita with Qt for the first time, but before changing the code, initialize a git repository in Qt’s source code directory (it will be located in c:/qtdev/env-dev/b_deps/ext_qt/s/). Create a .gitignore file (just copy something from the internet) and make an initial commit. It can take several minutes on NTFS, so don’t get worried if it doesn’t seem to be willing to end after a moment. Just be patient and go get a snack.
  2. DON’T run cmake on Qt. Or, be super careful about it. I just commented out the section that should download and extract the source files to make sure it doesn’t do that.
  3. Make extra sure you saved your patch outside of Qt’s source code directory (outside of your new fresh git) when you want to finally introduce the Qt patch to Krita’s ext_qt code. As I said, cmake will replace Qt with a clean version and later add your patch (that you of course already put in ext_qt/CMakeList.txt and ext_qt/ directory, right?) on top of the Qt’s source code.

Common pitfalls

  1. “Directory is not empty” (during any kind of ext_XXX building or extracting)
    • just run the script again.
  2. “File or directory doesn’t exist”
    • regarding ext_qt/s/.
    • If you check it, there is one directory inside, “qtbase” in my case – the same you changed.
    • You can’t remove/delete this directory (even with admin rights) and build will fail every time.
    • Solution: just restart your PC. Windows doesn’t have a proper root account, so things like that can happen, but fortunately it gets sane after rebooting.
    • Another possibility (thanks to Dmitry, of course): some executable is running, using those files or libraries. It might be Krita or Qt Creator. Make sure you closed them before trying to compile Qt.
  3. “Can’t find file to patch at input line X”, “Perhaps you used the wrong -p or –strip option?”
    • It’s probably because you copied the instruction for the patch from the line above and you didn’t notice the -d qtbase option.
    • Either remove it, or change the patch that it doesn’t contain qtbase part of the path.
  4. “patching file [path] Reversed (or previously applied) patch detected! Assume -R? [n]”
    • delete everything in b_deps and start again… I’m still not sure where exactly it’s written that cmake don’t need to extract the files (overwrite them) anymore.
    • -R would be wrong, and choosing “n” will break the running script.
  5. “Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354”
    • Convert LF to CRLF endings in the patch.
  6. “cc1plus.exe: error: one or more PCH files were found, but they were invalid”
    • Run env.bat script for this commandline, please.

Tests

In time of writing, if you want to have tests on Windows, you need to change build.cmd or call make directly. Build.cmd script has no option to turn those on.

If you turn it on in build.cmd, those tests will be located in c:/qtdev/env-dev/b/bin/ instead of respective folders like on Linux. Additional complication is that they often use some .dlls that are not there (since dependencies are built in b_deps). To fix that, I just copy the binary file from b/bin/ to i/bin/. Below there is a handly script that does it for me (and ensures that the test is freshly built):

#!/bin/bash

NAME=$1
MAKELOC=$2

MAKE=/c/mingw64/mingw64/bin/mingw32-make.exe

if [ ! -z "$MAKELOC" ]
then
	CURR=`pwd`
	echo "Current dictionary: ${CURR}, changing to ${MAKELOC}..."
	cd ${MAKELOC}
	rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
	${MAKE} -j8 ${NAME}
	rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
	echo "${MAKE} ${NAME}"
	cd ${CURR}
	rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
fi

cp b/bin/${NAME} i/bin/
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
i/bin/${NAME}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

Qt Creator

(Before you start to set up Qt Creator, make sure you can build Krita from console).

First you need to create a new Kit. You need to set up at least Compiler (make sure the path is correct!), Debugger, Qt version and CMake Tool. In the Kit settings remove all the properties that are passed to cmake. Make sure CMake Configuration field is empty, and CMake Generator should point to CodeBlocks-Mingw Makefiles.

Then you can set up the project. Make sure the configuration points to “Release with Debug Information”. Debug build is still broken: https://bugs.kde.org/show_bug.cgi?id=369303. Set up building directory to some random folder; configuration will fail, but that’s ok, because then you’ll get access to environment settings.

In Building Environment make sure you make the same surgery on PATH as you do in your version of env.bat script. Add a new argument to Building Steps: --j8 or --j4 or something else, depending on how many cores you want to use to build Krita. You can add a custom step after that: mingw32-make -j1 install/fast. Make sure all Key/Value pairs are correct. Then there is this risky step: put C:\qtdev\env-dev\b as “Version Directory” or however it is called in English Qt Creator (the first textbox on top).

Try to build Krita inside Qt Creator (do it only after you have all dependencies built). If it works, make sure you can still build Krita from console, too.

Tip: if everything seems correct except Qt Creator complains about some FindECM and you have no idea where you should be looking for it, that means you wanted to cheat the system and put something else as building directory.

One thought on “Windows Krita Development

  1. Suggestion: Change “git clone git@invent.kde.org:kde/krita.git krita” to the HTTPS clone url, or mention this url is for SSH. Git clone failed without any leads and I bounced around until I compared the URLs for cloning at invent.kde.org:kde/krita myself, and I’d guess some aren’t aware that SSH requires credentials.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s