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.
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"
)
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:
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…