gpt4 book ai didi

c++ - 如何从其他目录树将源文件包含到 Bool.Test 用例中?

转载 作者:行者123 更新时间:2023-11-28 08:10:12 26 4
gpt4 key购买 nike

这在某种程度上是我上一个问题的后续问题:How to achieve organisation of test suites and cases with Boost?

目录结构如另一个问题中所述,我也遵循其中描述的 Boost.Test 用例组织。

但是,我正在努力让一切都与 CMake 一起工作。

我的 tests/CMakeLists.txt如下:

# tests/CMakeLists.txt
# Add the test sources
set(test_SOURCES ${PROJECT_SOURCE_DIR}/tests/TestRunner.cpp)

# Add test cases
add_subdirectory(model)

# Include Boost and program's sources (find_package has been executed before)
include_directories(${Boost_INCLUDE_DIR})

# Create the tests
add_executable(MyProgramTests ${test_SOURCES})

# Link agains Boost libraries
target_link_libraries(MyProgramTests ${Boost_LIBRARIES})

tests/model/CMakeLists.txt说:

# tests/model/CMakeLists.txt
include(${PROJECT_SOURCE_DIR}/src/model/CMakeLists.txt)

# Add test cases to the list
set(test_SOURCES
${test_SOURCES}
${model_SOURCES}
${PROJECT_SOURCE_DIR}/tests/model/model_a_test.cpp
PARENT_SCOPE
)

src/model/CMakeLists.txt我刚刚写了:

set(model_SOURCES ${PROJECT_SOURCE_DIR}/src/model/model_a.cpp)

我如何必须包含 src/model/model_a.cpp在我的 tests/model/model_a_test.cpp所以编译终于找到了吗?我试过 #include "src/model/model_a.cpp" , #include "model/model_a.cpp"甚至只是#include "model_a.cpp" .在所有情况下 model_a.cpp找不到。

我很确定,我在 CMakeLists 文件中遗漏了一些东西。但是什么?

编辑

我终于通过添加程序源目录解决了${PROJECT_SOURCE_DIR}/src/modelinclude_directories命令 tests/CMakeLists.txt .有了这个,#include "model_a.cpp"应该使用。

最佳答案

看起来您缺少 PARENT_SCOPE 以便将 ${model_SOURCES} 的值从 src/model/CMakeLists.txttests/model/CMakeLists.txt

尝试使用

set(model_SOURCES ${PROJECT_SOURCE_DIR}/src/model/model_a.cpp PARENT_SCOPE)

关于c++ - 如何从其他目录树将源文件包含到 Bool.Test 用例中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9344487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com