作为构建的一部分,将执行以下代码行:
cmake_minimum_required(VERSION 3.12)
file(DOWNLOAD <my-url> ${CMAKE_CURRENT_BINARY_DIR}/<filename>)在某个时刻,服务器开始运行,现在(经过很长一段时间的延迟)它返回Internal Server Error (code 500)。但由于某些原因,CMake只是继续运行,就像什么都没发生一样,后来失败了(因为相关文件从未下载过)。如果下载失败,如何强制停止CMake?
操作系统: CentOS 7
CMake版本: 3.14.3
发布于 2020-04-17 01:14:08
您可以通过提供STATUS参数来检索file(DOWNLOAD ...)操作的状态:
file(DOWNLOAD <my-url> ${CMAKE_CURRENT_BINARY_DIR}/<filename>
STATUS DOWNLOAD_STATUS
)
# Separate the returned status code, and error message.
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE)
# Check if download was successful.
if(${STATUS_CODE} EQUAL 0)
message(STATUS "Download completed successfully!")
else()
# Exit CMake if the download failed, printing the error message.
message(FATAL_ERROR "Error occurred during download: ${ERROR_MESSAGE}")
endif()如果成功,则返回状态为0。否则,将提供不同的返回代码和错误消息。
https://stackoverflow.com/questions/61255773
复制相似问题