|
|
|
|
@ -82,41 +82,35 @@ CompileCommands::CompileCommands(const boost::filesystem::path &build_path) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path_) { |
|
|
|
|
auto file_path = file_path_; |
|
|
|
|
|
|
|
|
|
std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path) { |
|
|
|
|
std::string default_std_argument = "-std=c++1y"; |
|
|
|
|
|
|
|
|
|
auto extension = file_path.extension().string(); |
|
|
|
|
bool is_header = CompileCommands::is_header(file_path) || extension.empty(); // Include std C++ headers that are without extensions
|
|
|
|
|
|
|
|
|
|
// If header file, use a source file in the same folder if one exists
|
|
|
|
|
// If header file, use source file flags if they are in the same folder
|
|
|
|
|
std::vector<boost::filesystem::path> file_paths; |
|
|
|
|
if(is_header && !extension.empty()) { |
|
|
|
|
auto parent_path = file_path.parent_path(); |
|
|
|
|
auto stem = file_path.stem(); |
|
|
|
|
CompileCommands compile_commands(build_path); |
|
|
|
|
bool found = false; |
|
|
|
|
for(auto &command : compile_commands.commands) { |
|
|
|
|
// Priority on source file with the same filename (extension excluded) as the header file
|
|
|
|
|
if(command.file.stem() == stem) { |
|
|
|
|
file_path = command.file; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if(!found && command.file.parent_path() == parent_path) { |
|
|
|
|
file_path = command.file; |
|
|
|
|
found = true; |
|
|
|
|
} |
|
|
|
|
if(command.file.parent_path() == parent_path) |
|
|
|
|
file_paths.emplace_back(command.file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(file_paths.empty()) |
|
|
|
|
file_paths.emplace_back(file_path); |
|
|
|
|
|
|
|
|
|
std::vector<std::string> arguments; |
|
|
|
|
if(!build_path.empty()) { |
|
|
|
|
clangmm::CompilationDatabase db(build_path.string()); |
|
|
|
|
if(db) { |
|
|
|
|
clangmm::CompileCommands commands(file_path.string(), db); |
|
|
|
|
auto cmds = commands.get_commands(); |
|
|
|
|
for(auto &cmd : cmds) { |
|
|
|
|
auto cmd_arguments = cmd.get_arguments(); |
|
|
|
|
for(auto &file_path : file_paths) { |
|
|
|
|
clangmm::CompileCommands compile_commands(file_path.string(), db); |
|
|
|
|
auto commands = compile_commands.get_commands(); |
|
|
|
|
for(auto &command : commands) { |
|
|
|
|
auto cmd_arguments = command.get_arguments(); |
|
|
|
|
bool ignore_next = false; |
|
|
|
|
for(size_t c = 1; c < cmd_arguments.size(); c++) { |
|
|
|
|
if(ignore_next) { |
|
|
|
|
@ -134,6 +128,7 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
arguments.emplace_back(default_std_argument); |
|
|
|
|
} |
|
|
|
|
|