Building Krita from Source

If you want to help developing Krita, you need to know how to build Krita yourself. If you merely want to run the latest version of Krita, to test a bug or play with, you can use the nightly build for Windows the nightly build for Linux, or the nightly build for macOS.

You can build Krita on Linux, Windows, macOS and on Linux for Android. The libraries Krita needs (for instance to load and save various image types) are called dependencies.

Linux is the easiest operating system to build Krita on because all the libraries that Krita needs are available on most recent Linux distributions. For an easy guide to building Krita see Building Krita on Linux for Cats.

On macOS you can use tools like homebrew to get the dependencies, or build the dependencies manually. Building the dependencies manually is recommended because we have a number of changes to the source for libraries to make them function better with Krita.

On Windows you can either reuse the dependencies from the KDE Binary Factory, or build the dependencies yourself.

On all operating systems, you need to be familiar with using a terminal. Building Krita is a technical task and demands accuracy in following instructions and intelligence in understanding what happens.

Building on Linux

In general, there are two options for building Krita on Linux. One using the docker environment (recommended) and the other is by manually building all the Krita dependencies on the host linux system (unsupported).

Building on Windows

On Windows, you can either reuse the dependencies from the KDE Binary Factory, or build the dependencies yourself. If you decide to build all the dependencies yourself, this will take a long time. Note that you will do all your work in a CMD command window.

This is also more difficult than building Krita on Linux, so you need to pay attention to details. If you follow the guide closely, install correct dependencies and make sure your PATH doesn’t contain anything unwanted, there should be no issues.

Prerequisites

  1. Git - https://git-scm.com/downloads

  2. CMake 3.16.0 or later, the latest is usually fine - https://cmake.org/download/

  3. Ninja build system - https://github.com/ninja-build/ninja/releases

    • Since Ninja is a single executable, you can place it in the bin folder of CMake, next to cmake.exe for convenience.

  4. LLVM MinGW compiler toolchain

  5. You will also need a release of Python 3.10 (not 3.7, not 3.8, not 3.9, not 3.11) - https://www.python.org.

    • Make sure to have that version of python.exe in your path. This version of Python will be used for two things to configure Qt and to build the Python scripting module. Do not set PYTHONHOME or PYTHONPATH.

    • Make sure that your Python will have the correct architecture for the version you are trying to build. If building for 32-bit target, you need the 32-bit release of Python.

  6. It is useful to install Qt Creator - https://download.qt.io/official_releases/qtcreator/

Attention

Make double plus sure you do not have any other compilers or development environments or Python installation in your PATH!

Other Compilers

  • In the past we used mingw-w64 gcc 7.3.0 (mingw-builds). This version is no longer supported because our dependencies started requiring a more updated compiler to work.

  • It is possible to build Krita with a newer mingw-w64 gcc toolchain, for example gcc 11.2.0 by niXman on GitHub (mingw-builds), or the one from MSYS2.

  • MSYS2 can build Krita with the MINGW64, UCRT64 or CLANG64 environments.

  • Krita can also be built with MSVC (check the batch file in build-tools\windows). Krita built with MSVC has suboptimal performance due to codegen issues so we can’t use it.

Attention

If you use these compilers, you must build the dependencies yourself. Trying to mix dependencies built with a different compiler may outright fail to configure, or Krita may appear to build successfully but you get random crashes wuen running it.

Preparation

../_images/Krita-building_for-cats_001-init-dir_001_by-deevad.jpg

After installing the Prerequisites, prepare your working directory somewhere, like C:\krita-dev. Keep this short (30 characters in the prefix path is fine, but longer than this and you may get build errors). Makes sure the path does not contain whitespace. If you use a different path, remember to adjust the paths in the later steps.

mkdir C:\krita-dev
cd /d C:\krita-dev

Set up python environment (you don’t need to hand-craft the bat file with the predefined PATH variables):

git clone https://invent.kde.org/dkazakov/krita-deps-management.git
git clone https://invent.kde.org/dkazakov/ci-utilities.git -b work/split-ci-branch krita-deps-management/ci-utilities

