'''
G'MIC is a full-featured open-source framework for digital image processing. It provides a large deal of functions to convert / process / visualize generic image datasets, ranging from 1D scalar signals to 3D+t sequences of multi-spectral volumetric images, hence including 2D color images.
G'MIC is available on Windows and a variety of Linux machines and there were also instructions to compile G'MIC on MacOS. However, support for these instructions was outdated. In case nayone needs this great piece of software on a Mac, you might find the following shell script useful. Just download and execute. It should create qmic
and gmic_qt
and put it into /usr/local/bin
. Note that you might see some warnings, which you can (or at least: I could) safely ignore. Note that you need Homebrew installed to run the script.
#/bin/bash
#
# Compile g'mic on MacOS. Tested on MacOS Sequoia 15.0.
# Homebrew is required and warnings can probably be igored.
# Copyright 2024 by Helmut Kaufmann.
#
# Install libraries and compilers
brew install --quiet opencv libheif fftw llvm libomp ffmpeg
# Set environment variables
# Note that LLVM-capable C and C++ compilers are needed, hence the settings for CC and CXX
export CC=/usr/bin/clang -mcpu=apple-m1
export CXX=/usr/bin/clang++ -mcpu=apple-m1
export C_FLAGS=-Ofast
export CPLUS_FLAGS=-Ofast
export C_INCLUDE_PATH=-I/opt/X11/include
export CPLUS_INCLUDE_PATH=
export LD_LIBRARY_PATH=
export PKG_CONFIG_PATH=
export CONFIG+=openmp
export CMAKE_OSX_ARCHITECTURES=arm64
export QMAKE_CC=/usr/bin/clang
export QMAKE_CXX=/usr/bin/clang++ -I/opt/homebrew/include
export QMAKE_LINK="/usr/bin/clang++ -L/usr/lib -L/opt/homebrew/lib"
export QMAKE_CFLAGS=-I/opt/homebrew/include
export QMAKE_CXXFLAGS=-I/opt/homebrew/include
# Get or update required repositories
git clone https://github.com/GreycLab/gmic 2> /dev/null || git -C gmic pull
git clone https://github.com/GreycLab/CImg 2> /dev/null || git -C CImg pull
git clone https://github.com/GreycLab/gmic-community 2> /dev/null || git -C gmic-community pull
git clone https://github.com/c-koi/gmic-qt 2> /dev/null || git -C gmic-qt pull
#
# Build gmic
#
# First, determine current gmic version
cd gmic/src
RELEASE0=`grep "#define gmic_version" gmic.h | tail -c 5`
RELEASE1=`echo $RELEASE0 | head -c 1`
RELEASE2=`echo $RELEASE0 | head -c 2 | tail -c 1`
RELEASE3=`echo $RELEASE0 | head -c 3 | tail -c 1`
# Second, set and display version identifier
VERSION=$RELEASE1.$RELEASE2.$RELEASE3
DATE=$(date "+%Y-%m-%d-%H:%M:%S")
echo "Building version as of "
# Third, build gmic
# make clean
make -B OPENCV_CFLAGS="$(shell pkg-config opencv4 --cflags)" OPENCV_LIBS="$(shell pkg-config opencv4 --libs)" EXTRA_CFLAGS="-I/opt/homebrew/include -I/opt/homebrew/include/opencv4 -I/opt/local/include -march=native -flto -Wno-unused-parameter -Wno-c11-extensions -Wno-deprecated-declarations -Wno-c++17-extensions -Wno-variadic-macros -Dcimg_use_opencv $(OPENCV_CFLAGS) -Dcimg_use_heif" EXTRA_LIBS="$(OPENCV_LIBS) -L/opt/homebrew/lib -lheif" QMAKE_CC=/usr/bin/clang QMAKE_CXX="/usr/bin/clang++ -I/opt/homebrew/include" QMAKE_LINK="/usr/bin/clang++ -L/usr/lib -L/opt/homebrew/lib" "QMAKE_CFLAGS=-I/opt/homebrew/include" "QMAKE_CXXFLAGS=-I/opt/homebrew/include" QMAKE_EXPORT_ARCH_ARGS="''" QTPLUGIN.platforms=- CMAKE_OSX_ARCHITECTURES=arm64 cli
cd ../..
#
# Build gmic-qt
# exit 0
make -C gmic/src CImg.h gmic_stdlib_community.h
cd gmic-qt
qmake LFLAGS=-L/opt/homebrew/lib CONFIG+= HOST=none GMIC_PATH=../gmic/src QMAKE_CC=/usr/bin/clang QMAKE_CXX=/usr/bin/clang++ QMAKE_LINK="/usr/bin/clang++ -L/usr/lib -L/opt/homebrew/lib" "QMAKE_CFLAGS=-I/opt/homebrew/include" "QMAKE_CXXFLAGS=-I/opt/homebrew/include" QMAKE_EXPORT_ARCH_ARGS="''" QTPLUGIN.platforms=- CMAKE_OSX_ARCHITECTURES=arm64
make -B "SUBLIBS=-lX11"
cd ..
#
# Copy executables
#
sudo cp gmic/src/gmic gmic-qt/gmic_qt.app/Contents/MacOS/gmic_qt /usr/local/bin/
echo "Build complete and copied to /usr/local/bin - Enjoy!"