我正在构建动态库,并希望使用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来实现这个目标
答案 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)