【发布时间】:2019-11-12 23:45:48
【问题描述】:
我们(三个学生)对 CMake 非常陌生。对于一个大学项目,我们必须将 GoogleTest 包含到我们的代码库中,但我们遇到了很多麻烦。
我们有一个gtest_ours.cmake 文件:
project("googletests")
enable_testing()
include(GoogleTest)
file(GLOB_RECURSE MY_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
# header don't need to be included but this might be necessary for some IDEs
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
EXCLUDE
"${CMAKE_CURRENT_SOURCE_DIR}/src/MolSim.cpp"
)
add_subdirectory(googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(ParticleContainerTest ${sources} ${CMAKE_CURRENT_SOURCE_DIR}/test/ParticleContainerTest.cpp )
target_link_libraries(ParticleContainerTest ${MY_SRC} gtest gtest_main gmock gmock_main)
gtest_discover_tests(ParticleContainerTest)
set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10)
set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20)
从CMakeLists.txt 文件中,我们只需调用:
include(gtest_ours)
我们的文件夹结构是:
main
- src
- test
- CMakeLists.txt
- others
请帮忙,我们收到以下错误:
/home/lunaticcoding/psemoldyn_groupc/MolSim-master/test/ParticleContainerTest.cpp:9:10: fatal error: ../src/ParticleContainer.h: No such file or directory
#include "../src/ParticleContainer.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/ParticleContainerTest.dir/build.make:62: recipe for target 'CMakeFiles/ParticleContainerTest.dir/test/ParticleContainerTest.cpp.o' failed
make[2]: *** [CMakeFiles/ParticleContainerTest.dir/test/ParticleContainerTest.cpp.o] Error 1
CMakeFiles/Makefile2:144: recipe for target 'CMakeFiles/ParticleContainerTest.dir/all' failed
make[1]: *** [CMakeFiles/ParticleContainerTest.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
【问题讨论】:
-
如果您将
"."添加到include_directories,它应该可以工作。
标签: c++ unit-testing cmake googletest