return;
const SourcePackage &spkg = component->get_package();
- LibMode libmode = spkg.get_library_mode();
- if(dynamic_cast<SharedLibrary *>(this) && libmode<DYNAMIC)
- libmode = DYNAMIC;
+ BuildInfo::LibraryMode libmode = component->get_build_info().libmode;
+ if(dynamic_cast<SharedLibrary *>(this) && libmode<BuildInfo::DYNAMIC)
+ libmode = BuildInfo::DYNAMIC;
list<const Component *> queue;
list<Target *> dep_libs;
#include <algorithm>
#include <set>
+#include <msp/strings/format.h>
#include "buildinfo.h"
using namespace std;
BuildInfo::BuildInfo():
+ libmode(DYNAMIC),
threads(false),
debug(false),
optimize(0),
threads = bi.threads;
if(level==LOCAL)
{
+ libmode = bi.libmode;
debug = bi.debug;
optimize = bi.optimize;
strip = bi.strip;
add("incpath", &Loader::incpath);
add("libpath", &Loader::libpath);
add("library", &Loader::library);
+ add("libmode", &BuildInfo::libmode);
add("optimize", &BuildInfo::optimize);
add("strip", &BuildInfo::strip);
add("threads", &BuildInfo::threads);
{
obj.warnings.push_back(s);
}
+
+
+void operator>>(LexicalConverter &conv, BuildInfo::LibraryMode &libmode)
+{
+ if(conv.get()=="FORCE_STATIC")
+ libmode = BuildInfo::FORCE_STATIC;
+ else if(conv.get()=="STATIC")
+ libmode = BuildInfo::STATIC;
+ else if(conv.get()=="DYNAMIC")
+ libmode = BuildInfo::DYNAMIC;
+ else if(conv.get()=="FORCE_DYNAMIC")
+ libmode = BuildInfo::FORCE_DYNAMIC;
+ else
+ throw lexical_error(format("Conversion of '%s' to LibraryMode", conv.get()));
+}
class BuildInfo
{
public:
+ enum LibraryMode
+ {
+ FORCE_STATIC, //< Only accept static libraries
+ STATIC, //< Prefer static libraries but accept dynamic as well
+ DYNAMIC, //< Prefer dynamic libraries but accept static as well
+ FORCE_DYNAMIC //< Only accept dynamic libraries
+ };
+
class Loader: public Msp::DataFile::ObjectLoader<BuildInfo>
{
public:
PathList incpath;
PathList libpath;
WordList libs;
+ LibraryMode libmode;
WordList warnings;
bool threads;
bool debug;
for(BuildInfo::PathList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i)
*i = (pkg.get_source() / *i).str();
- if(pkg.get_library_mode()<DYNAMIC)
+ if(build_info.libmode<BuildInfo::DYNAMIC)
{
for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
{
argv.push_back("-o");
argv.push_back(relative(bin.get_path(), work_dir).str());
- bool static_link_ok = (comp.get_package().get_library_mode()<=STATIC);
+ bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC);
const Target::Dependencies &depends = target.get_depends();
for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
#include <string>
#include <msp/fs/path.h>
-enum LibMode
-{
- FORCE_STATIC,
- STATIC,
- DYNAMIC,
- FORCE_DYNAMIC
-};
-
typedef std::list<std::string> StringList;
typedef std::list<Msp::FS::Path> PathList;
typedef std::map<std::string, std::string> StringMap;
return source/arch.get_name()/detail;
}
-LibMode SourcePackage::get_library_mode() const
-{
- const string &mode = config.get_option("staticlibs").value;
- if(mode=="force")
- return FORCE_STATIC;
- else if(mode=="prefer")
- return STATIC;
- else if(mode=="avoid")
- return DYNAMIC;
- else if(mode=="reject")
- return FORCE_DYNAMIC;
- else
- throw runtime_error("unknown library mode");
-}
-
string SourcePackage::expand_string(const string &str) const
{
string result = str;
void SourcePackage::init_config()
{
config.add_option("tempdir", "temp", "Directory for storing temporary files");
- config.add_option("staticlibs", "local", "Use static libraries");
for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
config.add_option("with_"+i->name, i->def_value, i->descr);
const BuildInfo &get_build_info() const { return build_info; }
Builder &get_builder() const { return builder; }
- LibMode get_library_mode() const;
DependencyCache &get_deps_cache() const { return deps_cache; }
std::string expand_string(const std::string &) const;
private:
return 0;
}
-FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath &path, LibMode mode)
+FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath &path, BuildInfo::LibraryMode mode)
{
const Tool &linker = builder.get_toolchain().get_tool("LINK");
const Tool::SearchPath &syspath = linker.get_system_path();
const Architecture &arch = builder.get_current_arch();
list<string> shared_names;
- if(mode!=FORCE_STATIC)
+ if(mode!=BuildInfo::FORCE_STATIC)
{
const list<Pattern> &shared_patterns = arch.get_shared_library_patterns();
for(list<Pattern>::const_iterator i=shared_patterns.begin(); i!=shared_patterns.end(); ++i)
}
list<string> static_names;
- if(mode!=FORCE_DYNAMIC)
+ if(mode!=BuildInfo::FORCE_DYNAMIC)
{
const list<Pattern> &static_patterns = arch.get_static_library_patterns();
for(list<Pattern>::const_iterator i=static_patterns.begin(); i!=static_patterns.end(); ++i)
for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
{
- const list<string> *cur_names = (mode>=DYNAMIC ? &shared_names : &static_names);
+ const list<string> *cur_names = (mode>=BuildInfo::DYNAMIC ? &shared_names : &static_names);
for(list<string>::const_iterator j=cur_names->begin(); j!=cur_names->end(); )
{
FS::Path filename = *i / *j;
if(FileTarget *tgt = get_target(filename))
{
- if(cur_names!=&shared_names || mode==DYNAMIC || !tgt->get_package())
+ if(cur_names!=&shared_names || mode==BuildInfo::DYNAMIC)
{
builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, i->str(), tgt->get_type()));
return tgt;
if(++j==cur_names->end())
{
- if(mode==DYNAMIC && cur_names==&shared_names)
+ if(mode==BuildInfo::DYNAMIC && cur_names==&shared_names)
cur_names = &static_names;
- else if(mode==STATIC && cur_names==&static_names)
+ else if(mode==BuildInfo::STATIC && cur_names==&static_names)
cur_names = &shared_names;
else
break;
#include <list>
#include <map>
#include <msp/fs/path.h>
+#include "buildinfo.h"
class Builder;
class FileTarget;
used in linking with the library. If a file is found but no target is
associated with it, a new package-less target of appropriate type is
created. */
- FileTarget *find_library(const std::string &, const SearchPath &, LibMode);
+ FileTarget *find_library(const std::string &, const SearchPath &, BuildInfo::LibraryMode);
/** Locates a binary. The normal search path for binaries is used (usually
this means the PATH environment variable). If a file is found but no target