For context, I am using Visual Studio 2022 with:
- Test Adapter for Google Test installed from the VS installer
- a newly created CMake project from the corresponding project template
CMakeLists.txt
:
cmake_minimum_required(VERSION 3.14)
project(my_project)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(
hello_test
hello_test.cpp
)
target_link_libraries(
hello_test
gtest_main
)
include(GoogleTest)
gtest_discover_tests(hello_test)
hello_test.cpp
:
#include <gtest/gtest.h>
~~~~~~~~~~~~~~~ (errors out here)
I copied CMakeLists.txt
straight from the primer page with some changes:
hello_test.cc
->hello_test.cpp
GTest::gtest_main
->gtest_main
While the CMake cache generates, I still can’t include <gtest/gtest.h>
in hello_test.cpp
. It likely isn’t intellisense screwing me over since the program just straight up doesn’t want to build. I’m happy to share more error information if requested.
What should I do to get GTest to work on my project?