Introduce googletest library

The library will be either found in the system or downloaded via FetchContent.
This commit is contained in:
Bartosz Podrygajlo
2024-05-20 13:30:49 +02:00
parent 9fab212441
commit 9c913fa040
2 changed files with 18 additions and 2 deletions

View File

@@ -2507,6 +2507,21 @@ if(ENABLE_TESTS)
# meta-target: each test is supposed to add_dependencies(tests ${NEWTEST})
# then, it is possible to build and execute all tests using "ninja tests && ctest"
add_custom_target(tests)
find_package(GTest)
if (NOT GTest_FOUND)
message(STATUS "GTest package not found, will download googletest automatically. To prevent that install google test on your system (libgtest-dev)")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # 1.12.1
)
set(BUILD_GMOCK OFF)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()
endif()
add_subdirectory(common)

View File

@@ -8,8 +8,9 @@ explaining how to test with cmake and ctest; it is a suggested read, and the
following just lists the main points of how to compile the tests and how to add
new ones.
At the time of writing, only the NR RLC tests have been integrated. The author
hopes that more tests follow suit.
GoogleTest is a C++ unit testing framework that has been added as an external dependency. While using GoogleTest is not a requirement it can simplify writing unit tests.
See [primer](http://google.github.io/googletest/primer.html) for a quick introduction. To add it to your test executable link against
`GTest::gtest` or `GTest::gtest_main`.
# How to compile tests