Add support for -I command-line argument to specify #include search directories.

This commit is contained in:
Matt Pharr
2012-02-07 08:39:01 -08:00
parent 5b4673e8eb
commit bb8e13e3c9
3 changed files with 28 additions and 0 deletions

4
ispc.h
View File

@@ -423,6 +423,10 @@ struct Globals {
/** Arguments to pass along to the C pre-processor, if it is run on the
program before compilation. */
std::vector<std::string> cppArgs;
/** Additional user-provided directories to search when processing
#include directives in the preprocessor. */
std::vector<std::string> includePath;
};
enum {

View File

@@ -103,6 +103,7 @@ usage(int ret) {
printf(" [--help]\t\t\t\tPrint help\n");
printf(" [--help-dev]\t\t\tPrint help for developer options\n");
printf(" [-h <name>/--header-outfile=<name>]\tOutput filename for header\n");
printf(" [-I <path>]\t\t\t\tAdd <path> to #include file search path\n");
printf(" [--instrument]\t\t\tEmit instrumentation to gather performance data\n");
printf(" [--math-lib=<option>]\t\tSelect math library\n");
printf(" default\t\t\t\tUse ispc's built-in math functions\n");
@@ -287,6 +288,15 @@ int main(int Argc, char *Argv[]) {
ot = Module::Bitcode;
else if (!strcmp(argv[i], "--emit-obj"))
ot = Module::Object;
else if (!strcmp(argv[i], "-I")) {
if (++i == argc) {
fprintf(stderr, "No path specified after -I option.\n");
usage(1);
}
g->includePath.push_back(argv[i]);
}
else if (!strncmp(argv[i], "-I", 2))
g->includePath.push_back(argv[i]+2);
else if (!strcmp(argv[i], "--fuzz-test"))
g->enableFuzzTest = true;
else if (!strncmp(argv[i], "--fuzz-seed=", 12))

View File

@@ -1175,6 +1175,20 @@ Module::execPreprocessor(const char* infilename, llvm::raw_string_ostream* ostre
// track the source file position by handling them ourselves.
inst.getPreprocessorOutputOpts().ShowComments = 1;
clang::HeaderSearchOptions &headerOpts = inst.getHeaderSearchOpts();
headerOpts.UseBuiltinIncludes = 0;
#ifndef LLVM_2_9
headerOpts.UseStandardSystemIncludes = 0;
#endif // !LLVM_2_9
headerOpts.UseStandardCXXIncludes = 0;
if (g->debugPrint)
headerOpts.Verbose = 1;
for (int i = 0; i < (int)g->includePath.size(); ++i)
headerOpts.AddPath(g->includePath[i], clang::frontend::Angled,
true /* is user supplied */,
false /* not a framework */,
true /* ignore sys root */);
clang::PreprocessorOptions &opts = inst.getPreprocessorOpts();
// Add defs for ISPC and PI