diff --git a/.gitignore b/.gitignore index 25b55aa4..c615ae18 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ bin/ docs/diagrams coverage*.info - +packaging/_BUILD # CLion diff --git a/CMakeLists.txt b/CMakeLists.txt index d8acf6d4..58c64b2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 17) +set(CMAKE_VERBOSE_MAKEFILE ON) + set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") @@ -16,6 +18,7 @@ set(CLANG_UML_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin) set(UML_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src/uml) option(LLVM_CONFIG_PATH "Path to custom llvm-config executable") +option(GIT_VERSION "clang-uml version" "0.1.0") if(LLVM_CONFIG_PATH) message(STATUS "Using llvm-config from ${LLVM_CONFIG_PATH}") @@ -45,6 +48,10 @@ find_package(LLVM REQUIRED CONFIG) set(CLANG_INCLUDE_DIRS "llvm/clang/include") set(CLANG_LIBS clang) +# Configure executable version +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/src/version) +configure_file(src/version.h.in ${PROJECT_BINARY_DIR}/src/version/version.h) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") execute_process(COMMAND gcc --print-file-name=include OUTPUT_STRIP_TRAILING_WHITESPACE @@ -61,6 +68,8 @@ include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/include) include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/external/type_safe/include) include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/external/type_safe/external/debug_assert) include_directories(${PROJECT_SOURCE_DIR}/src/) +include_directories(${PROJECT_BINARY_DIR}/src/version) + file(GLOB_RECURSE SOURCES src/*.cc include/*.h) set(MAIN_SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc) diff --git a/Makefile b/Makefile index 6aaeb204..37a42714 100644 --- a/Makefile +++ b/Makefile @@ -26,12 +26,15 @@ LLVM_CONFIG_PATH ?= CMAKE_CXX_FLAGS ?= CMAKE_EXE_LINKER_FLAGS ?= +GIT_VERSION ?= $(shell git describe --tags --always --abbrev=7) + .PHONY: clean clean: rm -rf debug release debug/CMakeLists.txt: cmake -S . -B debug \ + -DGIT_VERSION=$(GIT_VERSION) \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS)" \ @@ -40,6 +43,7 @@ debug/CMakeLists.txt: release/CMakeLists.txt: cmake -S . -B release \ + -DGIT_VERSION=$(GIT_VERSION) \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS)" \ diff --git a/src/main.cc b/src/main.cc index 8ffe930b..0c6431c5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -21,8 +21,8 @@ #include "include_diagram/generators/plantuml/include_diagram_generator.h" #include "package_diagram/generators/plantuml/package_diagram_generator.h" #include "sequence_diagram/generators/plantuml/sequence_diagram_generator.h" - #include "util/util.h" +#include "version.h" #include #include @@ -38,6 +38,8 @@ using namespace clanguml; using config::config; +void print_version(); + void print_diagrams_list(const clanguml::config::config &cfg); bool check_output_directory(const std::string &dir); @@ -55,6 +57,7 @@ int main(int argc, const char *argv[]) std::vector diagram_names{}; std::optional output_directory; unsigned int thread_count{0}; + bool show_version{false}; bool verbose{false}; bool list_diagrams{false}; @@ -68,12 +71,18 @@ int main(int argc, const char *argv[]) "Override output directory specified in config file"); app.add_option("-t,--thread-count", thread_count, "Thread pool size (0 = hardware concurrency)"); + app.add_flag("-V,--version", show_version, "Print version and exit"); app.add_flag("-v,--verbose", verbose, "Verbose logging"); app.add_flag("-l,--list-diagrams", list_diagrams, "Print list of diagrams defined in the config file"); CLI11_PARSE(app, argc, argv); + if (show_version) { + print_version(); + return 0; + } + clanguml::util::setup_logging(verbose); clanguml::config::config config; @@ -223,6 +232,15 @@ bool check_output_directory(const std::string &dir) return true; } +void print_version() +{ + std::cout << "clang-uml " << clanguml::version::CLANG_UML_VERSION << '\n'; + std::cout << "Copyright (C) 2021-2022 Bartek Kryza " + << '\n'; + std::cout << "Built with libclang: " + << clanguml::version::CLANG_UML_LIBCLANG_VERSION << std::endl; +} + void print_diagrams_list(const clanguml::config::config &cfg) { using std::cout; diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 00000000..fb0a72a7 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,23 @@ +/** + * src/version.h + * + * Copyright (c) 2021-2022 Bartek Kryza + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +namespace clanguml::version { +static constexpr auto CLANG_UML_VERSION = "@GIT_VERSION@"; +static constexpr auto CLANG_UML_LIBCLANG_VERSION = "@LIBCLANG_VERSION_STRING@"; +} // namespace clanguml::version \ No newline at end of file