5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Git-2.7.0.windows.1 と CMake-3.4.1 で FindGit できない時の応急措置

Posted at

再現しるる対象環境

  • Windows
  • Git for Windows: 2.7.0.windows.1
    • env:path (%PATH%) を通した状態
  • CMake: 3.4.1

発生する問題

例として ExternalProject を使うなど CMake 内部で FindGit を間接的に、あるいは直接使う CMakeLists.txt に対して cmake した際に次のように Git のバージョンを取得できない事によりエラーが発生し中断する現象が発生する。

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/ExternalProject.cmake:1743 (message):
  error: git version 1.6.5 or later required for 'git submodule update
  --recursive': GIT_VERSION_STRING=''

問題の原因

CMake に含まれる FindGit.cmake が find_program で Git の実行ファイルを探すが、この時に Git for Windows をパスを通した状態で導入していると cmake の実行パスに git コマンドがあるかのように誤認識を起こす。

例えば C:\hoge\build から cmake .. などとした場合、 FindGit.cmake 内部では GIT_EXECUTABLE 変数へ誤って C:/hoge/build/git なるパス文字列をセットしてしまう。当然このようなフルパスに git コマンドは通常存在しないため Git のバージョン取得を行う FindGit.cmake の内部的なコードの実行と結果の取得は正常に行われず、 FindGit を間接あるいは直接必要とする CMakeLists.txt への cmake は失敗する。

この問題が起きた場合の応急措置

CMake を導入したパスがデフォールトであれば、"C:\Program Files (x86)\CMake\share\cmake-3.4\Modules\FindGit.cmake" を適当なテキストエディターを管理者権限で実行した状態で開き、 find_program の代わりにさしあたりこの環境の git.exe パスを直接定義する。

set(GIT_EXECUTABLE "C:/Program Files/Git/bin/git.exe")

注意

この対応はあくまでもこの状態になった環境での応急措置として行った事を忘れない事。

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?