cmake: support gtest from the package manager (#552)

Some developers would be happier with the gtest version provided from
their package manager. Use it if it is installed the package provide
cmake support.

Fixed: https://github.com/ArthurSonzogni/FTXUI/issues/551
This commit is contained in:
Arthur Sonzogni
2023-01-14 20:37:42 +01:00
committed by GitHub
parent 1561293140
commit 65848d1e5f
12 changed files with 161 additions and 111 deletions

View File

@@ -1,28 +1,13 @@
enable_testing()
option(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
option(FETCHCONTENT_QUIET FALSE)
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY "https://github.com/google/googletest"
GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907
GIT_PROGRESS TRUE
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
set(BUILD_GMOCK OFF CACHE INTERNAL "")
set(INSTALL_GTEST OFF CACHE INTERNAL "")
set(gtest_force_shared_crt ON CACHE INTERNAL "")
add_subdirectory(
${googletest_SOURCE_DIR}
${googletest_BINARY_DIR}
EXCLUDE_FROM_ALL
)
if (NOT FTXUI_BUILD_TESTS OR
NOT ${CMAKE_VERSION} VERSION_GREATER "3.11.4")
return()
endif()
add_executable(tests
enable_testing()
include(cmake/ftxui_find_google_test.cmake)
add_executable(ftxui-tests
src/ftxui/component/animation_test.cpp
src/ftxui/component/button_test.cpp
src/ftxui/component/collapsible_test.cpp
@@ -63,25 +48,18 @@ add_executable(tests
src/ftxui/screen/string_test.cpp
)
target_link_libraries(tests
target_link_libraries(ftxui-tests
PRIVATE component
PRIVATE gtest
PRIVATE gtest_main
PRIVATE GTest::gtest
PRIVATE GTest::gtest_main
)
target_include_directories(tests
target_include_directories(ftxui-tests
PRIVATE src
)
ftxui_set_options(tests)
target_compile_features(tests PUBLIC cxx_std_20)
ftxui_set_options(ftxui-tests)
target_compile_features(ftxui-tests PUBLIC cxx_std_20)
include(GoogleTest)
gtest_discover_tests(tests
gtest_discover_tests(ftxui-tests
DISCOVERY_TIMEOUT 600
)
include(cmake/ftxui_benchmark.cmake)
if (FTXUI_BUILD_TESTS_FUZZER)
include(cmake/ftxui_fuzzer.cmake)
endif()