[cfe-dev] How to add custom include dir to the header search path?
huc1985
huc1985 at 163.com
Mon Apr 8 19:52:16 PDT 2013
I'm writing a tools (do some static check) using clang lib . This is my code:
void main()
{
DiagnosticOptions diagnosticOptions;
TextDiagnosticPrinter *printer = new
TextDiagnosticPrinter(llvm::nulls(),
diagnosticOptions);
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs;
DiagnosticsEngine diagnostics(diagIDs, printer);
LangOptions langOpts;
TargetOptions targetOpts;
targetOpts.Triple = llvm::sys::getDefaultTargetTriple();
TargetInfo *pti = TargetInfo::CreateTargetInfo(diagnostics, targetOpts);
FileSystemOptions fsopts;
FileManager fileManager(fsopts);
SourceManager sourceManager(diagnostics, fileManager);
HeaderSearch headerSearch(fileManager, diagnostics, langOpts, pti);
CompilerInstance *theCompInst = new CompilerInstance();
theCompInst->setDiagnostics(&diagnostics);
Preprocessor *pp = new Preprocessor(diagnostics, langOpts,
pti,sourceManager, headerSearch, *theCompInst);
const FileEntry *pFile = fileManager.getFile(file_name);
sourceManager.createMainFileID(pFile);
theCompInst->getDiagnosticClient().BeginSourceFile(theCompInst->getLangOpts(),pp);
theCompInst->setPreprocessor(pp);
theCompInst->setSourceManager(&sourceManager);
theCompInst->setTarget(pti);
theCompInst->setDiagnostics(&diagnostics);
SourceManager &sourceMgr = theCompInst->getSourceManager();
theCompInst->createASTContext();
Rewriter rewriter;
rewriter.setSourceMgr(sourceMgr,langOpts);
MyASTConsumer consumer(rewriter);
ParseAST(theCompInst->getPreprocessor(), &consumer,
theCompInst->getASTContext());
theCompInst->getDiagnosticClient().EndSourceFile();
}
I want to check some C/C++ code using this tools. But *.h file and *.c file
is not in the same filefold.
Example:
test.c context:
#include "test.h"
.........
test.c in D:\test\test.c
test.h in D:\test\include\test.h
So I need to add "D:\test\include" to the header search path. How to do that
in my code?
Thanks all!
--
View this message in context: http://clang-developers.42468.n3.nabble.com/How-to-add-custom-include-dir-to-the-header-search-path-tp4031389.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list