Compile/Install GTK4 on Ubuntu Focal 20.04 or Bionic 18.04

Submitted by Dickens A S on Thu, 08/12/2021 - 12:36

This article explains how compile GTK4 on Lower LTS versions of Ubuntu

Issue the following commands to deploy the dependency packages

sudo apt-get -y install libncurses5
sudo apt-get -y install libelf++0 libelf1 libelf-dev
sudo apt-get -y install libxml2 libxml2-dev libxml2-utils 
sudo apt-get -y install libxslt1-dev libxslt1.1
sudo apt-get -y install sysprof libpango1.0-dev
sudo apt-get -y install libpango-1.0-0 libpangocairo-1.0-0
sudo apt-get -y install libglib2.0-0 libglib2.0-dev
sudo apt-get -y install libxkbcommon-dev libxrandr-dev libxrender-dev
sudo apt-get -y install libxi-dev libxdamage-dev libxfixes-dev
sudo apt-get -y install libxext-dev libxcursor-dev libfontconfig-dev
sudo apt-get -y install libx11-dev libwayland-dev libpng-dev
sudo apt-get -y install libc6-dev libc6 libc6-amd64 libc++-10-dev
sudo apt-get -y install libc++-dev 
sudo apt-get -y install libpng++-dev libpng-dev libpng16-16 
sudo apt-get -y install libjpeg-dev libjpeg62 libjpeg8 libjpeg8-dev
sudo apt-get -y install libspectre-dev libspectre1
sudo apt-get -y install librsvg2-2 librsvg2-dev
sudo apt-get -y install libpixman-1-0 libpixman-1-dev
sudo apt-get -y install libxcb-shm0 libxcb-shm0-dev
sudo apt-get -y install cairo-5c
sudo apt-get -y install libicu-dev libthai-dev
sudo apt-get -y install libvulkan-dev libvulkan1
sudo apt-get -y install libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-dev
sudo apt-get update
sudo apt-get -y install libegl1-mesa libegl1-mesa-dev
sudo apt-get -y install libgles2-mesa-dev libglfw3-dev libglfw3
sudo apt-get -y install libglew-dev libglew2.1
sudo apt-get -y install ffmpeg libatk1.0-dev libglm-dev iso-codes
sudo apt-get -y install libgraphene-1.0-dev libgraphene-1.0-0 
sudo apt-get -y install sassc hicolor-icon-theme libglib2.0-0
sudo apt-get -y install libglib2.0-dev pkg-config bison gettext
sudo apt-get -y install xsltproc 
sudo apt-get -y install libpython3.9 --fix-missing
sudo apt-get -y install python3.9-full
sudo apt-get -y install python3.9-dev

Install pip for mesa, ninja and cmake

sudo wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install --upgrade setuptools 
sudo python3 -m pip install --upgrade wheel
sudo python3 -m pip install meson
sudo python3 -m pip install ninja
sudo python3 -m pip install cmake

Checkout and compile a custom version of glib2

Change the version tags/2.68.3 accordingly to your needs

sudo mkdir build
sudo mkdir build/glib2
sudo git clone https://github.com/GNOME/glib.git build/glib2
sudo git --work-tree=build/glib2 --git-dir=build/glib2/.git checkout tags/2.68.3 -b 2.68.3
sudo mkdir build/glib2/_build
sudo meson -Dprefix=/usr -Dtests=false build/glib2/_build build/glib2
sudo ninja -C build/glib2/_build -j 1
sudo ninja -C build/glib2/_build install

Checkout and compile a custom version of pango

Change the version tags/1.48.7 accordingly to your needs

sudo mkdir build/pango
sudo git clone https://github.com/GNOME/pango.git build/pango
sudo git --work-tree=build/pango --git-dir=build/pango/.git checkout tags/1.48.7 -b 1.48.7
sudo mkdir build/pango/_build
sudo meson -Dprefix=/usr -Dgtk_doc=false build/pango/_build build/pango
sudo ninja -C build/pango/_build -j 1
sudo ninja -C build/pango/_build install

For bionic, you need to manually compile vulkan

Change the tags/v1.2.179 accordingly for your needs

sudo mkdir build/vulkan
sudo git clone https://github.com/KhronosGroup/Vulkan-Headers.git build/vulkan
sudo git --work-tree=build/vulkan --git-dir=build/vulkan/.git checkout tags/v1.2.179 -b v1.2.179
sudo mkdir build/vulkan/_build
sudo cmake build/vulkan -B build/vulkan/_build -DCMAKE_INSTALL_PREFIX=/usr
sudo cmake --build build/vulkan/_build --target install

sudo rm -fr build/vulkan
sudo mkdir build/vulkan
sudo git clone https://github.com/KhronosGroup/Vulkan-Loader.git build/vulkan
sudo git --work-tree=build/vulkan --git-dir=build/vulkan/.git checkout tags/v1.2.179 -b v1.2.179
sudo mkdir build/vulkan/_build
sudo cmake build/vulkan -B build/vulkan/_build -DCMAKE_INSTALL_PREFIX=/usr
sudo cmake --build build/vulkan/_build --target install

Checkout and compile a custom version of GTK4

Change the version tags/4.0 accordingly to your needs

sudo mkdir build/gtk4
sudo git clone https://github.com/GNOME/gtk.git build/gtk4
sudo git --work-tree=build/gtk4 --git-dir=build/gtk4/.git checkout tags/4.0 -b 4.0
sudo mkdir build/gtk4/_build
sudo meson -Dprefix=/usr -Dvulkan=enabled -Dwayland-backend=false -Dbroadway-backend=false -Dprint-backends=none -Dman-pages=false -Dgtk_doc=false -Ddemos=false -Dmedia=ffmpeg -Dbuild-examples=false -Dbuild-tests=false -Dinstall-tests=false build/gtk4/_build build/gtk4
sudo ninja -C build/gtk4/_build -j 1
sudo ninja -C build/gtk4/_build install

Finished!

Add new comment