Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vegertar/233aee7d550539f5ee49b3507e5b3441 to your computer and use it in GitHub Desktop.
Save vegertar/233aee7d550539f5ee49b3507e5b3441 to your computer and use it in GitHub Desktop.

Ordinarily, the minimal gtest working with cmake can be given by

cmake_minimum_required(VERSION 3.20)
project(gtest_with_cmake)

set(CMAKE_CXX_STANDARD 14)
include(GoogleTest)

enable_testing()
add_executable(example example.cpp)
target_link_libraries(example PRIVATE gtest pthread gtest_main)
gtest_discover_tests(example)

But on some platform, e.g. DragonflyBSD v6.2.2, the variable GTEST_INCLUDE_DIRS defined in GoogleTest.cmake module is empty, the same issue might be also found in Mac Catalina (10.15) in which @emmenlau mentioned a namespace syntax to avoid this old-fasioned problem.

The modified CMakeLists.txt is:

cmake_minimum_required(VERSION 3.20)
project(gtest_with_cmake)

set(CMAKE_CXX_STANDARD 14)

find_package(GTest REQUIRED)
enable_testing()
add_executable(example example.cpp)
target_link_libraries(example GTest::gtest GTest::gtest_main)
gtest_discover_tests(example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment