From b6155ddf737e68ff15d8428fae607fdc955cfb44 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sat, 23 Mar 2019 20:24:10 -0400 Subject: [PATCH] Enhance the output of --version with Git describe results. (#342) --- CMakeLists.txt | 17 +++++++++++++++++ src/main.cc | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 173a373e..efca2ba9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,3 +209,20 @@ target_sources(ccls PRIVATE src/messages/textDocument_signatureHelp.cc src/messages/workspace.cc ) + +### Obtain CCLS version information from Git +### This only happens when cmake is re-run! + +if(NOT CCLS_VERSION) + execute_process(COMMAND git describe --tag --long HEAD + OUTPUT_VARIABLE CCLS_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") + + if(NOT CCLS_VERSION) + set(CCLS_VERSION "") + endif() +endif() + +set_property(SOURCE src/main.cc APPEND PROPERTY + COMPILE_DEFINITIONS CCLS_VERSION=\"${CCLS_VERSION}\") diff --git a/src/main.cc b/src/main.cc index 0ebcfc1a..080c4765 100644 --- a/src/main.cc +++ b/src/main.cc @@ -60,7 +60,8 @@ int main(int argc, char **argv) { TraceMe(); sys::PrintStackTraceOnErrorSignal(argv[0]); cl::SetVersionPrinter([](raw_ostream &OS) { - OS << clang::getClangToolFullVersion("ccls") << "\n"; + OS << clang::getClangToolFullVersion("ccls version " CCLS_VERSION "\nclang") + << "\n"; }); for (auto &I : TopLevelSubCommand->OptionsMap)