From: Vladislav Shchapov Date: Thu, 26 May 2022 18:39:04 +0000 (+0500) Subject: Allow external gtest X-Git-Tag: 2.1.0-beta1~235 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=19c649838ae7ae82b2cf4d81c9471c8deaac80ff;p=thirdparty%2Fzlib-ng.git Allow external gtest Signed-off-by: Vladislav Shchapov --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8b250ed7..fc06ce7b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,35 +18,38 @@ if(WITH_SANITIZER STREQUAL "Memory") add_compile_options(-stdlib=libc++ -g) endif() -# Prevent overriding the parent project's compiler/linker settings for Windows -set(gtest_force_shared_crt ON CACHE BOOL - "Use shared (DLL) run-time lib even when Google Test is built as static lib." FORCE) -# Disable pthreads for simplicity -set(gtest_disable_pthreads ON CACHE BOOL - "Disable uses of pthreads in gtest." FORCE) - -# Allow specifying alternative Google test repository -if(NOT DEFINED GTEST_REPOSITORY) - set(GTEST_REPOSITORY https://github.com/google/googletest.git) -endif() -if(NOT DEFINED GTEST_TAG) - # Use older version of Google test to support older versions of GCC - if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 5.3) - set(GTEST_TAG release-1.10.0) - else() - set(GTEST_TAG release-1.11.0) +if(NOT TARGET GTest::GTest) + # Prevent overriding the parent project's compiler/linker settings for Windows + set(gtest_force_shared_crt ON CACHE BOOL + "Use shared (DLL) run-time lib even when Google Test is built as static lib." FORCE) + # Disable pthreads for simplicity + set(gtest_disable_pthreads ON CACHE BOOL + "Disable uses of pthreads in gtest." FORCE) + + # Allow specifying alternative Google test repository + if(NOT DEFINED GTEST_REPOSITORY) + set(GTEST_REPOSITORY https://github.com/google/googletest.git) + endif() + if(NOT DEFINED GTEST_TAG) + # Use older version of Google test to support older versions of GCC + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 5.3) + set(GTEST_TAG release-1.10.0) + else() + set(GTEST_TAG release-1.11.0) + endif() endif() -endif() -# Fetch Google test source code from official repository -FetchContent_Declare(googletest - GIT_REPOSITORY ${GTEST_REPOSITORY} - GIT_TAG ${GTEST_TAG}) + # Fetch Google test source code from official repository + FetchContent_Declare(googletest + GIT_REPOSITORY ${GTEST_REPOSITORY} + GIT_TAG ${GTEST_TAG}) -FetchContent_GetProperties(googletest) -if(NOT googletest_POPULATED) - FetchContent_Populate(googletest) - add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) + FetchContent_GetProperties(googletest) + if(NOT googletest_POPULATED) + FetchContent_Populate(googletest) + add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() + add_library(GTest::GTest ALIAS gtest) endif() set(TEST_SRCS @@ -95,7 +98,7 @@ if(WITH_SANITIZER STREQUAL "Memory") -fsanitize-memory-track-origins) endif() -target_link_libraries(gtest_zlib zlibstatic gtest) +target_link_libraries(gtest_zlib zlibstatic GTest::GTest) if(ZLIB_ENABLE_TESTS) add_test(NAME gtest_zlib