如何知道cmake项目的产生是否成功结束 [英] How to know whether the cmake project generation ended with success

查看:287
本文介绍了如何知道cmake项目的产生是否成功结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几周我在进行构建自动化。在Cmake的帮助下,我能够生成Windows的Visual Studio解决方案和MinGW生成文件,以及Linux的GCC生成文件。 Cmake任务分别通过Windows上的批处理文件和Linux上的Shell脚本执行。一切看起来都正确并且可以按预期工作。我的计划是设置不同的测试服务器,其中整个构建和测试过程将被自动化,并且结果将报告在某个地方。

The last few weeks I'm playing with build automation. With the help of Cmake, I'm able to generate Visual Studio solution and MinGW makefile for Windows and also GCC makefile for Linux. The Cmake task is executed through a batch file on Windows respectively through a shell script on Linux. Everything looks correct and works as expected. My plan is to setup different test servers where the whole build and test process will be automated and the results will be reported somewhere.

我无法弄清的一件事仍然是如何获取cmake命令的结果。我想知道cmake命令是否成功结束,因此如果发生错误,将报告失败。现在,我可以解析结果并查找已将构建文件写入...这句话,但我认为这并不是真正可靠的解决方案。

One thing I was not able to figure out yet is how to obtain the result of the cmake command. I would like to know whether the cmake command ended successfully or not, so in case of error the fail will be reported. At this moment I'm able to parse the result and look for "Build files have been written to: ..." sentence, but I think it is not really robust solution.

有没有一种方法可以确定cmake命令是否成功?我不想一定要坚持批处理文件,也欢迎使用Python(或其他)脚本。谢谢。

Is there a way to determine whether the cmake command was successful or not? I don't want to stick necessarily to batch files, Python (or other) scripts are also welcome. Thanks.

推荐答案

只需确保您的脚本确实退出,并且调用的程序报告了错误级别。

Just make sure your scripts do exit with the error levels reported by the programs you're calling.

让我通过显示一个示例来对此进行解释:

Let me explain this with showing an example:

vs2015_x86_build.cmd

@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: usage:
::          vs2015_x86_build.cmd <target> <config>
::                  <target> - target to be built (default: ALL_BUILD)
::                  <config> - configuration to be used for build (default: Debug)

if NOT "%1" == "" (SET CMAKE_TARGET=%1) else (SET CMAKE_TARGET=ALL_BUILD)
if NOT "%2" == "" (set CMAKE_BUILD_TYPE=%2) else (set CMAKE_BUILD_TYPE=Debug)
SET CMAKE_BINARY_DIR=vs2015_x86

IF NOT EXIST "%CMAKE_BINARY_DIR%\*.sln" (
    cmake -H"." -B"%CMAKE_BINARY_DIR%" -G"Visual Studio 14 2015"
    SET GENERATE_ERRORLEVEL=!ERRORLEVEL!
    IF NOT "!GENERATE_ERRORLEVEL!"=="0" (
        DEL /F /Q "%CMAKE_BINARY_DIR%\*.sln"
        EXIT /B !GENERATE_ERRORLEVEL!
    )
)
cmake --build "%CMAKE_BINARY_DIR%" --target "%CMAKE_TARGET%" --config "%CMAKE_BUILD_TYPE%"
SET BUILD_ERRORLEVEL=!ERRORLEVEL!
IF NOT "!BUILD_ERRORLEVEL!"=="0" (
    EXIT /B !BUILD_ERRORLEVEL!
)

ENDLOCAL 

引用

这篇关于如何知道cmake项目的产生是否成功结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