I'm using libclang's LibTooling
to get code completion data from C++ source files.
The ASTUnits are generated from a compile_commands.json file created via CMake
with Ninja
as the generator.
In the compiler invocation commands, there are relative header include paths (such as -Ifoo -I../bar
).
To successfully generate a clang::ASTUnit
, I need to set clang::FileManager::FileSystemOptions::WorkingDir
to instruct clang on how to canonicalise the relative paths.
Problem is, when calling
clang::ASTUnit::Reparse()
on my ASTUnits, this value is discarded and myclang::DiagnosticConsumer
then reports missing header files.
As a workaround, I'm regenerating the ASTUnits from scratch instead of reparsing them when the sources changes.
Q1:
Is this normal behavior ? For me it essencialy makes Reparse
useless.
Q2:
How to successfully reparse an ASTUnit with relative header include paths ?
Follow-up : Using Clang/LLVM 4.0.0, it is not possible to reparse an ASTUnit which compiler invocation contains relative include paths.
Starting from 5.0.0 however, clang::ASTUnit::Reparse
contains a third argument that allows to pass a clang::vfs::FileSystem
object that can solve this problem.