Browse Source

Improved CUDA support, and no longer passes multiple -x arguments to libclang. Some related cleanup as well.

merge-requests/388/head
eidheim 8 years ago
parent
commit
b47d971ca9
  1. 38
      src/compile_commands.cc
  2. 3
      src/compile_commands.h
  3. 25
      src/usages_clang.cc
  4. 3
      src/usages_clang.h

38
src/compile_commands.cc

@ -97,7 +97,8 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
ignore_next=false; ignore_next=false;
continue; continue;
} }
else if(cmd_arguments[c]=="-o" || cmd_arguments[c]=="-c") { else if(cmd_arguments[c]=="-o" || cmd_arguments[c]=="-c" ||
cmd_arguments[c]=="-x") { // Remove language arguments since some tools add languages not understood by clang
ignore_next=true; ignore_next=true;
continue; continue;
} }
@ -132,28 +133,30 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
arguments.emplace_back("-fretain-comments-from-system-headers"); arguments.emplace_back("-fretain-comments-from-system-headers");
auto extension=file_path.extension().string(); auto extension=file_path.extension().string();
if(extension==".h" || //TODO: temporary fix for .h-files (parse as c++) bool is_header=CompileCommands::is_header(file_path) || extension.empty(); // Include std C++ headers that are without extensions
extension!=".c")
arguments.emplace_back("-xc++");
if(extension.empty() || (1<extension.size() && extension[1]=='h') || extension==".tcc" || extension==".cuh") { if(is_header) {
arguments.emplace_back("-Wno-pragma-once-outside-header"); arguments.emplace_back("-Wno-pragma-once-outside-header");
arguments.emplace_back("-Wno-pragma-system-header-outside-header"); arguments.emplace_back("-Wno-pragma-system-header-outside-header");
arguments.emplace_back("-Wno-include-next-outside-header"); arguments.emplace_back("-Wno-include-next-outside-header");
} }
if(extension==".cu" || extension==".cuh") { if(extension==".cu" || extension==".cuh") {
arguments.emplace_back("-xcuda");
arguments.emplace_back("-D__CUDACC__");
arguments.emplace_back("-include"); arguments.emplace_back("-include");
arguments.emplace_back("cuda_runtime.h"); arguments.emplace_back("cuda_runtime.h");
arguments.emplace_back("-ferror-limit=1000"); // CUDA headers redeclares some std functions
} }
else if(extension==".cl") {
if(extension==".cl") {
arguments.emplace_back("-xcl"); arguments.emplace_back("-xcl");
arguments.emplace_back("-cl-std=CL2.0"); arguments.emplace_back("-cl-std=CL2.0");
arguments.emplace_back("-Xclang"); arguments.emplace_back("-Xclang");
arguments.emplace_back("-finclude-default-header"); arguments.emplace_back("-finclude-default-header");
arguments.emplace_back("-Wno-gcc-compat"); arguments.emplace_back("-Wno-gcc-compat");
} }
else if(is_header)
arguments.emplace_back("-xc++");
if(!build_path.empty()) { if(!build_path.empty()) {
arguments.emplace_back("-working-directory"); arguments.emplace_back("-working-directory");
@ -162,3 +165,24 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
return arguments; return arguments;
} }
bool CompileCommands::is_header(const boost::filesystem::path &path) {
auto ext = path.extension();
if(ext == ".h" || // c headers
ext == ".hh" || ext == ".hp" || ext == ".hpp" || ext == ".h++" || ext == ".tcc" || // c++ headers
ext == ".cuh") // CUDA headers
return true;
else
return false;
}
bool CompileCommands::is_source(const boost::filesystem::path &path) {
auto ext = path.extension();
if(ext == ".c" || // c sources
ext == ".cpp" || ext == ".cxx" || ext == ".cc" || ext == ".C" || ext == ".c++" || // c++ sources
ext == ".cu" || // CUDA sources
ext == ".cl") // OpenCL sources
return true;
else
return false;
}

3
src/compile_commands.h

@ -19,4 +19,7 @@ public:
/// Return arguments for the given file using libclangmm /// Return arguments for the given file using libclangmm
static std::vector<std::string> get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path); static std::vector<std::string> get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path);
static bool is_header(const boost::filesystem::path &path);
static bool is_source(const boost::filesystem::path &path);
}; };

25
src/usages_clang.cc

@ -532,9 +532,9 @@ Usages::Clang::PathSet Usages::Clang::find_paths(const boost::filesystem::path &
continue; continue;
} }
if(is_header(path)) if(CompileCommands::is_header(path))
paths.emplace(path); paths.emplace(path);
else if(is_source(path)) { else if(CompileCommands::is_source(path)) {
for(auto &command : compile_commands.commands) { for(auto &command : compile_commands.commands) {
if(filesystem::get_normal_path(command.file) == path) { if(filesystem::get_normal_path(command.file) == path) {
paths.emplace(path); paths.emplace(path);
@ -547,27 +547,6 @@ Usages::Clang::PathSet Usages::Clang::find_paths(const boost::filesystem::path &
return paths; return paths;
} }
bool Usages::Clang::is_header(const boost::filesystem::path &path) {
auto ext = path.extension();
if(ext == ".h" || // c headers
ext == ".hh" || ext == ".hp" || ext == ".hpp" || ext == ".h++" || ext == ".tcc" || // c++ headers
ext == ".cuh") // CUDA headers
return true;
else
return false;
}
bool Usages::Clang::is_source(const boost::filesystem::path &path) {
auto ext = path.extension();
if(ext == ".c" || // c sources
ext == ".cpp" || ext == ".cxx" || ext == ".cc" || ext == ".C" || ext == ".c++" || // c++ sources
ext == ".cu" || // CUDA sources
ext == ".cl") // OpenCL sources
return true;
else
return false;
}
std::pair<std::map<boost::filesystem::path, Usages::Clang::PathSet>, Usages::Clang::PathSet> Usages::Clang::parse_paths(const std::string &spelling, const PathSet &paths) { std::pair<std::map<boost::filesystem::path, Usages::Clang::PathSet>, Usages::Clang::PathSet> Usages::Clang::parse_paths(const std::string &spelling, const PathSet &paths) {
std::map<boost::filesystem::path, PathSet> paths_includes; std::map<boost::filesystem::path, PathSet> paths_includes;
PathSet paths_with_spelling; PathSet paths_with_spelling;

3
src/usages_clang.h

@ -133,9 +133,6 @@ namespace Usages {
static PathSet find_paths(const boost::filesystem::path &project_path, static PathSet find_paths(const boost::filesystem::path &project_path,
const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path); const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path);
static bool is_header(const boost::filesystem::path &path);
static bool is_source(const boost::filesystem::path &path);
static std::pair<std::map<boost::filesystem::path, PathSet>, PathSet> parse_paths(const std::string &spelling, const PathSet &paths); static std::pair<std::map<boost::filesystem::path, PathSet>, PathSet> parse_paths(const std::string &spelling, const PathSet &paths);
/// Recursively find and return all the include paths of path /// Recursively find and return all the include paths of path

Loading…
Cancel
Save