version "0.1";
description "My awesome library";
-Packages may also depend on other packages:
+Packages may also require other packages:
require "otherlib";
automatically determined from the component type. Library components will also
install any headers which were used to build the library.
+Components can have requirements, just like packages. They can also use
+library components from the same package:
+
+ use "mylib_common";
+
+Libraries used in this way will always be linked in statically. This can be
+useful in organizing code when multiple components in a package share a common
+part.
+
Packages may want to offer optional features, for example to allow the user to
choose whether to use a particular external library:
else
results.push_back(linker.create_target(objs));
+ const Target::Dependencies &world_deps = builder.get_target("world")->get_dependencies();
+ for(UseList::const_iterator i=uses.begin(); i!=uses.end(); ++i)
+ {
+ /* The world target depends on all primary targets; look for the
+ static library belonging to the component. This is a bit roundabout
+ way but gets the job done. */
+ bool found = false;
+ for(Target::Dependencies::const_iterator j=world_deps.begin(); j!=world_deps.end(); ++j)
+ if((*j)->get_component()==*i && dynamic_cast<StaticLibrary *>(*j))
+ {
+ results.front()->add_dependency(**j);
+ found = true;
+ break;
+ }
+ if(!found)
+ builder.problem(package.get_name(), format("Can't find static library %s for component %s", (*i)->get_name(), name));
+ }
+
for(list<Target *>::const_iterator i=results.begin(); i!=results.end(); ++i)
{
builder.add_primary_target(**i);
add("build_info", &Loader::build_info);
add("require", &Loader::require);
add("default", &Component::deflt);
+ add("use", &Loader::use);
}
void Component::Loader::source(const string &s)
{
load_sub(obj.install_map, obj.package.get_source_directory());
}
+
+void Component::Loader::use(const string &n)
+{
+ const SourcePackage::ComponentList &components = obj.package.get_components();
+ for(SourcePackage::ComponentList::const_iterator i=components.begin(); i!=components.end(); ++i)
+ if(i->get_name()==n && i->get_type()==LIBRARY)
+ {
+ obj.uses.push_back(&*i);
+ return;
+ }
+ error(format("Unknown library component '%s'", n));
+}
void require(const std::string &);
void build_info();
void install_map();
+ void use(const std::string &);
};
enum Type
};
typedef std::list<Msp::FS::Path> SourceList;
+ typedef std::list<const Component *> UseList;
protected:
SourcePackage &package;
bool install;
BuildInfo build_info;
Package::Requirements requires;
+ UseList uses;
bool deflt;
InstallMap install_map;
bool get_install() const { return install; }
const InstallMap &get_install_map() const { return install_map; }
const Package::Requirements &get_required_packages() const { return requires; }
+ const UseList &get_used_components() const { return uses; }
bool is_default() const { return deflt; }
/** Prepares any required packages. */