gpt4 book ai didi

cmake - CTest 未检测到测试

转载 作者:行者123 更新时间:2023-12-03 21:20:52 25 4
gpt4 key购买 nike

我有一个结构的项目

├── CMakeLists.txt
├── mzl.c
├── mzl.h
└── tests
├── CMakeLists.txt
├── mzl-communication-test.c
├── mzl-setup-test.c
├── mzl-test-errors.c
└── mzl-test-errors.h

所在目录 CMakeLists.txt文件是
project(mzl)
cmake_minimum_required(VERSION 2.8)

add_subdirectory(tests)

# Enable testing for the project
enable_testing()

# Find zmq
find_library(ZMQ_LIB zmq REQUIRED)
message(STATUS "ZMQ Library: ${ZMQ_LIB}")

# Find threading library
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)
message(STATUS "Threading Library: ${CMAKE_THREAD_LIBS_INIT}")



# Set include directories for headers
set (
MZL_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}
CACHE STRING "MZL Include Directories"
)
include_directories(${MZL_INCLUDE_DIRS})

# Set source files
set (
MZL_SRC_FILES
mzl.c
)

# Add library
add_library(${PROJECT_NAME} STATIC ${MZL_SRC_FILES})

# Link to zmq
target_link_libraries(${PROJECT_NAME} ${ZMQ_LIB} ${CMAKE_THREAD_LIBS_INIT})

tests/CMakeLists.txt
# Use MZL Source Directories (mzl headers are in top directory)
include_directories(${CMAKE_SOURCE_DIR})

# Variable from here is empty
message(STATUS "MZL Include Directories: ${MZL_INCLUDE_DIRS}")

# Files common to all tests
set ( TEST_COMMON_SOURCES
mzl-test-errors.c
)

# Library setup/shutdown testing
set(SETUP_TEST_NAME mzl-setup-test)
add_executable(${SETUP_TEST_NAME} ${TEST_COMMON_SOURCES} ${SETUP_TEST_NAME}.c)
target_link_libraries(${SETUP_TEST_NAME} ${PROJECT_NAME} ${ZMQ_LIB})
add_test(${SETUP_TEST_NAME} ${SETUP_TEST_NAME})

# Communcations test
set(COMMUNICATION_TEST_NAME mzl-communication-test)
add_executable(${COMMUNICATION_TEST_NAME} ${TEST_COMMON_SOURCES}
${COMMUNICATION_TEST_NAME}.c)
target_link_libraries(${COMMUNICATION_TEST_NAME} ${PROJECT_NAME}
${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIB})
add_test(${COMMUNICATION_TEST_NAME} ${COMMUNICATION_TEST_NAME})

在我添加第二个测试之前一切正常 mzl-communication-test .添加它和 tests/CMakeLists.txt 中的行后后 # Communications test , 正在运行 ctest没有做任何额外的事情——它仍然只运行了第一次测试。

删除构建目录并运行后 cmake再次,初始 CMake 运行没有错误,但运行 make再次运行 CMake,导致 CMake 出错:
CMake Error: Parse error in cache file build/CMakeCache.txt. Offending entry: include

接着是一个 Make 错误:
Makefile:203: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1

运行 make再次导致所有内容都被构建,包括测试;但是,正在运行 ctest结果是
Test project build
No tests were found!!!

问题似乎与我正在用 CMake 做的事情有关,但无法从这里弄清楚该怎么做,因为我看不到我所做的与最初工作时不同的任何事情。甚至我对 git 的最后一次提交(在我提交时正在工作)也不再起作用。

最佳答案

您需要移动enable_testing()做之前先打电话add_subdirectory(tests)

# Enable testing for the project
enable_testing()

add_subdirectory(tests)

关于cmake - CTest 未检测到测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30250494/

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