project(GitUpdateTest) cmake_minimum_required(VERSION 2.8) if(WIN32) option(USE_GIT_EXE OFF "Prefer git.exe instead of git.cmd") endif() set(Git_FOUND 0) set(GIT_EXECUTABLE GIT_EXECUTABLE-NOTFOUND) if(USE_GIT_EXE) if(EXISTS "C:/Program Files (x86)/Git/bin/git.exe") set(GIT_EXECUTABLE "C:/Program Files (x86)/Git/bin/git.exe" CACHE FILEPATH "prefer git.exe" FORCE) elseif(EXISTS "C:/Program Files/Git/bin/git.exe") set(GIT_EXECUTABLE "C:/Program Files/Git/bin/git.exe" CACHE FILEPATH "prefer git.exe" FORCE) endif() endif() find_package(Git REQUIRED) message("GIT_EXECUTABLE: ${GIT_EXECUTABLE}") set(git_repo_dir "${CMAKE_CURRENT_BINARY_DIR}/test_repo") file(APPEND "${git_repo_dir}/test.txt" "text\n") add_custom_target(UpdateGitRepo ALL COMMAND ${GIT_EXECUTABLE} init COMMAND ${GIT_EXECUTABLE} add test.txt COMMAND ${GIT_EXECUTABLE} commit -m "Bla" WORKING_DIRECTORY ${git_repo_dir} )