c:\Python310\python.exe -m venv PythonEnv --upgrade-deps
PythonEnv\Scripts\activate.bat
python -m pip install -r krita-deps-management\requirements.txt

Getting the dependencies

../_images/Krita-building_for-cats_003-get-libs_001_by-deevad.jpg

Donwload the dependencies and generate the environment file. Make sure you replace the paths to llvm-mingw and ninja:

python krita-deps-management\tools\setup-env.py --full-krita-env -v PythonEnv -p c:\deps\llvm-mingw-20220906-ucrt-x86_64\bin\ -p c:\deps\llvm-mingw-20220906-ucrt-x86_64\x86_64-w64-mingw32\bin\ -p c:\deps\Ninja\

Attention

If you happen to decide to hand-craft the PATH variable, make sure your PATH variable does not have double backslash symbols \\. Especially as a result of multiple path variables concatenation.

If it has, ASAN symbolizer will crash when parsing error-reports.

Every time you want to build or run your home-grown Krita, open the CMD window, change to the C:\krita-dev folder and run the env.bat file generated by the script above:

cd /d C:\krita-dev
env.bat

You will note that most command samples below contain these two lines, but the truth is you only need to run env.bat once for each CMD window.

Then get the source code of Krita:

../_images/Krita-building_for-cats_002-git-clone_001_by-deevad.jpg
cd /d C:\krita-dev
git clone https://invent.kde.org/graphics/krita.git

Attention

If you build Krita with ASAN, make sure you don’t use prebuilt deps, or at least manually rebuild Qt with ASAN support as well (-DQT_ENABLE_ASAN=ON). There is a know issue in LLVM’s linker, which causes Qt be loaded before ASAN and, therefore, causing some allocations confuse ASAN. Until this issue is fixed, build Qt with ASAN as a workaround.

Building Krita

../_images/Krita-building_for-cats_005-build_001_by-deevad.jpg

Again, on the command line, configure the build:

cd /d C:\krita-dev
env.bat
mkdir -p C:\krita-dev\b_krita
cd b_krita

cmake C:\krita-dev\krita ^
    -DCMAKE_INSTALL_PREFIX=C:/krita-dev/_install ^
    -DBUILD_TESTING=ON ^
    -DINSTALL_BENCHMARKS=ON ^
    -DKRITA_ENABLE_PCH=OFF ^
    -DHIDE_SAFE_ASSERTS=OFF ^
    -G Ninja ^
    -DCMAKE_BUILD_TYPE=RelWithDebInfo

ninja -j8 install

If you are hacking on Krita, you can rebuild Krita without running the full build by entering the build directory and running mingw32-make -j8 install or ninja -j8 install.

cd /d C:\krita-dev
env.bat
cd b_krita
ninja -j8 install
../_images/Krita-building_for-cats_006-installing_by-deevad.jpg

Running Krita

You must start Krita from the command prompt, after having run env.bat:

cd /d C:\krita-dev
env.bat
_install\bin\krita
:: or
_install\bin\krita.exe
../_images/Krita-building_for-cats_008-running-success_by-deevad.jpg

Building on macOS

We will build Krita on macOS with the same scripts that are used to build the nightly builds and the releases. We will NOT be building krita from within XCode, but from within the terminal.

Prequisites

You will need to install:

Preparation

../_images/Krita-building_for-cats_002-git-clone_001_by-deevad.jpg

Open Terminal.app. First you need to install necessary build tools that we fetch via Craft:

export BUILDROOT=$HOME/dev

mkdir -p $BUILDROOT
cd $BUILDROOT

# fetch Craft and use it for installing CMake, ninja and a few other tools
git clone https://invent.kde.org/packaging/craftmaster.git --depth=1
export KDECI_CRAFT_DOWNLOADS=$BUILDROOT/craft-downloads
export KDECI_CRAFT_CONFIG=$BUILDROOT/upstream-ci-utilities/craft/qt5/CraftConfig.ini
export KDECI_CRAFT_PROJECT_CONFIG=$BUILDROOT/.craft.ini
export KDECI_CRAFT_PLATFORM=macos-arm-clang

