我正在尝试为我的一个基于cmake的项目使用gtest。
这是他们在github上提供的cmake,用于在配置时构建gtest (删除注释以使其更简短):
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
add_executable(example example.cpp)
target_link_libraries(example gtest_main)
add_test(NAME example_test COMMAND example)现在,当在一个非常简单的项目中使用它时:
.
├── CMakeLists.txt
├── CMakeLists.txt.in
├── build
└── gtest_example.cpp它的工作方式与预期一致。但是,当使用自己的CMakeLists.txt和CMakeLists.txt.in以及第一个CMakeLists.txt中的add_subdirectory(test)添加测试目录时,它就不再起作用了。
由于输入了if(result),execute_process()似乎失败了。
我做错了什么?
发布于 2018-08-24 03:26:09
我在github上发现了这个问题,解决了我的问题。详情请参见file changes。
如果有人有同样的问题,我会接受这个答案。
https://stackoverflow.com/questions/51992128
复制相似问题