gtest集成到项目的cmake配置

关键在于

set(GTEST_ROOT "/path/to/gtest" CACHE PATH "Path to googletest")
find_package(GTest REQUIRED)

半完整举例

IF (WIN32)
set (GTEST_ROOT ${PROJECT_SOURCE_DIR}/libgtest_win_mingw_release)
ELSEIF (UNIX)
#ubuntu
set (GTEST_ROOT ${PROJECT_SOURCE_DIR}/libgtest_ubuntu2004_release)
#manjaro
#set (GTEST_ROOT ${PROJECT_SOURCE_DIR}/libgtest_manjaro_release)
ENDIF ()

find_package(GTest REQUIRED)
message(STATUS "GTEST_INCLUDE_DIR: ${GTEST_INCLUDE_DIR}")
include_directories(${GTEST_INCLUDE_DIR})

项目最后加上

target_link_libraries(${PROJECT_NAME} ${GTEST_BOTH_LIBRARIES})

上一篇:gmock试用


下一篇:gtest and lcov