diff --git a/src/c2ffi.cpp b/src/c2ffi.cpp index 644bfc2..efb60b6 100644 --- a/src/c2ffi.cpp +++ b/src/c2ffi.cpp @@ -67,6 +67,8 @@ int main(int argc, char *argv[]) { add_includes(ci, sys.includes, false, true); add_includes(ci, sys.sys_includes, true, true); + add_includes(ci, sys.frameworks, false, true, true); + add_includes(ci, sys.sys_frameworks, true, true, true); C2FFIASTConsumer *astc = NULL; diff --git a/src/include/c2ffi/init.h b/src/include/c2ffi/init.h index 055c3fd..96be41b 100644 --- a/src/include/c2ffi/init.h +++ b/src/include/c2ffi/init.h @@ -27,10 +27,11 @@ namespace c2ffi { void add_include(clang::CompilerInstance &ci, const char *path, - bool isAngled = false, bool show_error = false); + bool isAngled = false, bool show_error = false, + bool is_framework = false); void add_includes(clang::CompilerInstance &ci, c2ffi::IncludeVector &v, bool is_angled = false, - bool show_error = false); + bool show_error = false, bool is_framework = false); void init_ci(config &c, clang::CompilerInstance &ci); } diff --git a/src/include/c2ffi/opt.h b/src/include/c2ffi/opt.h index 885068e..8f162f5 100644 --- a/src/include/c2ffi/opt.h +++ b/src/include/c2ffi/opt.h @@ -46,6 +46,8 @@ namespace c2ffi { IncludeVector includes; IncludeVector sys_includes; + IncludeVector frameworks; + IncludeVector sys_frameworks; OutputDriver *od; std::ostream *output; diff --git a/src/init.cpp b/src/init.cpp index 19655c3..920d2e6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -49,12 +49,16 @@ using namespace c2ffi; void c2ffi::add_include(clang::CompilerInstance &ci, const char *path, bool is_angled, - bool show_error) { + bool show_error, bool is_framework) { struct stat buf{}; if(stat(path, &buf) < 0 || !S_ISDIR(buf.st_mode)) { if(show_error) { std::cerr << "Error: Not a directory: "; - if(is_angled) + if(is_framework && is_angled) + std::cerr << "--sys-frameworks "; + else if(is_framework) + std::cerr << "--frameworks "; + else if(is_angled) std::cerr << "-i "; else std::cerr << "-I "; @@ -68,7 +72,7 @@ void c2ffi::add_include(clang::CompilerInstance &ci, const char *path, bool is_a auto &fm = ci.getFileManager(); if (auto dirent = fm.getDirectoryRef(path); dirent) { - clang::DirectoryLookup lookup(*dirent, clang::SrcMgr::C_System, false); + clang::DirectoryLookup lookup(*dirent, clang::SrcMgr::C_System, is_framework); ci.getPreprocessor().getHeaderSearchInfo() .AddSearchPath(lookup, is_angled); @@ -77,9 +81,9 @@ void c2ffi::add_include(clang::CompilerInstance &ci, const char *path, bool is_a void c2ffi::add_includes(clang::CompilerInstance &ci, c2ffi::IncludeVector &includeVector, bool is_angled, - bool show_error) { + bool show_error, bool is_framework) { for(auto &&include : includeVector) - add_include(ci, include.c_str(), is_angled, show_error); + add_include(ci, include.c_str(), is_angled, show_error, is_framework); } void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) { diff --git a/src/options.cpp b/src/options.cpp index 67eb4a2..db926e5 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -39,13 +39,16 @@ enum { NOSTDINC = CHAR_MAX+5, WCHAR_SIZE = CHAR_MAX+6, ERROR_LIMIT = CHAR_MAX+7, - + FRAMEWORKS = CHAR_MAX+8, + SYS_FRAMEWORKS = CHAR_MAX+9, OPTION_MAX }; static struct option options[] = { { "include", required_argument, 0, 'I' }, { "sys-include", required_argument, 0, 'i' }, + { "frameworks", required_argument, 0, FRAMEWORKS }, + { "sys-frameworks", required_argument, 0, SYS_FRAMEWORKS }, { "driver", required_argument, 0, 'D' }, { "help", no_argument, 0, 'h' }, { "macro-file", required_argument, 0, 'M' }, @@ -149,6 +152,14 @@ void c2ffi::process_args(config &config, int argc, char *argv[]) { config.sys_includes.push_back(optarg); break; + case FRAMEWORKS: + config.frameworks.push_back(optarg); + break; + + case SYS_FRAMEWORKS: + config.sys_frameworks.push_back(optarg); + break; + case 'D': if(config.od) { std::cerr << "Error: you may only specify one output driver" @@ -292,6 +303,8 @@ void usage(void) { "Options:\n" " -I, --include Add a \"LOCAL\" include path\n" " -i, --sys-include Add a include path\n" + " --frameworks Add a framework directory to the include path\n" + " --sys-frameworks Add a system framework directory to the include path\n" " --nostdinc Disable standard include path\n" " -D, --driver Specify an output driver (default: " << OutputDrivers[0].name << ")\n"