我的CMake项目遇到了麻烦。
这就是我想做的:
所以我的文件夹结构如下:
实用程序
| --CMakeLists.txt
|-包括
|- .hpp
|-来源
|- .cpp
|-测试
| --CMakeLists.txt
|-源
| --test_main.cpp
|-* _ test.cpp
问题在这里,我从源代码实现了库,并在Test文件夹CMakeLists.txt中包含了文件夹,但是当我尝试访问测试中的标头时,错误消息“ .hpp:目录中没有这样的文件” “
我在多个站点中搜索了答案,但没有任何帮助。感谢您的提前帮助:)
这是我的Source和Include文件夹的CMakeLists.txt:
### Respnsible for providing custom festures for the engine ###
project(Utilities)
### Include all CPP-Files from the source directory to the library ###
file(GLOB LIB source/*.cpp)
### Create a new libraray based on the cpp-files from the source directory ###
add_library(Utilities STATIC ${LIB})
### Create a include directory property, where the header files are public available for ###
### the including project, but the source files stay in the background, only serving as logic definition ###
target_include_directories(Utilities
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/source
)
这是我在测试区域的CMakeLists.txt:
project(Utilities_UTest)
### Include all C++ related files from the source directory ###
file(GLOB TEST source/*.cpp source/*.hpp)
include_directories(include)
### Set executable files for this unit-test project ###
add_executable(${PROJECT_NAME} "${TEST}")
target_link_libraries(${PROJECT_NAME} PRIVATE catch libUtilities.so)
这是cpp文件的顶部,在这里我尝试使用catch2框架测试库中的内容:
#include "catch.hpp"
#include "Array.hpp"
SCENARIO("Arrays can be created empty.")
{
...
仅作为附加信息: 我在Ubuntu 18.04上使用带有 GCC for x86_64-linux-gnu 7.3.0 套件的Visual Studio Code