Added option to inject custom compile flags to compilation database (fixes #112)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -183,4 +183,17 @@ void generate_diagrams(const std::vector<std::string> &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
|
||||
@@ -139,6 +139,9 @@ void find_translation_units_for_diagrams(
|
||||
const std::vector<std::string> &compilation_database_files,
|
||||
std::map<std::string, std::vector<std::string>> &translation_units_map);
|
||||
|
||||
void adjust_compilation_database(const clanguml::config::config &config,
|
||||
clang::tooling::CompilationDatabase &db);
|
||||
|
||||
template <typename DiagramModel, typename DiagramConfig,
|
||||
typename TranslationUnitVisitor>
|
||||
class diagram_ast_consumer : public clang::ASTConsumer {
|
||||
|
||||
@@ -222,6 +222,7 @@ struct config : public inheritable_diagram_options {
|
||||
// directory
|
||||
option<std::string> compilation_database_dir{
|
||||
"compilation_database_dir", "."};
|
||||
option<std::vector<std::string>> add_compile_flags{"add_compile_flags"};
|
||||
option<std::string> output_directory{"output_directory"};
|
||||
|
||||
option<std::map<std::string, diagram_template>> diagram_templates{
|
||||
|
||||
@@ -585,6 +585,7 @@ template <> struct convert<config> {
|
||||
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);
|
||||
|
||||
@@ -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<const inheritable_diagram_options &>(c);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user