I've been trying to set up google test v1.10 in visual studio 2019 for a really long time now and it hasn't been working, and a lot has changed as well. Most of the tutorials are out of data and Microsoft help page says to use the google test adapter but I have an already existing project that I want to add google test. I've referred to the google test installation page(https://github.com/google/googletest/blob/master/googletest/README.md) and tried to set it up using the cmake method but it isn't working and the cmake method is a bit complicated. I was wondering if anyone could help with the steps for a dummy like me? I feel like this will also help people who are trying to set it up currently and are stuck as well.
This is what i did for the cmake thingy:
created an empty project in vs, and added a source.cpp file and a Header.h file(for the example).
I created a CMakeLists.txt and a CMakeLists.txt.in file and copy pasted this in for the first one(tweaked a bit for my project)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
# Now simply link against gtest or gtest_main as needed. Eg
add_executable(test_ source.cpp)
target_link_libraries(test_ gtest_main)
add_test(NAME example_test COMMAND test)
and CMakeLists.txt.in
cmake_minimum_required(VERSION 2.8.2)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
- I created a build folder in my project file
- I used the cmake command from the terminal to build it into the build folder like this
cmake -S "path to src code" -B "path to build"
and these are the warnings I got:
No project() command is present. The top level CMakeLists.txt file must contain a literal, direct call to the project() command. And a line of code such as
project(projectName)
near the top of the CMake file, but after cmake_minimum_required().
CMake is pretending there is a "project(projectName)" command on the first line.
This warning is for project developers. Use who-dev to supress it.
other than that it did the building
and this is my project tree currently
and this is what's there in /build
but idk what to do after this? How do I start creating tests? If possible i want to create another project inside my current solution so i can run tests separately
here's what is mean
the googletest project is where i want to run my tests if possible
and this what my project tree looks like after