def CxxFlags(d_flags, r_flags): """ set the local compile option for cxx files, this influences the all of cxx files in target tag Args: d_flags : debug mode preprocess flags r_flags : release mode preprocess flags """ env = Environment.GetCurrent() tag = SyntaxTag.TagCxxFlags() if env.BuildMode() == "debug": tag.AddSV(d_flags) else: tag.AddSV(r_flags) return tag
def PROTO_LIBRARY(name, files, *args): """ compile proto files into a static library .a when parse proto files failed, raise Exception BrocProtoError Args: name: the name of proto static library files: a string sperearated by blank character, representing the relative path of proto files args: a variable number of SyntaxTag.TagProtoFlags, SyntaxTag.TagInclude, SyntaxTag.CppFlags, SyntaxTag.CXXFlags, SyntaxTag.TagLibs """ # check validity of name if not Function.CheckName(name): raise BrocArgumentIllegalError("name(%s) PROTO_LIBRARY is illegal" % name) # check proto file whether belongs to module proto_files = files.split() env = Environment.GetCurrent() for _file in proto_files: abs_path = os.path.normpath(os.path.join(env.BrocDir(), _file)) if not env.ModulePath() in abs_path: raise NotInSelfModuleError(abs_path, env.ModulePath()) # to check args tag_protoflags = SyntaxTag.TagProtoFlags() tag_cppflags = SyntaxTag.TagCppFlags() tag_cxxflags = SyntaxTag.TagCxxFlags() tag_libs = SyntaxTag.TagLibs() tag_include = SyntaxTag.TagInclude() for arg in args: if isinstance(arg, SyntaxTag.TagProtoFlags): tag_protoflags.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagCppFlags): tag_cppflags.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagCxxFlags): tag_cxxflags.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagLibs): tag_libs.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagInclude): tag_include.AddSVs(arg.V()) else: raise BrocArgumentIllegalError("don't support tag(%s) in PROTO_LIBRARY in %s" \ % (str(arg), env.BrocPath())) include = set() source = set() for f in proto_files: root, _ = os.path.splitext(f) result_file = os.path.join(os.path.join('broc_out', env.ModuleCVSPath()), \ "%s.pb.cc" % root) include.add(os.path.dirname(result_file)) if os.path.dirname(f): tag_include.AddV( os.path.join(env.ModuleCVSPath(), os.path.dirname(f))) source.add(result_file) protolib = Target.ProtoLibrary(env, files, tag_include, tag_protoflags) ret, msg = protolib.PreAction() if not ret: raise BrocProtoError(msg) tag_include.AddSVs(include) broc_out = os.path.join("broc_out", env.BrocCVSDir()) if broc_out not in tag_include.V(): tag_include.AddV(os.path.join("broc_out", env.BrocCVSDir())) tag_sources = Sources(" ".join(list(source)), tag_include, tag_cppflags, tag_cxxflags) if not env.AppendTarget( Target.StaticLibrary(name, env, tag_sources, tag_libs)): raise BrocArgumentIllegalError( "PROTO_LIBRARY(%s) name exists already" % name) return protolib