CMake GoogleTests在我的测试文件中找不到导入的头文件
CMake GoogleTests can't find header file imported in my test file
我们(三个学生(是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
gtest_ours.cmake
文件存在几个问题。由于您尚未将ParticleContainerTest
目标的包含目录定义为包含ParticleContainer.h
,因此引发了错误。您只添加了gtest_SOURCE_DIR
目录作为包含目录。要更正此问题,请考虑在add_executable()
:之后添加此行
target_include_directories(ParticleContainerTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
这样,src
目录将是一个include目录,因此您可以修改test/ParticleContainerTest.cpp
以获得更合理的#include
:
#include "ParticleContainer.h"
此外,我不确定您打算在哪里使用${MY_SRC}
源文件,但您不希望在target_link_libraries()
调用中包含此文件。此调用应仅包括预定义的目标、库名称或链接选项作为参数;不要将源文件列表添加到此调用。我也不确定您在add_executable()
调用中在哪里定义了${sources}
参数,但也许您想把${MY_SRC}
放在那里。
最后,EXCLUDE
限定符不适用于file(GLOB_RECURSE ...)
签名。但是,您可以在之后使用list(REMOVE_ITEM ...)
:从列表中删除特定的文件
file(GLOB_RECURSE MY_SRC CONFIGURE_DEPENDS
"${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"
)
list(REMOVE_ITEM MY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/MolSim.cpp)
相关文章:
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 找不到QtResource文件中的文件
- "assimp/config.h"找不到,但它在文件夹中
- C++系统找不到指定的文件错误
- 在 Ubuntu 18.04 上,我编译的 cpp 可执行文件找不到 VTK7 依赖项
- Pyinstaller创建的可执行文件找不到Meipass目录中存在的DLL
- 如何修复"QtCharts"库文件找不到/无法包含<QtCharts>?
- 为什么生成文件找不到包含目录
- 我的类在 .h 文件中定义,.cpp文件找不到
- 生成文件找不到 .o 文件
- 部署Qt-dll文件-找不到windows插件,尽管平台/qwindows.dll存在,因此存在libEGL和libGL
- 资源中的文件找不到本地文件
- C++包括 C 文件(找不到 typedef)
- C++生成文件找不到文件
- Xcode 6.0.1版gmp.h头文件找不到,尽管gmp.h和gmpxx.h在local/include中
- 生成文件找不到同一目录中的文件
- 我的生成文件找不到我的头目录
- 包含的文件 <> 找不到 " " 中包含的文件
- 突然间,Ogre头文件找不到(DEVELOPER_DIR随着Xcode更新而改变)
- 尝试在Xcode 5中包含头文件.找不到文件