diff --git a/CHANGELOG.md b/CHANGELOG.md index 085f0d9a..f7647295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # CHANGELOG +### 0.3.3 + * Added 'add_compile_flags' config options (#112) * Added JSON generator (#114) * Added diagram templates support (#105) * Added parents (base classes) diagram filter diff --git a/README.md b/README.md index 4c4b2d55..2f2130f5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build status](https://github.com/bkryza/clang-uml/actions/workflows/build.yml/badge.svg)](https://github.com/bkryza/clang-uml/actions) [![Coverage](https://codecov.io/gh/bkryza/clang-uml/branch/master/graph/badge.svg)](https://codecov.io/gh/bkryza/clang-uml) -[![Version](https://img.shields.io/badge/version-0.3.2-blue)](https://github.com/bkryza/clang-uml/releases) +[![Version](https://img.shields.io/badge/version-0.3.3-blue)](https://github.com/bkryza/clang-uml/releases) [![Version](https://img.shields.io/badge/LLVM-12,13,14,15-orange)](https://github.com/bkryza/clang-uml/releases) `clang-uml` is an automatic C++ to UML class, sequence, package and include diagram generator, driven by diff --git a/docs/configuration_file.md b/docs/configuration_file.md index e1111913..d365e3e9 100644 --- a/docs/configuration_file.md +++ b/docs/configuration_file.md @@ -53,6 +53,9 @@ ```yaml # Directory containing the compile_commands.json file compilation_database_dir: debug +# Inject additional compile commands to the compilation database entries +add_compile_flags: + - '-Wno-vla-extension' # The directory where *.puml files will be generated output_directory: docs/diagrams # Set this as default for all diagrams diff --git a/src/common/generators/generators.cc b/src/common/generators/generators.cc index 83d1f5c1..ffc50eca 100644 --- a/src/common/generators/generators.cc +++ b/src/common/generators/generators.cc @@ -183,4 +183,17 @@ void generate_diagrams(const std::vector &diagram_names, } } +void adjust_compilation_database(const clanguml::config::config &config, + clang::tooling::CompilationDatabase &db) +{ + if (config.add_compile_flags && !config.add_compile_flags().empty()) { + for (auto &compile_command : db.getAllCompileCommands()) { + compile_command.CommandLine.insert( + compile_command.CommandLine.begin() + 1, + config.add_compile_flags().begin(), + config.add_compile_flags().end()); + } + } +} + } // namespace clanguml::common::generators \ No newline at end of file diff --git a/src/common/generators/generators.h b/src/common/generators/generators.h index c2a6e956..e85d2f8f 100644 --- a/src/common/generators/generators.h +++ b/src/common/generators/generators.h @@ -139,6 +139,9 @@ void find_translation_units_for_diagrams( const std::vector &compilation_database_files, std::map> &translation_units_map); +void adjust_compilation_database(const clanguml::config::config &config, + clang::tooling::CompilationDatabase &db); + template class diagram_ast_consumer : public clang::ASTConsumer { diff --git a/src/common/model/source_file.cc b/src/common/model/source_file.cc index b5161c97..de121e77 100644 --- a/src/common/model/source_file.cc +++ b/src/common/model/source_file.cc @@ -31,6 +31,7 @@ std::string to_string(source_file_t sf) return "implementation"; default: assert(false); + return ""; } } diff --git a/src/common/model/template_parameter.cc b/src/common/model/template_parameter.cc index 662f6286..d3a80903 100644 --- a/src/common/model/template_parameter.cc +++ b/src/common/model/template_parameter.cc @@ -37,7 +37,8 @@ std::string to_string(template_parameter_kind_t k) case template_parameter_kind_t::concept_constraint: return "concept_constraint"; default: - assert(0); + assert(false); + return ""; } } diff --git a/src/config/config.h b/src/config/config.h index c13ffc08..1a5c1172 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -222,6 +222,7 @@ struct config : public inheritable_diagram_options { // directory option compilation_database_dir{ "compilation_database_dir", "."}; + option> add_compile_flags{"add_compile_flags"}; option output_directory{"output_directory"}; option> diagram_templates{ diff --git a/src/config/yaml_decoders.cc b/src/config/yaml_decoders.cc index 52c7befb..e7d1b55c 100644 --- a/src/config/yaml_decoders.cc +++ b/src/config/yaml_decoders.cc @@ -585,6 +585,7 @@ template <> struct convert { get_option(node, rhs.using_namespace); get_option(node, rhs.output_directory); get_option(node, rhs.compilation_database_dir); + get_option(node, rhs.add_compile_flags); get_option(node, rhs.include_relations_also_as_members); get_option(node, rhs.puml); get_option(node, rhs.generate_method_arguments); diff --git a/src/config/yaml_emitters.cc b/src/config/yaml_emitters.cc index cb7a6be8..66a0b38e 100644 --- a/src/config/yaml_emitters.cc +++ b/src/config/yaml_emitters.cc @@ -187,6 +187,7 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const config &c) out << c.compilation_database_dir; out << c.output_directory; + out << c.add_compile_flags; out << dynamic_cast(c); diff --git a/src/main.cc b/src/main.cc index f8ef1031..e6acb353 100644 --- a/src/main.cc +++ b/src/main.cc @@ -76,6 +76,12 @@ int main(int argc, const char *argv[]) cli.diagram_names, cli.config, compilation_database_files, translation_units_map); + // + // Inject any additional compilation flags from the config to the + // compilation database + // + clanguml::common::generators::adjust_compilation_database(cli.config, *db); + clanguml::common::generators::generate_diagrams(cli.diagram_names, cli.config, cli.effective_output_directory, db, cli.verbose, cli.thread_count, cli.generators, translation_units_map);