# Copyright 1999-2025 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 CMAKE_MAKEFILE_GENERATOR="emake" CMAKE_BUILD_TYPE=Release inherit bash-completion-r1 cmake flag-o-matic qmake-utils toolchain-funcs DESCRIPTION="GREYC's Magic Image Converter" HOMEPAGE="https://gmic.eu/ https://github.com/GreycLab/gmic https://github.com/GreycLab/gmic-qt" # gmic-qt versioning differs from gmic core - use latest compatible version GMIC_QT_PV="3.5.0" GMIC_QT_URI="https://github.com/GreycLab/gmic-qt/archive/v.${GMIC_QT_PV}.tar.gz -> gmic-qt-${GMIC_QT_PV}.tar.gz" SRC_URI="https://gmic.eu/files/source/gmic_${PV}.tar.gz -> ${P}.tar.gz gimp? ( ${GMIC_QT_URI} ) gui? ( ${GMIC_QT_URI} ) " GMIC_QT_DIR="gmic-qt-v.${GMIC_QT_PV}" S="${WORKDIR}/${PN}-${PV}" LICENSE="CeCILL-2 GPL-3" SLOT="0" KEYWORDS="~amd64 ~x86" IUSE="bash-completion +cli ffmpeg fftw gimp graphicsmagick gui jpeg opencv openexr openmp png static-libs tiff X" REQUIRED_USE=" || ( cli gimp gui ) gimp? ( png fftw X ) gui? ( png fftw X ) " QT_DEPS=" dev-qt/qtbase:6[gui,network,widgets] " COMMON_DEPEND=" fftw? ( sci-libs/fftw:3.0=[threads] ) gimp? ( >=media-gfx/gimp-3.0.0 ${QT_DEPS} ) graphicsmagick? ( media-gfx/graphicsmagick:0= ) gui? ( ${QT_DEPS} ) jpeg? ( media-libs/libjpeg-turbo:0 ) media-libs/cimg net-misc/curl opencv? ( >=media-libs/opencv-2.3.1a-r1:0= ) openexr? ( dev-libs/imath:= media-libs/openexr:0= ) png? ( media-libs/libpng:0= ) sys-libs/zlib tiff? ( media-libs/tiff:0 ) X? ( x11-libs/libX11 x11-libs/libXext ) " RDEPEND="${COMMON_DEPEND} ffmpeg? ( media-video/ffmpeg:0= ) " DEPEND="${COMMON_DEPEND} gimp? ( dev-qt/qttools:6[linguist] ) gui? ( dev-qt/qttools:6[linguist] ) virtual/pkgconfig " pkg_pretend() { if use openmp ; then tc-check-openmp fi if ! test-flag-CXX -std=c++11 ; then die "You need at least GCC 4.7.x or Clang >= 3.3 for C++11-specific compiler flags" fi } src_prepare() { cmake_src_prepare ln -sr "${S}" "${WORKDIR}/${PN}" || die if use gimp || use gui ; then sed -i \ -e '/CMAKE_CXX_FLAGS_RELEASE/d' \ "${WORKDIR}/${GMIC_QT_DIR}/CMakeLists.txt" || die "sed failed" local S="${WORKDIR}/${GMIC_QT_DIR}" cd "${WORKDIR}/${GMIC_QT_DIR}" || die patch -p1 -i "${FILESDIR}/gmic-qt-3.5.0-stripping.patch" || die patch -p1 -i "${FILESDIR}/gmic-qt-3.5.0-system-gmic.patch" || die cd - || die cmake_src_prepare fi } src_configure() { # for "lrelease" local PATH="${PATH}:$(qt6_get_bindir)" local mycmakeargs=( -DBUILD_LIB=ON -DBUILD_LIB_STATIC=$(usex static-libs ON OFF) -DBUILD_CLI=$(usex cli ON OFF) -DBUILD_MAN=$(usex cli ON OFF) -DBUILD_BASH_COMPLETION=$(usex cli $(usex bash-completion ON OFF) OFF) -DENABLE_X=$(usex X ON OFF) -DENABLE_FFMPEG=$(usex ffmpeg ON OFF) -DENABLE_FFTW=$(usex fftw ON OFF) -DENABLE_GRAPHICSMAGICK=$(usex graphicsmagick ON OFF) -DENABLE_JPEG=$(usex jpeg ON OFF) -DENABLE_OPENCV=$(usex opencv ON OFF) -DENABLE_OPENEXR=$(usex openexr ON OFF) -DENABLE_OPENMP=$(usex openmp ON OFF) -DENABLE_PNG=$(usex png ON OFF) -DENABLE_TIFF=$(usex tiff ON OFF) -DENABLE_ZLIB=ON -DENABLE_DYNAMIC_LINKING=ON -DCUSTOM_CFLAGS=ON -DUSE_SYSTEM_CIMG=ON ) cmake_src_configure # gmic-qt local CMAKE_USE_DIR="${WORKDIR}/${GMIC_QT_DIR}" append-cppflags -I"${WORKDIR}/gmic/src" append-ldflags -L"${BUILD_DIR}" local qt_mycmakeargs=( -DENABLE_DYNAMIC_LINKING=ON -DENABLE_SYSTEM_GMIC=ON -DGMIC_LIB_PATH="${BUILD_DIR}" ) local BUILD_DIR if use gimp ; then BUILD_DIR=${WORKDIR}/gimp_build mycmakeargs=( "${qt_mycmakeargs[@]}" -DGMIC_QT_HOST=gimp3 ) cmake_src_configure fi if use gui; then BUILD_DIR=${WORKDIR}/gui_build mycmakeargs=( "${qt_mycmakeargs[@]}" -DGMIC_QT_HOST=none ) cmake_src_configure fi } src_compile() { cmake_src_compile # gmic-qt local S="${WORKDIR}/${GMIC_QT_DIR}" local BUILD_DIR if use gimp; then BUILD_DIR="${WORKDIR}/gimp_build" cmake_src_compile fi if use gui; then BUILD_DIR="${WORKDIR}/gui_build" cmake_src_compile fi } src_install() { dodoc README # - the Gimp plugin dir is also searched by non-Gimp tools, and it's # hardcoded in "gmic_stdlib.gmic" # - using the GMIC_SYSTEM_PATH env var to specify another system dir here # might mean that this big file will be automatically downloaded in # "~/.config/gmic/" when the user runs a tool before updating and sourcing # the new environment local PLUGIN_DIR if use gimp; then PLUGIN_DIR="/usr/$(get_libdir)/gimp/3.0/plug-ins/gmic_gimp_qt" fi if use gimp || use gui; then mkdir -p "${ED}/${PLUGIN_DIR}" || die insinto "${PLUGIN_DIR}" doins "resources/gmic_cluts.gmz" fi cmake_src_install # By default, "gmic.cpp" includes "gmic.h" which defines "cimg_plugin" to "gmic.cpp" and then # includes "CImg.h" which includes "cimg_plugin" which is "gmic.cpp", of course. # # Yes, upstream is bad and they should feel bad. Undo this madness so we can build media-gfx/zart # using the installed "gmic.h". sed -i -e '/^#define cimg.*_plugin/d' "${ED}/usr/include/gmic.h" || die "sed failed" use cli && use bash-completion && newbashcomp "${BUILD_DIR}/resources/${PN}_bashcompletion.sh" ${PN} # gmic-qt if use gimp; then exeinto "${PLUGIN_DIR}" doexe "${WORKDIR}/gimp_build/gmic_gimp_qt" fi if use gui; then dobin "${WORKDIR}/gui_build/gmic_qt" fi }