aboutsummaryrefslogtreecommitdiff
path: root/src/Conf.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-06 09:38:59 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-06 09:41:18 +0100
commitad3b5099263e5977d1de9bfcff715a92009e8355 (patch)
treefd49aca56de6253efc4c2720423a65142bc4c150 /src/Conf.cpp
parentea17671d7fe9ece8a33bdbc2f1d7bdf68bbccb69 (diff)
Add define.static, define.dynamic
Diffstat (limited to 'src/Conf.cpp')
-rw-r--r--src/Conf.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 75fdd02..f8b53e3 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -7,6 +7,8 @@ using u8string = utf8::unchecked::iterator<char*>;
namespace sibs
{
+ static const string EMPTY_STRING = "";
+
class UnexpectedTokenException : public std::runtime_error
{
public:
@@ -458,6 +460,14 @@ namespace sibs
{
return defines;
}
+
+ const string& SibsConfig::getDefinedValue(const string &name) const
+ {
+ auto it = defines.find(name);
+ if(it != defines.end())
+ return it->second;
+ return EMPTY_STRING;
+ }
void getLibFiles(const string &libPath, vector<string> &outputFiles)
{
@@ -723,6 +733,53 @@ namespace sibs
else
throw ParserException("Expected field under define to be a single value, was a list");
}
+ else if(currentObject.equals("define.static"))
+ {
+ // TODO: Do same for cmake args and other objects where you have static and dynamic.
+ // Makes it easier to handle config (no need for switch for different libraryTypes)
+ validatePackageTypeDefined();
+
+ if(value.isSingle())
+ {
+ if(packageType == PackageType::STATIC)
+ {
+ if(!isValidCIdentifier(name))
+ {
+ string errMsg = "Definition \"";
+ errMsg.append(name.data, name.size);
+ errMsg += "\" is not in a valid format. The first character have to match [a-zA-Z_] and the next characters have to match [a-zA-Z0-9_]";
+ throw ParserException(errMsg);
+ }
+ defines[string(name.data, name.size)] = string(value.asSingle().data, value.asSingle().size);
+ }
+ }
+ else
+ throw ParserException("Expected field under define.static to be a single value, was a list");
+ }
+ else if(currentObject.equals("define.dynamic"))
+ {
+ validatePackageTypeDefined();
+
+ if(value.isSingle())
+ {
+ // TODO: Remove `LIBRARY` from PackageType and if building a project where type is `library`,
+ // then convert it to dynamic. If a dependency has type `library`, then convert to dynamic
+ // unless build option includes to build dependencies as static libraries
+ if(packageType == PackageType::DYNAMIC || packageType == PackageType::LIBRARY)
+ {
+ if(!isValidCIdentifier(name))
+ {
+ string errMsg = "Definition \"";
+ errMsg.append(name.data, name.size);
+ errMsg += "\" is not in a valid format. The first character have to match [a-zA-Z_] and the next characters have to match [a-zA-Z0-9_]";
+ throw ParserException(errMsg);
+ }
+ defines[string(name.data, name.size)] = string(value.asSingle().data, value.asSingle().size);
+ }
+ }
+ else
+ throw ParserException("Expected field under define.dynamic to be a single value, was a list");
+ }
else if(currentObject.equals("cmake"))
{
parseCmake(name, value, cmakeDirGlobal, cmakeArgsGlobal);
@@ -947,6 +1004,12 @@ namespace sibs
throw ParserException(errMsg);
}
+ void SibsConfig::validatePackageTypeDefined() const
+ {
+ if((int)packageType == -1)
+ throw ParserException("package.type type has not been defined yet. Expected to be either 'executable', 'static', 'dynamic' or 'library'");
+ }
+
void SibsTestConfig::processObject(StringView name)
{
currentObject = name;