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)