How to do it

In this recipe, we will only focus on how to fetch the Google Test sources to build the gtest_main target. For a discussion on how this target is used to test the example sources, we refer the reader to Chapter 4, Creating and Running Tests, Recipe 3, Defining a unit test and linking against Google Test:

  1. We first include the FetchContent module, which will provide the functions that we will require to declare, query, and populate the dependency:
include(FetchContent)
  1. Then, we declare the content - its name, repository location, and the precise version to fetch:
FetchContent_Declare(  googletest  GIT_REPOSITORY https://github.com/google/googletest.git  GIT_TAG release-1.8.0)
  1. We then query whether the content has already been ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.