def get_cpp_info(name): cppinfo = CppInfo("{}/1.0".format(name), "/tmp/root") cppinfo.includedirs = [] cppinfo.includedirs.append("path/includes/{}".format(name)) cppinfo.includedirs.append("other\\include\\path\\{}".format(name)) # To test some path in win, to be used with MinGW make or MSYS etc cppinfo.libdirs = [] cppinfo.libdirs.append("one\\lib\\path\\{}".format(name)) cppinfo.libs = [] cppinfo.libs.append("{}_onelib".format(name)) cppinfo.libs.append("{}_twolib".format(name)) cppinfo.defines = [] cppinfo.defines.append("{}_onedefinition".format(name)) cppinfo.defines.append("{}_twodefinition".format(name)) cppinfo.cflags = ["{}_a_c_flag".format(name)] cppinfo.cxxflags = ["{}_a_cxx_flag".format(name)] cppinfo.sharedlinkflags = ["{}_shared_link_flag".format(name)] cppinfo.exelinkflags = ["{}_exe_link_flag".format(name)] cppinfo.sysroot = "/path/to/folder/{}".format(name) cppinfo.frameworks = [] cppinfo.frameworks.append("{}_oneframework".format(name)) cppinfo.frameworks.append("{}_twoframework".format(name)) cppinfo.system_libs = [] cppinfo.system_libs.append("{}_onesystemlib".format(name)) cppinfo.system_libs.append("{}_twosystemlib".format(name)) cppinfo.frameworkdirs = [] cppinfo.frameworkdirs.append("one/framework/path/{}".format(name)) return cppinfo
def _loads_cpp_info(text, filter_empty): pattern = re.compile(r"^\[([a-zA-Z0-9._:-]+)\]([^\[]+)", re.MULTILINE) try: # Parse the text data = OrderedDict() for m in pattern.finditer(text): var_name = m.group(1) lines = [] for line in m.group(2).splitlines(): line = line.strip() if not line or line[0] == "#": continue lines.append(line) if not lines: continue tokens = var_name.split(":") if len(tokens) == 2: # has config var_name, config = tokens else: config = None if 'system_libs' in var_name: tokens = var_name.split("system_libs_", 1) field = 'system_libs' else: tokens = var_name.split("_", 1) field = tokens[0] dep = tokens[1] if len(tokens) == 2 else None if field == "cppflags": field = "cxxflags" data.setdefault(dep, defaultdict(dict)) data[dep][config][field] = lines # Build the data structures def _relativize_path(p, _rootpath): try: return os.path.relpath(p, _rootpath) except ValueError: return p def _populate_cpp_info(_cpp_info, _data, _rootpath): for key, v in _data.items(): if key.endswith('dirs'): v = [_relativize_path(it, _rootpath) for it in v] v = ['' if it == '.' else it for it in v] setattr(_cpp_info, key, v) if None in data: del data[None] deps_cpp_info = DepsCppInfo() for dep, configs_cpp_info in data.items(): # Data for the 'cpp_info' object (no configs) no_config_data = configs_cpp_info.pop(None) rootpath = no_config_data.pop('rootpath')[0] dep_cpp_info = CppInfo(dep, rootpath) dep_cpp_info.filter_empty = filter_empty _ = no_config_data.pop('name')[0] version = no_config_data.pop('version', [""])[0] dep_cpp_info.version = version generatornames = no_config_data.pop("generatornames", []) # can be empty for n in generatornames: gen, value = n.split("=", 1) dep_cpp_info.names[gen] = value generatorfilenames = no_config_data.pop( "generatorfilenames", []) # can be empty for n in generatorfilenames: gen, value = n.split("=", 1) dep_cpp_info.filenames[gen] = value dep_cpp_info.sysroot = no_config_data.pop('sysroot', [""])[0] _populate_cpp_info(dep_cpp_info, no_config_data, rootpath) # Now the configs for config, config_data in configs_cpp_info.items(): cpp_info_config = getattr(dep_cpp_info, config) _populate_cpp_info(cpp_info_config, config_data, rootpath) # Add to the dependecy list deps_cpp_info.add(dep, DepCppInfo(dep_cpp_info)) return deps_cpp_info except Exception as e: logger.error(traceback.format_exc()) raise ConanException( "There was an error parsing conanbuildinfo.txt: %s" % str(e))