|
11 | 11 | cmake_minimum_required(VERSION 2.8.12)
|
12 | 12 | project(creduce)
|
13 | 13 |
|
| 14 | +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") |
| 15 | + |
14 | 16 | include(CheckIncludeFile)
|
15 | 17 | include(CheckCXXCompilerFlag)
|
| 18 | +include(GetGitRevisionDescription) |
16 | 19 |
|
17 | 20 | ###############################################################################
|
18 | 21 |
|
| 22 | +# Determine the short git hash for the source tree. The logic here follows the |
| 23 | +# logic in the `git-hash.sh` script. |
| 24 | +# |
| 25 | +## METHOD 1: The source tree is the result of `git archive'. |
| 26 | +# `git archive' inserts the abbreviated hash of the archive's commit into this |
| 27 | +# file. (See the `.gitattributes' file.) |
| 28 | +# |
| 29 | +set(GIT_HASH "$Format:%h$") |
| 30 | +if(GIT_HASH MATCHES "^\\$") |
| 31 | + ## METHOD 2: The source tree is a git repository. |
| 32 | + get_git_head_revision(GIT_REFSPEC GIT_HASH) |
| 33 | + if(NOT GIT_HASH STREQUAL "GITDIR-NOTFOUND") |
| 34 | + # Trim to the short hash. |
| 35 | + string(SUBSTRING "${GIT_HASH}" 0 7 GIT_HASH) |
| 36 | + else() |
| 37 | + ## METHOD 3: Give up. |
| 38 | + set(GIT_HASH "unknown") |
| 39 | + endif() |
| 40 | +endif() |
| 41 | + |
| 42 | +add_definitions("-DGIT_VERSION=\"${GIT_HASH}\"") |
| 43 | + |
| 44 | +### |
| 45 | + |
19 | 46 | # Generate config.h
|
20 | 47 | #
|
21 | 48 | set(ENABLE_TRANS_ASSERT ON CACHE BOOL "Use assert() in clang_delta transformations.")
|
@@ -47,11 +74,6 @@ configure_file("cmake_config.h.in" "${PROJECT_BINARY_DIR}/config.h")
|
47 | 74 |
|
48 | 75 | ###
|
49 | 76 |
|
50 |
| -execute_process(COMMAND "git" "show" "-s" "--format=%h" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE creduce_GIT_HASH) |
51 |
| -string(STRIP "${creduce_GIT_HASH}" creduce_GIT_HASH) |
52 |
| - |
53 |
| -### |
54 |
| - |
55 | 77 | # Include this flag if the C++ compiler supports it.
|
56 | 78 | # See LLVM file `share/llvm/cmake/HandleLLVMOptions.cmake`.
|
57 | 79 | check_cxx_compiler_flag(
|
|
0 commit comments