diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index afae97c..a0cdad0 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -11,19 +11,41 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # set(CMAKE_VERBOSE_MAKEFILE ON) # configure clang-tidy +find_program(CLANG_TIDY "clang-tidy") set(CLANG_TIDY_HEADER_FILTER "src/") -set(CLANG_TIDY_CHECKS "-*,bugprone-*,cert-*,modernize-*,-modernize-use-trailing-return-type,readability-*,performance-*,llvm-*,-llvm-header-guard,google-*,-google-readability-todo,cppcoreguidelines-*,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes") +set(CLANG_TIDY_CHECKS "-*,bugprone-*,cert-*,modernize-*,-modernize-use-trailing-return-type,readability-*,performance-*,llvm-*,-llvm-header-guard,google-*,-google-readability-todo,cppcoreguidelines-*,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-pro-type-union-access,-readability-function-cognitive-complexity") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # run clang-tidy on Release builds, disable with `set_target_properties(lib_foobar PROPERTIES CXX_CLANG_TIDY "")` -if (CMAKE_BUILD_TYPE STREQUAL "Release") +if (CMAKE_BUILD_TYPE STREQUAL "Release" AND CLANG_TIDY) set(CMAKE_CXX_CLANG_TIDY - clang-tidy; + ${CLANG_TIDY}; -header-filter=${CLANG_TIDY_HEADER_FILTER}; -checks=${CLANG_TIDY_CHECKS}; ) endif() +# generate a header file with the version number from git tag/ commit +# execute_process( +# COMMAND git describe --always --tags --dirty +# OUTPUT_VARIABLE GIT_VERSION_TAG +# OUTPUT_STRIP_TRAILING_WHITESPACE +# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +# ) +# execute_process( +# COMMAND git rev-parse --abbrev-ref HEAD +# OUTPUT_VARIABLE GIT_BRANCH_NAME +# OUTPUT_STRIP_TRAILING_WHITESPACE +# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +# ) +# message(STATUS "Git version: ${GIT_BRANCH_NAME}, ${GIT_VERSION_TAG}") + +# configure_file( +# autogen/version.h.in +# generated/version.h +# ) +# set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h) + ## CONFIGURE LIBRARIES @@ -78,12 +100,11 @@ install(TARGETS ctestapp # Caveat: This only works well, when all sources are added to the SOURCES variable. # If your project is separated into multiple (internal) libraries, use the integrated # clang-tidy runner of CMake, which is already enabled on Release builds. -find_program(CLANG_TIDY "clang-tidy") if(CLANG_TIDY) # get include directories and convert them to compiler flags (prepend "-I") - get_property(TIDY_INCLUDE_DIRS TARGET ctestapp PROPERTY INCLUDE_DIRECTORIES) - foreach(X IN ITEMS ${TIDY_INCLUDE_DIRS}) - list(APPEND TIDY_INCLUDE_DIRS_ARG "-I${X}") + get_target_property(TIDY_INCLUDE_DIRS ctestapp INCLUDE_DIRECTORIES) + foreach(dir IN ITEMS ${TIDY_INCLUDE_DIRS}) + list(APPEND TIDY_INCLUDE_DIRS_ARG "-I${dir}") endforeach() # add a Make target named "tidy" (to run clang-tidy manually) diff --git a/cpp/autogen/version.h.in b/cpp/autogen/version.h.in new file mode 100644 index 0000000..a94df13 --- /dev/null +++ b/cpp/autogen/version.h.in @@ -0,0 +1,17 @@ +/** + * @file version.h + * @brief Auto-generated version number preprocessor definitions + * + * These values will be calculated by CMake. Do not modify manually! + * + * @author Jannik Beyerstedt + * @copyright (c) consider it GmbH, 2020 + */ + +#ifndef VERSION_H +#define VERSION_H + +#define GIT_VERSION_TAG "@GIT_VERSION_TAG@" +#define GIT_BRANCH_NAME "@GIT_BRANCH_NAME@" + +#endif /* VERSION_H */ diff --git a/cpp/template-file.cpp b/cpp/template-file.cpp index 313f43e..fd30a58 100644 --- a/cpp/template-file.cpp +++ b/cpp/template-file.cpp @@ -1,7 +1,7 @@ /** * @file template-file.h * @brief File containing example of doxygen usage for quick reference. - * + * * Here typically goes a more extensive explanation of what the header defines. * * @author Name diff --git a/cpp/template-file.h b/cpp/template-file.h index 9bed9ab..0191376 100644 --- a/cpp/template-file.h +++ b/cpp/template-file.h @@ -1,7 +1,7 @@ /** * @file template-file.h * @brief File containing example of doxygen usage for quick reference. - * + * * Here typically goes a more extensive explanation of what the header defines. * * @author Name @@ -10,8 +10,8 @@ * @copyright Licensed under the GNU GPLv3 License */ -#ifndef _TEMPLATE_FILE_H -#define _TEMPLATE_FILE_H +#ifndef TEMPLATE_FILE_H +#define TEMPLATE_FILE_H // only include what is needed by this header file here! // starting with the most generic (standard library) @@ -31,7 +31,7 @@ typedef enum BoxEnum_enum { /** * @brief This method adds two integers. - * + * * Detailed explanation. * @param a First integer to add. * @param b Second integer to add. @@ -39,4 +39,4 @@ typedef enum BoxEnum_enum { */ int add(int a, int b); -#endif /* _TEMPLATE_FILE_H */ +#endif /* TEMPLATE_FILE_H */