From a110ab10cccc0acc075691900945c3cc93a3e587 Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Fri, 16 Aug 2024 10:13:07 +0800 Subject: [PATCH] [cmake] fetch googletest --- test/CMakeLists.txt | 6 ------ test/unittest/CMakeLists.txt | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 016d3fe6..7ed9edfa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,11 +1,5 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) -SET(GTEST_ROOT_DIR googletest/googletest) -INCLUDE_DIRECTORIES(${GTEST_ROOT_DIR} ${GTEST_ROOT_DIR}/include) -ADD_DEFINITIONS(-DGTEST_USE_OWN_TR1_TUPLE=1) -ADD_LIBRARY(gtest STATIC ${GTEST_ROOT_DIR}/src/gtest-all.cc) -TARGET_LINK_LIBRARIES(gtest pthread) - ADD_EXECUTABLE(demo demo.cpp) if(NOT MSVC) ADD_EXECUTABLE(load_test load_test.cpp) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 9745e7cd..4a375c1d 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -1,8 +1,21 @@ +if (MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL") + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +endif() + +include(FetchContent) + +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.11.0 +) +FetchContent_MakeAvailable(googletest) + + SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/deps/gtest/include) - ADD_DEFINITIONS(-DLOGGING_LEVEL=LL_WARNING) ADD_EXECUTABLE(test.run @@ -17,8 +30,4 @@ ADD_EXECUTABLE(test.run textrank_test.cpp ) -if(MSVC) - TARGET_LINK_LIBRARIES(test.run gtest) -else() - TARGET_LINK_LIBRARIES(test.run gtest pthread) -endif() +TARGET_LINK_LIBRARIES(test.run gtest)