Skip to content

Make it possible to compile Krita on Windows with Clang12 via MSYS2

Dmitry Kazakov requested to merge dkazakov/krita:kazakov/msys-clang-build into master

Summary

The patch adds a lot of fixes that make it possible to compile Krita with MSYS2. Both, deps and Krita can now be compiled with either Clang 12.0.1 or GCC 10.3.0. This manual explains how to compile everything with Clang 12.0.1.

  • the patch makes Krita reuse several libraries prebuilt by MSYS2. I'm not sure how safe it is:

    • ZLIB
    • Iconv
    • EXPAT
    • Gettext
    • OpenSSL
  • DrMinGW deps cannot be currently built in this environment. I don't know why. Though MSYS2 has its own build of DrMinGW, so we can probably just reuse it. FIXED

  • KSeExpr cannot be currently built in this environment. Its CMakeLists.txt sees CLang in %PATH% and gets crazy. FIXED

  • Some patches (e.g. the one in ext_boost) still don't check if the environment is MSYS2. That is, they are applied for all the builds. That might be probably unsafe. FIXED

Building Krita with MSYS2+Clang on Windows

  1. Download MSYS2 installer from here: https://github.com/msys2/msys2-installer/releases/download/2021-07-25/msys2-x86_64-20210725.exe

  2. Start MSYS2 (not MinGW64!) shell via c:\msys64\msys2.exe This shell is used only for maintenance of the MSYS2 installation, we don't use it for development in any way (because it is based on Cygwin, but we need a msvcrt.dll-based or ucrt.dll-based environment)

  3. Update package definitions:

    pacman -Syu
    pacman -Su
  4. Install minimal set of necessary packages. libssp is needed for DrMinGW.

    pacman -S mingw-w64-clang-x86_64-toolchain mingw-w64-clang-x86_64-libssp mingw-w64-clang-x86_64-ninja
  5. Now close you MSYS2.exe shell and open your normal windows terminal application (cmd.exe or CMDer)

  6. Add the path to Clang64 installation (c:\msys64\clang64\) to your environment file. Make sure that the path to Python comes before the path to Clang64. The latter also has installation of Python for LLDB, which has incompatible version. My file looks like this:

    set PATH=C:\deps\Python38;C:\msys64\clang64\bin\;%PATH%
    set PATH=%PATH%;C:\deps\Ninja\
    set BUILDROOT=c:\dev\env-11
    set PATH=%BUILDROOT%\i\bin\;%BUILDROOT%\i\lib;%PATH%
    set PATH=%BUILDROOT%\gettext\bin;%PATH%
    set PATH=%BUILDROOT%\i-dep\bin\;%BUILDROOT%\i-dep\lib;%PATH%
    set "WindowsSdkDir=%ProgramFiles(x86)%\Windows Kits\10"
    set "WindowsSdkVerBinPath=%ProgramFiles(x86)%\Windows Kits\10\bin\10.0.17763.0"
    set PYTHONPATH=%BUILDROOT%\i\lib\site-packages;%PYTHONPATH% 
  7. Build Krita deps

    cd b
    cmake ..\krita\3rdparty -DSUBMAKE_JOBS=16 -DQT_ENABLE_DYNAMIC_OPENGL=on -DEXTERNALS_DOWNLOAD_DIR=c:/dev/env-11/d -DINSTALL_ROOT=c:/dev/env-11/i -G "MinGW Makefiles" -DENABLE_PYTHON_DEPS=ON -DUSE_QT_TABLET_WINDOWS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
    set TARGETS=ext_patch ext_icoutils ext_lzma ext_qt ext_boost ext_exiv2 ext_fftw3 ext_eigen3 ext_ilmbase ext_jpeg ext_lcms2 ext_ocio ext_openexr ext_png ext_tiff ext_gsl ext_vc ext_libraw ext_giflib ext_freetype ext_kwindowsystem ext_drmingw ext_python ext_sip ext_pyqt ext_quazip ext_openjpeg ext_libheif ext_seexpr ext_mypaint
    for %i in (%TARGETS%) do ( cmake --build . --parallel 16 --target %i)
  8. Build Krita using Clang

    cd b-krita
    cmake ..\krita -DHIDE_SAFE_ASSERTS=OFF -G "CodeBlocks - Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=..\i -DCMAKE_INSTALL_PREFIX=..\i -DBUILD_TESTING=on
    ninja -j16 install
  9. Now you have Krita built with Clang! Congratulations! ;)

Edited by Dmitry Kazakov

Merge request reports