macOS Sierra (10.12.3) 上で krita (3.1.88, git d007680) をビルドしました。krita のバイナリが mac 向けに安定版として公開されたのがバージョン 3.1 からということもあり、情報が少なく、はまりどころもいくつかあったので今後のためにビルド手順をまとめておきます。

ビルド手順

作業ディレクトリは適宜読み替えて下さい。私の場合は $HOME/Documents/repos/kritaです。

0. 参考リンク

1. ソースのダウンロード

$ git clone https://anongit.kde.org/krita.git src

2. 依存ライブラリのインストール

依存ライブラリの一覧は krita/README_PACKAGERS.md にあります。

私の環境で追加インストールが必要だったライブラリは以下の通りです。(上 3 つのみ必須で残りは optional)

vc 以外は homebrew パッケージがあるので homebrew でインストールし、vc はソースからビルドしました。

KDE framework 5 のインストール (https://github.com/haraldF/homebrew-kf5)

$ brew tap haraldf/kf5
$ cd /usr/local/Homebrew/Library/Taps/haraldf/homebrew-kf5/
$ ./tools/install.sh

その他ライブラリのインストール

$ brew install exiv2 lcms2 gsl libraw ocio
$ brew install poppler --with-qt5

vc のインストール

$ mkdir vc
$ cd vc
$ git clone https://github.com/VcDevel/Vc
$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/opt/Vc -DBUILD_TESTING=OFF ../Vc/
$ make -j5
$ make install

3. 環境に応じた修正

この状態で krita をビルドすると、私の環境では Qt と OpenEXR 周りのエラーが発生したので src/CMakeLists.txt の末尾付近 (最後の include_directories の出現の直後; 632 行目) に

include_directories(BEFORE /usr/local/opt/qt5/include)
include_directories(BEFORE /usr/local/include/OpenEXR)

を追加しました。

一行目は Qt5 と Qt4 が両方ともインストールされている場合に誤って Qt4 のヘッダが読み込まれないようにするためで、二行目は OpenEXR/half.hhalf.h としてインクルードされている部分があり手元の環境ではパスが通っていなかったためです。

4. ビルド

$ PATH="/usr/local/opt/gettext/bin:$PATH" cmake -DCMAKE_INSTALL_PREFIX=$HOME/Documents/repos/krita/inst $HOME/Documents/repos/krita/src -DWITH_GMIC=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPRODUCTSET=ALL -DPACKAGERS_BUILD=ON -DBUILD_TESTING=OFF -DKDE4_BUILD_TESTS=OFF -DCMAKE_PREFIX_PATH="/usr/local/Cellar/qt5/5.8.0_1/lib/cmake;/opt/Vc/lib/cmake"
$ make -j5
$ make -j5 install

ポイント

5. 実行

ビルドできても実行までにやや手間がかかります。

make install 終了時には /Application/KDE/krita.app/ 以下は次のようなファイル構成になっていると思います (私はそうでした)。

$ tree
.
└── krita.app
    └── Contents
        ├── Info.plist
        ├── MacOS
        │   └── krita
        └── Resources
            └── krita_SRCS.icns

作業ディレクトリ $HOME/Documents/repos/krita/ 以下は次のようになりました。

$ tree -L 2
.
├── build
│   ├── CMakeCache.txt
│   ... (略)
│   └── plugins
├── inst
│   ├── etc
│   ├── lib
│   └── share
└── src
    ├── 3rdparty
    ... (略)
    └── winquirks

krita バイナリ配布版のディレクトリ構成を参考にリンクを張ります。

$ ln -s $HOME/Documents/repos/krita/inst/lib /Applications/KDE/krita.app/Contents/Frameworks
$ ln -s $HOME/Documents/repos/krita/inst/lib/kritaplugins /Applications/KDE/krita.app/Contents/PlugIns
$ ln -s $HOME/Documents/repos/krita/inst/share/* /Applications/KDE/krita.app/Contents/Resources
$ ln -s $HOME/Documents/repos/krita/inst/share /Applications/KDE/krita.app/Contents

(煩雑ですがミニマルなつもりです)

/Applications/KDE/krita.app/ 以下は次のようになりました。

$ tree -L 4
.
└── krita.app
    └── Contents
        ├── Frameworks -> /Users/arcturu/Documents/repos/krita/inst/lib
        ├── Info.plist
        ├── MacOS
        │   └── krita
        ├── PlugIns -> /Users/arcturu/Documents/repos/krita/inst/lib/kritaplugins
        ├── Resources
        │   ├── applications -> /Users/arcturu/Documents/repos/krita/inst/share/applications
        │   ├── color -> /Users/arcturu/Documents/repos/krita/inst/share/color
        │   ├── color-schemes -> /Users/arcturu/Documents/repos/krita/inst/share/color-schemes
        │   ├── icons -> /Users/arcturu/Documents/repos/krita/inst/share/icons
        │   ├── krita -> /Users/arcturu/Documents/repos/krita/inst/share/krita
        │   ├── krita_SRCS.icns
        │   ├── kritaplugins -> /Users/arcturu/Documents/repos/krita/inst/share/kritaplugins
        │   └── metainfo -> /Users/arcturu/Documents/repos/krita/inst/share/metainfo
        └── share -> /Users/arcturu/Documents/repos/krita/inst/share

これでアイコンをクリックするか、$ /Applications/KDE/krita.app/Contents/MacOS/krita で起動します。

OpenMP について

Xcode についている clang (Apple LLVM version 8.0.0 (clang-800.0.42.1)) は現状 OpenMP に対応していません。OpenMP に対応させるには clang 3.7.0 以上か gcc 4.2 以上を使えばよいらしい (Macでclang+OpenMP 2016) ので gcc 6.2.0 で試しましたが、ビルドできませんでした。以下エラー抜粋です。

[  2%] Building CXX object libs/widgetutils/CMakeFiles/kritawidgetutils.dir/KoResourcePaths.cpp.o
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/Availability.h:184:0,
                 from /usr/local/opt/qt5/include/QtCore/qsystemdetection.h:236,
                 from /usr/local/opt/qt5/include/QtCore/qglobal.h:95,
                 from /usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qscopedpointer.h:43,
                 from /usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/QScopedPointer:1,
                 from /Users/arcturu/Documents/repos/krita/src/libs/widgetutils/KoResourcePaths.h:21,
                 from /Users/arcturu/Documents/repos/krita/src/libs/widgetutils/KoResourcePaths.cpp:18:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
                                  ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
                                  ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
                                  ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
                                  ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:54:35: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithMonth API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 1),
                                   ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:54:35: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithMonth API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 1),
                                   ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:54:35: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithMonth API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 1),
                                   ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:54:35: error: 'introduced' was not declared in this scope
     kCFISO8601DateFormatWithMonth API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 1),

これは cmake fails to build on macOS Sierra with GCC@6.2.0 · Issue #1847 · LLNL/spack と全く同じ問題だと思われます。clang では C と Objective-C のごった煮もビルドできるが gcc では問題があるらしい。gcc もランタイムを用意すれば Objectove-C コードをビルドできる (CentOS6 に Objective-C 環境を整える - Qiita) そうなのでなんとかなりそうな気もしますが、新しい clang を使ったほうが簡単そうです。

また、gcc では以下のような警告も出ます。(参考: warning: section “__textcoal_n” is deprecate since updating to Mac OSX Sierra [duplicate])

[  1%] Building CXX object libs/version/CMakeFiles/kritaversion.dir/KritaVersionWrapper.cpp.o
/var/folders/ky/fzyv5cp90c16t7kxbq9c_hf80000gn/T//ccsMpiqj.s:3:11: warning: section "__textcoal_nt" is deprecated
        .section __TEXT,__textcoal_nt,coalesced,pure_instructions
                 ^      ~~~~~~~~~~~~~
/var/folders/ky/fzyv5cp90c16t7kxbq9c_hf80000gn/T//ccsMpiqj.s:3:11: note: change section name to "__text"
        .section __TEXT,__textcoal_nt,coalesced,pure_instructions

落とし穴

ビルド手順 3 の include_directories(BEFORE /usr/local/opt/qt5/include) を追加していない状態でビルドすると以下のようなエラーが出ました。原因は Qt4 のヘッダファイルが誤って読み込まれてしまい、Qt5 で新しく定義されたマクロが展開できなかったことだと考えられます。

[  0%] Building CXX object libs/version/CMakeFiles/kritaversion.dir/KritaVersionWrapper.cpp.o
In file included from /usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/QString:1:0,
                 from /Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.h:22,
                 from /Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp:18:
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qstring.h:576:24: error: missing binary operator before token "("
 #if QT_DEPRECATED_SINCE(5, 0)
                        ^
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qstring.h:1052:24: error: missing binary operator before token "("
 #if QT_DEPRECATED_SINCE(5, 3)
                        ^
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qstring.h:1081:24: error: missing binary operator before token "("
 #if QT_DEPRECATED_SINCE(5, 0)
                        ^
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qstring.h:1481:24: error: missing binary operator before token "("
 #if QT_DEPRECATED_SINCE(5, 0)
                        ^
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qstring.h:1756:24: error: missing binary operator before token "("
 #if QT_DEPRECATED_SINCE(5, 0)
                        ^
In file included from /usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qstring.h:50:0,
                 from /usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/QString:1,
                 from /Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.h:22,
                 from /Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp:18:
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qrefcount.h:54:21: error: expected ';' at end of member declaration
     inline bool ref() Q_DECL_NOTHROW {
                     ^
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qrefcount.h:54:23: error: 'Q_DECL_NOTHROW' does not name a type
     inline bool ref() Q_DECL_NOTHROW {
                       ^~~~~~~~~~~~~~
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qrefcount.h:65:23: error: expected ';' at end of member declaration
     inline bool deref() Q_DECL_NOTHROW {
                       ^
/usr/local/Cellar/qt5/5.8.0_1/lib/QtCore.framework/Headers/qrefcount.h:65:25: error: 'Q_DECL_NOTHROW' does not name a type
     inline bool deref() Q_DECL_NOTHROW {
                         ^~~~~~~~~~~~~~
                              ^
(中略)


/Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp:30:30: error: 'const struct QStaticStringData<7>' has no member named 'data_ptr'; did you mean 'data'?
         QString gitVersion = QStringLiteral(KRITA_GIT_SHA1_STRING);
                              ^
/Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp: In lambda function:
/Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp:31:19: error: 'QStringData' was not declared in this scope
         version = QStringLiteral("%1 (git %2)").arg(kritaVersion, gitVersion);
                   ^
/Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp:31:19: error: braces around scalar initializer for type 'qunicodechar {aka char16_t}'
         version = QStringLiteral("%1 (git %2)").arg(kritaVersion, gitVersion);
                   ^
/Users/arcturu/Documents/repos/krita/src/libs/version/KritaVersionWrapper.cpp:31:19: error: 'const struct QStaticStringData<11>' has no member named 'data_ptr'; did you mean 'data'?
         version = QStringLiteral("%1 (git %2)").arg(kritaVersion, gitVersion);
                   ^
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-deprecated-register'
cc1plus: warning: unrecognized command line option '-Wno-macro-redefined'
make[2]: *** [libs/version/CMakeFiles/kritaversion.dir/KritaVersionWrapper.cpp.o] Error 1
make[1]: *** [libs/version/CMakeFiles/kritaversion.dir/all] Error 2
make: *** [all] Error 2

OpenEXR/half.h へのパスが通っていないときは以下のようなエラーが出ます。

Scanning dependencies of target kritapigment
[  5%] Building CXX object libs/pigment/CMakeFiles/kritapigment.dir/DebugPigment.cpp.o
[  5%] Building CXX object libs/pigment/CMakeFiles/kritapigment.dir/KoBasicHistogramProducers.cpp.o
/Users/arcturu/Documents/repos/krita/src/libs/pigment/KoBasicHistogramProducers.cpp:26:10: fatal error:
      'half.h' file not found
#include <half.h>

/Applications/KDE/krita.app/ 以下のディレクトリ構成は重要で、例えば /Applications/KDE/krita.app/PlugIns/ がないと The Calligra LittleCMS color management plugin is not installed. Krita will quit now. というポップアップが出て強制終了します。

The Calligra LittleCMS color management plugin is not installed. Krita will quit now.
comments powered by Disqus