]> git.tdb.fi Git - builder.git/blobdiff - source/sourcepackage.cpp
Support conditionals inside components
[builder.git] / source / sourcepackage.cpp
index 9d8a5656935ac02a30581e715455c6bdfb5a5486..cb4f978aedba7c6e61c5fb4f8719e67e05f0123f 100644 (file)
@@ -67,6 +67,27 @@ FS::Path SourcePackage::get_out_dir() const
                return source_dir/arch.get_name();
 }
 
+bool SourcePackage::match_feature(const string &cond) const
+{
+       string::size_type equals = cond.find('=');
+       if(equals!=string::npos)
+       {
+               if(equals==0)
+                       throw invalid_argument("SourcePackage::match_feature");
+               bool negate = cond[equals-1]=='!';
+               string feat = cond.substr(0, equals-negate);
+               string value = config.get_option("with_"+feat).value;
+               return (value==cond.substr(equals+1))!=negate;
+       }
+       else
+       {
+               bool negate = (cond[0]=='!');
+               string feat = cond.substr(negate);
+               string value = config.get_option("with_"+feat).value;
+               return lexical_cast<bool>(value)!=negate;
+       }
+}
+
 void SourcePackage::do_prepare()
 {
        BuildInfo final_build_info;
@@ -116,7 +137,7 @@ void SourcePackage::do_prepare()
        if(pc_needed)
        {
                PkgConfigFile *pc = new PkgConfigFile(builder, *this);
-               builder.get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc));
+               builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc));
        }
 }
 
@@ -231,25 +252,7 @@ void SourcePackage::Loader::headers(const string &n)
 
 void SourcePackage::Loader::if_feature(const string &cond)
 {
-       bool match = false;
-       string::size_type equals = cond.find('=');
-       if(equals!=string::npos)
-       {
-               if(equals==0)
-                       throw invalid_argument("SourcePackage::Loader::if_feature");
-               bool negate = cond[equals-1]=='!';
-               string name = cond.substr(0, equals-negate);
-               string value = obj.config.get_option("with_"+name).value;
-               match = (value==cond.substr(equals+1))!=negate;
-               value = cond.substr(equals+1);
-       }
-       else
-       {
-               bool negate = (cond[0]=='!');
-               string name = cond.substr(negate);
-               string value = obj.config.get_option("with_"+name).value;
-               match = lexical_cast<bool>(value)!=negate;
-       }
+       bool match = obj.match_feature(cond);
        obj.builder.get_logger().log("configure", format("%s: feature %s %smatched", obj.name, cond, (match ? "" : "not ")));
        if(match)
                load_sub_with(*this);