aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index a543b43579..d2936c3b52 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -412,6 +412,7 @@ static int main0(int argc, char **argv) {
ZigList<const char *> framework_dirs = {0};
ZigList<const char *> frameworks = {0};
bool have_libc = false;
+ bool have_libcpp = false;
const char *target_string = nullptr;
bool rdynamic = false;
const char *linker_script = nullptr;
@@ -456,6 +457,9 @@ static int main0(int argc, char **argv) {
const char *override_soname = nullptr;
bool only_preprocess = false;
bool ensure_libc_on_non_freestanding = false;
+ bool ensure_libcpp_on_non_freestanding = false;
+ bool cpp_rtti = true;
+ bool cpp_exceptions = true;
ZigList<const char *> llvm_argv = {0};
llvm_argv.append("zig (LLVM option parsing)");
@@ -580,10 +584,11 @@ static int main0(int argc, char **argv) {
return (term.how == TerminationIdClean) ? term.code : -1;
} else if (argc >= 2 && strcmp(argv[1], "fmt") == 0) {
return stage2_fmt(argc, argv);
- } else if (argc >= 2 && strcmp(argv[1], "cc") == 0) {
+ } else if (argc >= 2 && (strcmp(argv[1], "cc") == 0 || strcmp(argv[1], "c++") == 0)) {
emit_h = false;
strip = true;
ensure_libc_on_non_freestanding = true;
+ ensure_libcpp_on_non_freestanding = (strcmp(argv[1], "c++") == 0);
bool c_arg = false;
Stage2ClangArgIterator it;
@@ -632,6 +637,8 @@ static int main0(int argc, char **argv) {
case Stage2ClangArgL: // -l
if (strcmp(it.only_arg, "c") == 0)
have_libc = true;
+ if (strcmp(it.only_arg, "c++") == 0)
+ have_libcpp = true;
link_libs.append(it.only_arg);
break;
case Stage2ClangArgIgnore:
@@ -648,6 +655,9 @@ static int main0(int argc, char **argv) {
case Stage2ClangArgNoStdLib:
ensure_libc_on_non_freestanding = false;
break;
+ case Stage2ClangArgNoStdLibCpp:
+ ensure_libcpp_on_non_freestanding = false;
+ break;
case Stage2ClangArgShared:
is_dynamic = true;
is_shared_lib = true;
@@ -712,6 +722,18 @@ static int main0(int argc, char **argv) {
verbose_cc = true;
verbose_link = true;
break;
+ case Stage2ClangArgExceptions:
+ cpp_exceptions = true;
+ break;
+ case Stage2ClangArgNoExceptions:
+ cpp_exceptions = false;
+ break;
+ case Stage2ClangArgRtti:
+ cpp_rtti = true;
+ break;
+ case Stage2ClangArgNoRtti:
+ cpp_rtti = false;
+ break;
}
}
// Parse linker args
@@ -916,6 +938,8 @@ static int main0(int argc, char **argv) {
const char *l = &arg[2];
if (strcmp(l, "c") == 0)
have_libc = true;
+ if (strcmp(l, "c++") == 0)
+ have_libcpp = true;
link_libs.append(l);
} else if (arg[1] == 'I' && arg[2] != 0) {
clang_argv.append("-I");
@@ -1057,6 +1081,8 @@ static int main0(int argc, char **argv) {
} else if (strcmp(arg, "--library") == 0 || strcmp(arg, "-l") == 0) {
if (strcmp(argv[i], "c") == 0)
have_libc = true;
+ if (strcmp(argv[i], "c++") == 0)
+ have_libcpp = true;
link_libs.append(argv[i]);
} else if (strcmp(arg, "--forbid-library") == 0) {
forbidden_link_libs.append(argv[i]);
@@ -1221,6 +1247,10 @@ static int main0(int argc, char **argv) {
have_libc = true;
link_libs.append("c");
}
+ if (!have_libcpp && ensure_libcpp_on_non_freestanding && target.os != OsFreestanding) {
+ have_libcpp = true;
+ link_libs.append("c++");
+ }
Buf zig_triple_buf = BUF_INIT;
target_triple_zig(&zig_triple_buf, &target);
@@ -1287,6 +1317,8 @@ static int main0(int argc, char **argv) {
LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i)));
link_lib->provided_explicitly = true;
}
+ g->cpp_rtti = cpp_rtti;
+ g->cpp_exceptions = cpp_exceptions;
g->subsystem = subsystem;
g->valgrind_support = valgrind_support;
g->want_pic = want_pic;
@@ -1433,6 +1465,8 @@ static int main0(int argc, char **argv) {
}
CodeGen *g = codegen_create(main_pkg_path, zig_root_source_file, &target, out_type, build_mode,
override_lib_dir, libc, cache_dir_buf, cmd == CmdTest, root_progress_node);
+ g->cpp_rtti = cpp_rtti;
+ g->cpp_exceptions = cpp_exceptions;
if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2);
g->valgrind_support = valgrind_support;
g->link_eh_frame_hdr = link_eh_frame_hdr;