Table of Contents
In this article, I will take you through the steps to install catch2 on Ubuntu 20.04 LTS (Focal Fossa). Catch2 is a free and open source unit testing framework for C++, but it also provides basic micro-benchmarking features, and simple BDD macros. Its main advantage is that it is both simple and natural to use. Other advantage is that the Tests can auto register themselves and do not have to be named with valid identifiers. Its assertions look like normal C++ code, and sections provide a nice way to share set-up and tear-down code in tests. It can be easily installed on any Linux based systems. Here we will see the steps to install on Ubuntu 20.04 LTS system.
How to Install Catch2 on Ubuntu 20.04 LTS (Focal Fossa)
Also Read: How to Install SimulIDE on Ubuntu 20.04 LTS (Focal Fossa)
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04 LTS
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
and cmake
utility available in your System.
Step 2: Update Your Server
First you need to update the system cache with all the latest available updates from Ubuntu repo by using sudo apt update
command as shown below.
cyberithub@ubuntu:~$ sudo apt update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [712 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,072 kB]
Fetched 3,120 kB in 3s (953 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Step 3: Clone the Repo
Next step is to clone the Catch2
repo from GitHub using below git clone
command. This will create a local directory called Catch2
and download all the repo contents in it.
cyberithub@ubuntu:~$ git clone https://github.com/catchorg/Catch2.git
Cloning into 'Catch2'...
remote: Enumerating objects: 35286, done.
remote: Counting objects: 100% (514/514), done.
remote: Compressing objects: 100% (304/304), done.
remote: Total 35286 (delta 262), reused 414 (delta 210), pack-reused 34772
Receiving objects: 100% (35286/35286), 25.62 MiB | 5.02 MiB/s, done.
Resolving deltas: 100% (24827/24827), done.
Step 4: Build Files
Next you need to configure and build all the files by switching to directory Catch2
and then by running cmake -Bbuild -H. -DBUILD_TESTING=OFF
command as shown below. This will build all the files and write to Catch2/build
under local user home directory.
cyberithub@ubuntu:~$ cd Catch2/ cyberithub@ubuntu:~/Catch2$ cmake -Bbuild -H. -DBUILD_TESTING=OFF -- The CXX compiler identification is GNU 9.4.0 -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/cyberithub/Catch2/build
Step 5: Install Catch2
Once the build is successful, you need to install catch2 testing framework by using sudo cmake --build build/ --target install
command as shown below. This will install the framework globally.
cyberithub@ubuntu:~/Catch2$ sudo cmake --build build/ --target install
Scanning dependencies of target Catch2
[ 0%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_automake.cpp.o
[ 1%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_common_base.cpp.o
[ 2%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_compact.cpp.o
[ 3%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_console.cpp.o
[ 4%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_cumulative_base.cpp.o
[ 5%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_event_listener.cpp.o
[ 6%] Building CXX object src/CMakeFiles/Catch2.dir/catch2/reporters/catch_reporter_helpers.cpp.o
..............................................................
Scanning dependencies of target Catch2WithMain
[ 99%] Building CXX object src/CMakeFiles/Catch2WithMain.dir/catch2/internal/catch_main.cpp.o
[100%] Linking CXX static library libCatch2Main.a
[100%] Built target Catch2WithMain
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/cmake/Catch2/Catch2Config.cmake
-- Installing: /usr/local/lib/cmake/Catch2/Catch2ConfigVersion.cmake
-- Installing: /usr/local/share/doc/Catch2
-- Installing: /usr/local/share/doc/Catch2/assertions.md
-- Installing: /usr/local/share/doc/Catch2/test-cases-and-sections.md
-- Installing: /usr/local/share/doc/Catch2/why-catch.md
...........................................................