touch $KDECI_CRAFT_PROJECT_CONFIG
function craftmaster { python3 craftmaster/CraftMaster.py --config $KDECI_CRAFT_CONFIG --config-override $KDECI_CRAFT_PROJECT_CONFIG --target $KDECI_CRAFT_PLATFORM --variables DownloadDir=$KDECI_CRAFT_DOWNLOADS $@; }

craftmaster --setup
craftmaster -c -i --options virtual.ignored=True --update craft
craftmaster -c -i core/cacert dev-utils/7zip-base dev-utils/cmake-base dev-utils/7zip dev-utils/cmake dev-utils/patchelf dev-utils/ninja

# add the tools that Craft installed into the current PATH
export PATH=$BUILDROOT/$KDECI_CRAFT_PLATFORM/dev-utils/bin/:$PATH

Now fetch Krita sources, build scripts and set up virtual environment for Python:

cd $BUILDROOT
git clone https://invent.kde.org/graphics/krita.git

# fetch environment scripts under Krita's source directory
cd krita
git clone https://invent.kde.org/dkazakov/krita-deps-management.git krita-deps-management --depth=1
git clone https://invent.kde.org/dkazakov/ci-utilities.git -b work/split-ci-branch krita-deps-management/ci-utilities --depth=1

# create venv environemnt for running build scripts
python3 -m venv $BUILDROOT/venv --upgrade-deps
source $BUILDROOT/venv/bin/activate
pip install -r krita-deps-management/requirements.txt

Fetching prebuilt dependencies

../_images/Krita-building_for-cats_003-get-libs_001_by-deevad.jpg

Now set up the environment for building Krita and download all the dependencies in a prebuilt form:

cd $BUILDROOT/krita
source $BUILDROOT/venv/bin/activate

python krita-deps-management/tools/setup-env.py --full-krita-env -v $BUILDROOT/venv -p $BUILDROOT/$KDECI_CRAFT_PLATFORM/dev-utils/bin/

The script will generate the following environment for you:

  • $BUILDROOT/krita/_install — the install prefix for Krita with all the deps preinstalled

  • $BUILDROOT/krita/_build — the build folder for Krita

  • $BUILDROOT/krita/env — a script for build environment activation

  • $BUILDROOT/krita/env_deactivate — a script for build environment de-activation

The steps above should be done only once when you set up the environement for the first time. Next time you open the console you should just source the env-file at $BUILDROOT/krita/env, you don’t have to repeat all these steps with craft and python’s environment.

Building Krita

../_images/Krita-building_for-cats_006-installing_by-deevad.jpg

Building Krita is straightforward, just activate the environment and do the build. Everything will be activated automatically.

# go to the Krita source directory
cd $BUILDROOT/krita

# activate the build environment (you don't need to activate
# any previous environments, like Python's venv environment;
# everything is included in this ``env`` file)
source $BUILDROOT/krita/env

mkdir -p _build
cd _build

# configure Krita as usual
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DHIDE_SAFE_ASSERTS=OFF \
      -DBUILD_TESTING=ON \
      -DCMAKE_INSTALL_PREFIX=$BUILDROOT/krita/_install \
      -DCMAKE_TOOLCHAIN_FILE=$BUILDROOT/krita/krita-deps-management/tools/macos-toolchain-krita.cmake \
      $BUILDROOT/krita

# build and install
ninja -j8 install

This will build and install Krita to $BUILDROOT/krita/_install/bin/krita.app

Running Krita

You can run krita in the same terminal window:

$BUILDROOT/krita/_install/bin/krita.app/Contents/MacOS/krita

If you want to debug krita with lldb:

cd $BUILDROOT/krita
lldb ./_install/bin/krita.app/Contents/MacOS/krita
(lldb) target create "./_install/bin/krita.app/Contents/MacOS/krita"
Current executable set to './_install/bin/krita.app/Contents/MacOS/krita' (x86_64).
(lldb) r
../_images/Krita-building_for-cats_008-running-success_by-deevad.jpg

Building on Android

See a dedicated page for building Krita on Android

Building Krita’s dependencies manually

See a dedicated page for building Krita’s dependencies manually