From c48dc7c1daf9178efd81884fa7a12beb59468b2b Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 28 Nov 2015 13:05:08 +0000 Subject: [PATCH] Reimplement CMake Git revision extraction The third-party module solution used didn't require Git to be installed, but it was broken when the repository layout changed. Since Git is very likely to be installed, just use CMake's built-in FindGit module and call Git to extract the HEAD short revision ID. --- CMakeLists.txt | 24 +++++++----------------- docs/BUILD.MSVC.md | 2 -- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3197eefd..2f36245b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,24 +7,14 @@ # Get Build Revision ############################## -# Uses the CMake module in this repo: https://github.com/rpavlik/cmake-modules -# On Windows, this requires Git for Windows to be installed. +find_package(Git) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) -include(GetGitRevisionDescription OPTIONAL RESULT_VARIABLE GIT_MODULE_PATH) -IF (NOT GIT_MODULE_PATH MATCHES "NOTFOUND") - get_git_head_revision(GIT_REFSPEC GIT_COMMIT_STRING --tags --long) - - IF (GIT_COMMIT_STRING MATCHES "GITDIR-NOTFOUND") - set(GIT_COMMIT_STRING "unknown") - ELSE () - # Get a shortened ID. Although knowing the shortest unique string requires Git, - # 8 characters should be a good compromise between chance of ambiguity and length, - # especially since the version numbers would narrow down the range of possibly - # ambiguous commits. - string(SUBSTRING ${GIT_COMMIT_STRING} 0 8 GIT_COMMIT_STRING) - ENDIF () -ELSE () +IF (GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE GIT_COMMIT_STRING + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +ELSE() SET (GIT_COMMIT_STRING "unknown") ENDIF () diff --git a/docs/BUILD.MSVC.md b/docs/BUILD.MSVC.md index 899a0669..14ac4647 100644 --- a/docs/BUILD.MSVC.md +++ b/docs/BUILD.MSVC.md @@ -67,8 +67,6 @@ Example CMake keys: `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DCMAKE_ARCHIVE_OUTP #### LOOT -LOOT uses a third-party CMake module to generate its build revision data, so first download the `GetGitRevisionDescription.cmake` and `GetGitRevisionDescription.cmake.in` files found in [this repository](https://github.com/rpavlik/cmake-modules) to the `build` subdirectory of the LOOT folder. - 1. Set CMake up so that it builds the binaries in the `build` subdirectory of the LOOT folder. 2. Define any necessary parameters. 3. Configure CMake, then generate a build system for Visual Studio 12.