GoogleTest
Pieter PThis page explains how to install the Google Test framework on Ubuntu.
Install dependencies and tools
First, install GCC, CMake, GNU Make and Git if you haven't already.
sudo apt updatesudo apt install gcc g++ cmake make git
Download, build and install
#!/usr/bin/env bash# Script to download and install GoogleTestset -exversion="release-1.10.0" # Release tag on GitHubprefix="$HOME/.local"cd /tmp# Downloadgit clone --single-branch --depth=1 --branch "$version" \https://github.com/google/googletest.gitmkdir googletest/build && cd $_# Configurecmake .. -DCMAKE_INSTALL_PREFIX="$prefix" -DCMAKE_BUILD_TYPE=Release# Buildmake -j$(nproc)# Installmake install
Usage
To use GoogleTest in your project, you can use the following CMake snippet:
enable_testing()find_package(GTest REQUIRED)include(GoogleTest)add_executable(test-exe test.cpp) # test.cpp contains TEST(...) casestarget_link_libraries(test-exe PRIVATE GTest::gtest_main)if(NOT CMAKE_CROSSCOMPILING)gtest_discover_tests(test-exe)endif()
CMake has to find GoogleTest, so you need to make sure that $HOME/.local
is in its search paths. See Installing Locally.
Tested on
- Ubuntu 19.10 - GoogleTest 1.10.0