Skip to content

Commit

Permalink
[cmake] fetch googletest
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Aug 16, 2024
1 parent fe88bd2 commit a110ab1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
6 changes: 0 additions & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
23 changes: 16 additions & 7 deletions test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

0 comments on commit a110ab1

Please sign in to comment.