Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --frameworks, --sys-frameworks options #85

Open
wants to merge 3 commits into
base: llvm-11.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/c2ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions src/include/c2ffi/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/include/c2ffi/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace c2ffi {

IncludeVector includes;
IncludeVector sys_includes;
IncludeVector frameworks;
IncludeVector sys_frameworks;
OutputDriver *od;

std::ostream *output;
Expand Down
14 changes: 9 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -292,6 +303,8 @@ void usage(void) {
"Options:\n"
" -I, --include Add a \"LOCAL\" include path\n"
" -i, --sys-include Add a <system> 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"
Expand Down