GTest首先在CMake建立

时间:2016-10-20 10:31:14

标签: c++ cmake googletest

我正在构建动态库,并希望使用gtest进行测试。

SET(GTEST_LIBRARY libs/googletest-master)
set(GTEST_INCLUDE_DIR libs/googletest-master/googletest/include)
#set(GTEST_MAIN_LIBRARY libs/googletest-master/googletest/include/gtest)

#find_package(PostgreSQL REQUIRED)

enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})

但是,berofe设置GTEST_MAIN_LIBRARY我必须首先构建它。 我如何配置CMake来实现这个目标

  1. 使用Cmake&&amp ;;构建gtest make(在unix上)
  2. 获取GTEST_MAIN_LIBRARY
  3. 的相应路径
  4. 继续构建

2 个答案:

答案 0 :(得分:0)

I copied gtests srcs into project make a build with Make and add this to CMake

add_subdirectory(libs/googletest-master)

SET(GTEST_LIBRARY libs/googletest-master)
set(GTEST_INCLUDE_DIR libs/googletest-master/googletest/include)
set(GTEST_MAIN_LIBRARY libs/googletest-master/googlemock/gtest)

enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

答案 1 :(得分:-2)

如果您将googletest的源代码放在CMakeLists.txt文件所在的子目录中,则以下内容应该有效:

add_subdirectory(./googletest)

add_executable(your_program ${MY_SRC})

add_dependencies(your_program gmock)
add_dependencies(your_program gtest)