diff options
author | David Shah <dave@ds0.me> | 2020-01-14 18:47:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 18:47:45 +0000 |
commit | 4cdf002557e17b23c1b9ba2e01e51279049894a3 (patch) | |
tree | 08c24d466d84a0e90cd6f221aaed347dcf247366 | |
parent | 56918e5596a8531c5a21bed8e9407fa0ea7aa507 (diff) | |
parent | 659c4fad56da8d285060c8d0edd3918e8c5a1575 (diff) | |
download | nextpnr-4cdf002557e17b23c1b9ba2e01e51279049894a3.tar.gz nextpnr-4cdf002557e17b23c1b9ba2e01e51279049894a3.tar.bz2 nextpnr-4cdf002557e17b23c1b9ba2e01e51279049894a3.zip |
Merge pull request #379 from twam/pass_version
Change version to git describe and make set-able from outside
-rw-r--r-- | CMakeLists.txt | 20 | ||||
-rw-r--r-- | common/command.cc | 4 | ||||
-rw-r--r-- | common/version.h.in | 2 | ||||
-rw-r--r-- | json/jsonwrite.cc | 2 |
4 files changed, 15 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 54da5bdd..8131d4a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,13 +121,17 @@ else() add_definitions("-DNO_GUI") endif() -# Get the latest abbreviated commit hash of the working branch -execute_process( - COMMAND git log -1 --format=%h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE -) +if (NOT DEFINED CURRENT_GIT_VERSION) + # Get the latest abbreviated commit hash of the working branch + # if not already defined outside (e.g. by package manager when building + # outside of git repository) + execute_process( + COMMAND git describe --tags --always + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE CURRENT_GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() if (BUILD_TESTS) add_subdirectory(3rdparty/googletest/googletest ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/googletest EXCLUDE_FROM_ALL) @@ -138,8 +142,6 @@ if (BUILD_GUI) add_subdirectory(3rdparty/QtPropertyBrowser ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/QtPropertyBrowser EXCLUDE_FROM_ALL) endif() -add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}") - configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/common/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h ) diff --git a/common/command.cc b/common/command.cc index c2f02b27..3866caca 100644 --- a/common/command.cc +++ b/common/command.cc @@ -69,14 +69,14 @@ bool CommandHandler::executeBeforeContext() { if (vm.count("help") || argc == 1) { std::cerr << boost::filesystem::basename(argv[0]) - << " -- Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")\n"; + << " -- Next Generation Place and Route (Version " GIT_DESCRIBE_STR ")\n"; std::cerr << options << "\n"; return argc != 1; } if (vm.count("version")) { std::cerr << boost::filesystem::basename(argv[0]) - << " -- Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")\n"; + << " -- Next Generation Place and Route (Version " GIT_DESCRIBE_STR ")\n"; return true; } validate(); diff --git a/common/version.h.in b/common/version.h.in index 8072116b..c67d7d52 100644 --- a/common/version.h.in +++ b/common/version.h.in @@ -1,6 +1,6 @@ #ifndef VERSION_H #define VERSION_H -#define GIT_COMMIT_HASH_STR "@GIT_COMMIT_HASH@" +#define GIT_DESCRIBE_STR "@CURRENT_GIT_VERSION@" #endif
\ No newline at end of file diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 9723d3b2..477bfca5 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -214,7 +214,7 @@ void write_context(std::ostream &f, Context *ctx) { f << stringf("{\n"); f << stringf(" \"creator\": %s,\n", - get_string("Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")").c_str()); + get_string("Next Generation Place and Route (Version " GIT_DESCRIBE_STR ")").c_str()); f << stringf(" \"modules\": {\n"); write_module(f, ctx); f << stringf("\n }"); |