cmake execute_process()始终失败,并显示“无此文件或目录”。当我打电话给git [英] cmake execute_process() always fails with "No such file or directory" when I call git

查看:484
本文介绍了cmake execute_process()始终失败,并显示“无此文件或目录”。当我打电话给git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux计算机上,从cmake项目中,我试图使用execute_process调用git,以便可以将源代码控制中的信息包含到我的应用程序中。

On a linux machine, from a cmake project, I'm trying to call git using execute_process so that I can include info from source control into my app.

我创建了一个小测试来尝试打印git版本:

I created a little test to try and print the git version:

cmake_minimum_required (VERSION 2.8)

set (git_cmd "/usr/bin/git --version")
#set (git_cmd "ls") # returns success if you uncomment this line 
message(STATUS "git cmd: ${git_cmd}")
execute_process(COMMAND ${git_cmd}
  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  RESULT_VARIABLE git_result
  OUTPUT_VARIABLE git_ver)

message(STATUS "git ver[${git_result}]: ${git_ver}")

configure_file (
  "${PROJECT_SOURCE_DIR}/versionInfo.h.in"
  "${PROJECT_BINARY_DIR}/versionInfo.h"
  )

在运行make时会给出以下输出:

Which gives the following output when you run make:

-- git cmd: /usr/bin/git --version
-- git ver[No such file or directory]: 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rsanderson/build/githash: 

但是如果我将命令更改为 ls ,则结果有效,并且我看到目录列表打印出来。我还检查了/ usr / bin中确实存在git。

But if I change the command to ls the result is valid and I see the dir listing print. I also checked with which that git is indeed in /usr/bin.

对我在这里缺少的内容有任何想法吗?

Any ideas of what I'm missing here?

推荐答案

您必须将参数作为第二个选项传递,例如:

You have to pass the arguments as a second option like this:

cmake_minimum_required (VERSION 2.8)

set (git_cmd "git")
set (git_arg "--version")
message(STATUS "git cmd: ${git_cmd}")
execute_process(COMMAND ${git_cmd} ${git_arg}
  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  RESULT_VARIABLE git_result
  OUTPUT_VARIABLE git_ver)

message(STATUS "git ver[${git_result}]: ${git_ver}")

这篇关于cmake execute_process()始终失败,并显示“无此文件或目录”。当我打电话给git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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