diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md index 2be5a6665..80f81e8ff 100755 --- a/docs/source/Compiler.md +++ b/docs/source/Compiler.md @@ -123,5 +123,7 @@ Additional options: - `--include-prefix PATH` : Prefix this path to any generated include statements. +- `--keep-prefix` : Keep original prefix of schema include statement. + NOTE: short-form options for generators are deprecated, use the long form whenever possible. diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 94de8364f..5ebe4c9f6 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -358,6 +358,7 @@ struct IDLOptions { bool union_value_namespacing; bool allow_non_utf8; std::string include_prefix; + bool keep_include_path; bool binary_schema_comments; bool skip_flatbuffers_import; std::string go_namespace; @@ -403,6 +404,7 @@ struct IDLOptions { cpp_object_api_pointer_type("std::unique_ptr"), union_value_namespacing(true), allow_non_utf8(false), + keep_include_path(false), binary_schema_comments(false), skip_flatbuffers_import(false), reexport_ts_modules(true), diff --git a/src/flatc.cpp b/src/flatc.cpp index 7e324eb14..d940d3ac1 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -103,6 +103,7 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const { " PATH \n" " --include-prefix Prefix this path to any generated include statements.\n" " PATH\n" + " --keep-prefix Keep original prefix of schema include statement.\n" " --no-fb-import Don't include flatbuffers import statement for TypeScript.\n" " --no-ts-reexport Don't re-export imported dependencies for TypeScript.\n" "FILEs may be schemas, or JSON files (conforming to preceding schema)\n" @@ -155,6 +156,8 @@ int FlatCompiler::Compile(int argc, const char** argv) { opts.include_prefix = argv[argi]; if (opts.include_prefix.back() != '/' && opts.include_prefix.back() != '\\') opts.include_prefix += "/"; + } else if(arg == "--keep-prefix") { + opts.keep_include_path = true; } else if(arg == "--strict-json") { opts.strict_json = true; } else if(arg == "--allow-non-utf8") { diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 2f97f83fd..3fe447ef4 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -72,8 +72,9 @@ class CppGenerator : public BaseGenerator { } for (auto it = parser_.included_files_.begin(); it != parser_.included_files_.end(); ++it) { - const auto basename = - flatbuffers::StripPath(flatbuffers::StripExtension(it->first)); + auto basename = flatbuffers::StripExtension(it->first); + if (!parser_.opts.keep_include_path) + basename = flatbuffers::StripPath(basename); if (basename != file_name_) { code_ += "#include \"" + parser_.opts.include_prefix + basename + "_generated.h\"";