Added --query-driver option to enable automatic detection of system include paths from selected compiler (#109)
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "compilation_database.h"
|
||||
|
||||
#include "util/query_driver_output_extractor.h"
|
||||
|
||||
namespace clanguml::common {
|
||||
|
||||
std::unique_ptr<compilation_database>
|
||||
@@ -77,9 +79,40 @@ compilation_database::getAllCompileCommands() const
|
||||
return commands;
|
||||
}
|
||||
|
||||
std::string compilation_database::guess_language_from_filename(
|
||||
const std::string &filename) const
|
||||
{
|
||||
if (util::ends_with(filename, std::string{".c"}))
|
||||
return "c";
|
||||
|
||||
return "c++";
|
||||
}
|
||||
|
||||
void compilation_database::adjust_compilation_database(
|
||||
std::vector<clang::tooling::CompileCommand> &commands) const
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
if (config().query_driver && !config().query_driver().empty()) {
|
||||
for (auto &compile_command : commands) {
|
||||
util::query_driver_output_extractor extractor{
|
||||
config().query_driver(),
|
||||
guess_language_from_filename(compile_command.Filename)};
|
||||
|
||||
extractor.execute();
|
||||
|
||||
std::vector<std::string> system_header_args;
|
||||
for (const auto &path : extractor.system_include_paths()) {
|
||||
system_header_args.emplace_back("-isystem");
|
||||
system_header_args.emplace_back(path);
|
||||
}
|
||||
|
||||
compile_command.CommandLine.insert(
|
||||
compile_command.CommandLine.begin() + 1,
|
||||
system_header_args.begin(), system_header_args.end());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config().add_compile_flags && !config().add_compile_flags().empty()) {
|
||||
for (auto &compile_command : commands) {
|
||||
compile_command.CommandLine.insert(
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
|
||||
const clang::tooling::CompilationDatabase &base() const;
|
||||
|
||||
std::string guess_language_from_filename(const std::string &filename) const;
|
||||
|
||||
private:
|
||||
void adjust_compilation_database(
|
||||
std::vector<clang::tooling::CompileCommand> &commands) const;
|
||||
|
||||
Reference in New Issue
Block a user