Skip to content

CMake Build System for Linux

Martin Winter edited this page Feb 3, 2024 · 3 revisions

Build systems for OpenBoard

Note: The cmake build system is a community contribution and not officially maintained. Please send questions, suggestions and bug reports to letsfindaway.

Starting with version 1.7.1, OpenBoard comes with two build systems that fulfill different requirements.

  • The qmake based build system is the default build used to build the release packages for OpenBoard.
  • The cmake based build system supports community builds with an FHS compliant layout.

Both approaches have their own specific purpose.

qmake

The qmake based build system is tailored to create installable packages for Windows, MacOS and Linux, especially Ubuntu. The Linux packages install into /opt/openboard. They may include a bundled version of Qt if needed. This provides some independence from the packages provided by the distribution. However, the build files may need to be modified for distributions other than Ubuntu.

cmake

The cmake based build system focuses on Linux only. The package layout is FHS compliant, i.e. the binary installs into /usr/bin, the data files into /usr/share/openboard, etc. The build files aim to be universal for many different distributions and use the cmake and pkgconfig mechanisms to locate include files and libraries.

What to choose

If you want to build OpenBoard for Windows or MacOS, then qmake is the way to go. For Linux builds, it depends.

  • If you are on Ubuntu and want to create the same package layout as the released packages, then use qmake as well.
  • If you are on any other distribution, or want to build an FHS compliant package, then use cmake.

Building OpenBoard with cmake

Dependencies

Building OpenBoard requires the following dependencies to be installed:

  • Qt 5.15 or Qt 6 (at least up to 6.6) with the following modules
    • Core
    • Concurrent
    • DBus
    • Multimedia
    • MultimediaWidgets
    • Network
    • PrintSupport
    • Svg
    • SvgWidgets (Qt 6 only)
    • UiTools
    • WebEngineWidgets
    • Xml
    • LinguistTools (only binaries, development files not required)
  • ffmpeg-4, ffmpeg-5 or fmpeg-6
  • openssl 1.1 or openssl 3.0
  • poppler (at least up to 23.12)
  • quazip 1.x

The following build tools are required:

  • gcc >= 10
  • cmake >= 3.16
  • pkg-config
  • make or ninja

Each distribution may have different names for the packages that provide these dependencies, so we cannot provide a complete list of packages to install in every case. For some distributions, we plan to provide a list of package names on a separate wiki page.

Configure

The configuration stage checks dependencies and populates the build directory. It is recommended to use a separate build directory. In the following we will use a directory called build in the project directory, but any other directory name and location can be used.

If you have multiple Qt versions installed in parallel, you need to specify which version to use (5 or 6). You also need to specify the prefix for the installation, which should normally be /usr:

# start in the project directory
mkdir build
cmake -S . -B build [-G Ninja] -DCMAKE_INSTALL_PREFIX:PATH=/usr [-DQT_VERSION=5|6] [-DCMAKE_BUILD_TYPE=Debug|Release|RelWithDebInfo]

This command sets up all the necessary build files in the build directory. The -G Ninja parameter selects ninja as the build tool, which typically provides faster parallel builds than the default make. The build type is used to select a debug or release build, with or without debug info. The default is a debug build. If you want to run OpenBoard later without installing it on your system, select a debug build (see below).

If the Qt version is not specified, the available Qt version will be detected automatically. If Qt 5 and Qt 6 are installed at the same time, Qt 5 is preferred.

If any dependencies are missing, cmake will detect them at this stage.

Build

Now build OpenBoard. Change to the build directory and run cmake:

cd build
cmake --build .

(Optionally) Install

At this point you can install OpenBoard on your system. However, directly installing a self-compiled application without first packaging it is not recommended. Instead, we suggest that you build a package (see below) and install it using your package manager. This has the advantages that

  • the package manager knows about the package;
  • you can uninstall the package later using the package manager;
  • when upgrading, your changes to the configuration files in /etc/openboard are preserved.

To run and test the newly compiled OpenBoard, you can install it into a directory in your home directory and run it from there. This requires that you have selected a debug build before.

As an example, we install OpenBoard to ~/Programs/openboard and run it as follows:

# install OpenBoard to a local directory specified by DESTDIR
mkdir -p ~/Programs/openboard
DESTDIR=~/Programs/openboard cmake --install

# run OpenBoard from there and specify the local install directory by OPENBOARD_BASE
cd ~/Programs/openboard
OPENBOARD_BASE=. usr/bin/openboard

Note that this requires a debug build, as the OPENBOARD_BASE environment variable is not evaluated for release builds.

Package

For an installable package, you should typically choose a Release or RelWithDebInfo build type. You can then use

cpack -G DEB
  or
cpack -G RPM

This will create a .deb or .rpm package which can then be installed on your machine.

Using QtCreator with cmake builds

You can easily use QtCreator to build and test OpenBoard with a few configuration steps. The following short instructions assume that you have already configured the basic things of QtCreator and defined a suitable kit. You have also cloned the OpenBoard repository and checked out the desired branch. Then proceed as follows:

  • Choose "Open Project" and select the CMakeLists.txt file from OpenBoard.
  • Configure the desired kits and build types. It is recommended to select a debug build type.
  • Select "Project" mode from the left sidebar.
  • In the CMake configuration, change CMAKE_INSTALL_PREFIX from /usr/local to /usr.
  • Open the build step details and select the install target.
  • Set the QT_VERSION if necessary.
  • Scroll down to the build environment, open the details and add a variable DESTDIR with the value install.
  • Then switch to the Run configuration
  • Scroll down to Run Environment, open details and add a variable OPENBOARD_BASE with value install.

Then just click on the "Build", "Debug" or "Run" button.

This setup will not only compile and run OpenBoard, but also set up translations and web applications by creating a local installation in the install folder and running OpenBoard pointing to that folder.