So here is the full procedure to build G’MIC! Based on building on a Debian stable (except I target it to Ubuntu users, since @David_Tschumperle is using Ubuntu, so I use sudo
for few root-needing commands) .
- Install crossroad!
$ git clone git://git.tuxfamily.org/gitroot/crossroad/crossroad.git
$ cd crossroad
$ pip3 install -r requirements.txt
$ ./setup.py build && ./setup.py install
(obviously a --prefix
option is available to the install
subcommand if preferred)
- Just as for a native build, following
README.md
:
$ git clone https://github.com/dtschump/gmic.git
$ git clone https://github.com/c-koi/gmic-qt.git
$ make -C gmic/src CImg.h gmic_stdlib.h
- Let’s make sure we have C and C++ cross-compilers:
$ crossroad -h w64
w64: Setups a cross-compilation environment for Microsoft Windows operating systems (64-bit).
Not available. Some requirements are missing:
- x86_64-w64-mingw32-gcc [package "gcc-mingw-w64-x86-64"] (missing)
- x86_64-w64-mingw32-ld [package "binutils-mingw-w64-x86-64"] (missing)
$ sudo apt install binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64
[…]
$ crossroad -h w64
w64: Setups a cross-compilation environment for Microsoft Windows operating systems (64-bit).
Installed language list:
- C
Uninstalled language list:
- Ada Common package name providing the feature: gnat-mingw-w64-x86-64
- C++ Common package name providing the feature: g++-mingw-w64-x86-64
- OCaml Common package name providing the feature: mingw-ocaml
- Objective C Common package name providing the feature: gobjc++-mingw-w64-x86-64
- fortran Common package name providing the feature: gfortran-mingw-w64-x86-64
$ sudo apt install g++-mingw-w64-x86-64
$ crossroad -h w64
[…]
Installed language list:
- C
- C++
[…]
- Ok now we have the basics to build for Windows 64-bit. Let’s enter the crossroad environment. I will call it
gmic
:
$ crossroad w64 gmic
⤫ ccd -y gmic-qt
⤫ crossroad source msys2
Note: you will notice I use a different prompt in my tutorial to show when I am inside crossroad (⤫
) or not ($
).
- Finally let’s configure. We will use CMake (Crossroad supports autotools, meson and CMake only, but not
qmake
, patches accepted!), so it obviously has to be installed as well, if not already (sudo apt install cmake
), same for pkg-config
(sudo apt install pkg-config
). I could just do a one-liner with all crossroad dependencies, but I will take the opportunity to show how the package manager works by discovering the first dependency issue together.
⤫ crossroad cmake /path/to/src/gmic-qt/
[…]
CMake Error at CMakeLists.txt:129 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" (requested
version 5.2.0) with any of the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/jehan/.local/share/crossroad/artifacts/w64/gmic/gmic-qt/CMakeFiles/CMakeOutput.log".
⤫ crossroad search --search-files Qt5Config.cmake
[…]
The following packages have files matching the search "Qt5Config.cmake":
- phonon-qt5
- qca-qt5
- qt5
- qt5-static
- snorenotify
⤫ crossroad install qt5
Now re-run crossroad cmake /path/to/src/gmic-qt/
, check the next dependency error, search the package with crossroad search --search-files
, install and so on. Loop on. I will spare you each run. Here is the command to install remaining missing dependencies:
⤫ crossroad install fftw curl gimp
Note: the gimp
dependency is for building with GMIC_QT_HOST=gimp
(the default, which is the only tested so far) as it requires to link against libgimp
. That pulls quite a lot of dependencies, but obviously they won’t be necessary after the build.
- Special case: the build needs to call some Qt binaries (
moc
and rcc
) and I have not figured out yet if we can use native ones. But also even if the format is the same, native tools may not be the same version as the used Windows Qt libraries (apparently it’s important as I see that there is a wrapper tool called qtchooser
to select the right Qt binary depending on your version/target, etc.). I didn’t want to spend too long figuring out what was what so I just rely on Wine for this and it works fine (no build issue on a Fedora 31 and a Debian stable at least). Therefore I temporarily install Wine as a binfmt_misc
interpreter for Windows binaries.
$ sudo apt install wine
$ sudo sh -c "echo ':DOSWin:M::MZ::/usr/bin/wine:' > /proc/sys/fs/binfmt_misc/register"
Note: I use $
as it doesn’t need to be run from inside the crossroad environment, but whatever. It would work inside ⤫
as well.
- Configure again and now it should be a success!
⤫ crossroad cmake /path/to/src/gmic-qt/
crossroad info: running "cmake -DCMAKE_INSTALL_PREFIX:PATH=$CROSSROAD_PREFIX -DCMAKE_TOOLCHAIN_FILE=$CROSSROAD_CMAKE_TOOLCHAIN_FILE /path/to/src/gmic-qt/"
-- Using CMake version: 3.13.4
Build type is Release
Building for target host application: gimp
G'MIC path: ../gmic/src
LTO is disabled (windows platform)
Found G'MIC repository
Found ../gmic/src/CImg.h
Found ../gmic/src/gmic_stdlib.h
CImg version is [293]
G'MIC version is [293]
-- Correctly found FFTW3
G'Mic: using OpenMP
-- The following OPTIONAL packages have been found:
* CURL
* OpenMP, A low-level parallel execution library, <http://openmp.org/wp/>
Optionally used by gmic-qt
-- The following REQUIRED packages have been found:
* Qt5Core
* Qt5Gui
* Qt5Widgets
* Qt5Network
* Qt5 (required version >= 5.2.0)
* Qt5LinguistTools
* PNG
* ZLIB
* FFTW3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jehan/.local/share/crossroad/artifacts/w64/gmic/gmic-qt
- Now build:
⤫ make
[…]
[100%] Linking CXX executable gmic_gimp_qt.exe
[100%] Built target gmic_gimp_qt
⤫ make install
[ 1%] Automatic MOC for target gmic_gimp_qt
[ 1%] Built target gmic_gimp_qt_autogen
[100%] Built target gmic_gimp_qt
Install the project...
-- Install configuration: "Release"
-- Installing: /home/jehan/.local/share/crossroad/roads/w64/gmic/lib/gimp/2.0/plug-ins/gmic_gimp_qt.exe
You may take a rest while watching the build, surf the web, watch webcomics or movies, etc. Unlike a native build in a VM, a cross-build won’t take more time that a native Linux build, and won’t kill your resource usage (not more than a native Linux build again; technically it’s exactly the same except that the output format is different, that’s all). On a very non-powerful micro machine, full build took about 20 minutes.
- The files will be found under
$CROSSROAD_PREFIX
. In particular, the GIMP plug-in for instance will be in $CROSSROAD_PREFIX/lib/gimp/2.0/plug-ins/gmic_gimp_qt.exe
:
⤫ file $CROSSROAD_PREFIX/lib/gimp/2.0/plug-ins/gmic_gimp_qt.exe
/home/jehan/.local/share/crossroad/roads/w64/gmic/lib/gimp/2.0/plug-ins/gmic_gimp_qt.exe: PE32+ executable (GUI) x86-64 (stripped to external PDB), for MS Windows
Nice we have a Windows binary! Small bonus for packaging: you may look for the library dependencies automatically with x86_64-w64-mingw32-objdump
(which come with the binutils-mingw-w64-x86-64
package which we already installed).
⤫ x86_64-w64-mingw32-objdump -p $CROSSROAD_PREFIX/lib/gimp/2.0/plug-ins/gmic_gimp_qt.exe |grep dll
DLL Name: Qt5Core.dll
DLL Name: Qt5Gui.dll
DLL Name: Qt5Network.dll
DLL Name: Qt5Widgets.dll
DLL Name: libbabl-0.1-0.dll
DLL Name: libcurl-4.dll
DLL Name: libfftw3-3.dll
DLL Name: libgegl-0.4-0.dll
DLL Name: libgimp-2.0-0.dll
DLL Name: libgobject-2.0-0.dll
DLL Name: libpng16-16.dll
DLL Name: libgcc_s_seh-1.dll
DLL Name: libgomp-1.dll
DLL Name: libstdc++-6.dll
DLL Name: GDI32.dll
DLL Name: KERNEL32.dll
DLL Name: msvcrt.dll
DLL Name: SHELL32.dll
DLL Name: USER32.dll
DLL Name: zlib1.dll
Then recursively do the same thing for each DLL, so that you get the full list of dependencies you need to package. Siril for instance automatized this process with a Python script calling this tool recursively (which is pretty cool so I am planning on using the same thing for GIMP).
- You may reset the
binfmt_misc
configuration to not run Windows binaries by mistake on your pretty Linux box (note that this was not a permanent change anyway and would have been resetted after reboot):
sudo sh -c "echo -1 > /proc/sys/fs/binfmt_misc/DOSWin"
- Enjoy G’MIC with a beer, a glass of wine, kir, whisky, schnaps, soda, water, juice… whatever suits you!
Note: a lot of these steps are only to be done once or automatized a bit more. So on next builds, it will be a lot faster.