aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-01 09:40:08 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-01 09:41:07 +0100
commit1f6ee990275f412d4cc84483051fd549710da634 (patch)
tree9d41c91a67390d05329c590876da8656e4c0c4d8 /src
parent281ca4edaaa40d1cbffcde1e6f593133653397b8 (diff)
Add config parsing for cmake
cmake has not integrated yet, but it will parse... Add test script to easily run tests
Diffstat (limited to 'src')
-rw-r--r--src/Conf.cpp64
-rw-r--r--src/FileUtil.cpp12
2 files changed, 76 insertions, 0 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 27713d8..39a8c1d 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -456,6 +456,8 @@ namespace sibs
void SibsConfig::processObject(StringView name)
{
currentObject = name;
+ if(currentObject.equals("cmake") || currentObject.equals("cmake.static") || currentObject.equals("cmake.dynamic"))
+ useCmake = true;
//printf("Process object: %.*s\n", name.size, name.data);
}
@@ -730,6 +732,18 @@ namespace sibs
else
throw ParserException("Expected field under dependencies to be a single value, was a list");
}
+ else if(currentObject.equals("cmake"))
+ {
+ parseCmake(name, value, cmakeDirGlobal, cmakeArgsGlobal);
+ }
+ else if(currentObject.equals("cmake.static"))
+ {
+ parseCmake(name, value, cmakeDirStatic, cmakeArgsStatic);
+ }
+ else if(currentObject.equals("cmake.dynamic"))
+ {
+ parseCmake(name, value, cmakeDirDynamic, cmakeArgsDynamic);
+ }
else
{
string errMsg = "Invalid config object \"";
@@ -738,6 +752,56 @@ namespace sibs
throw ParserException(errMsg);
}
}
+
+ void SibsConfig::parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, string &cmakeDir, string &cmakeArgs)
+ {
+ if(fieldName.equals("dir"))
+ {
+ if(fieldValue.isSingle())
+ {
+ cmakeDir = projectPath;
+ cmakeDir += TINYDIR_STRING("/");
+ cmakeDir += toFileString(fieldValue.asSingle());
+ // No need to validate if CMakeLists.txt exists here, cmake will tell us if the file doesn't exist
+ }
+ else
+ {
+ string errMsg = "Expected ";
+ errMsg.append(currentObject.data, currentObject.size);
+ errMsg += ".";
+ errMsg.append(fieldName.data, fieldName.size);
+ errMsg += " to be a single value, was a list";
+ throw ParserException(errMsg);
+ }
+ }
+ else if(fieldName.equals("args"))
+ {
+ if(fieldValue.isList())
+ {
+ for(const StringView &arg : fieldValue.asList())
+ {
+ bool prependSpace = !cmakeArgs.empty();
+ cmakeArgs.reserve(cmakeArgs.size() + 4 + (prependSpace ? 1 : 0) + arg.size);
+ if(prependSpace)
+ cmakeArgs += " ";
+ cmakeArgs += "\"-D";
+ cmakeArgs.append(arg.data, arg.size);
+ cmakeArgs += "\"";
+ }
+ }
+ else
+ {
+ string errMsg = "Expected ";
+ errMsg.append(currentObject.data, currentObject.size);
+ errMsg += ".";
+ errMsg.append(fieldName.data, fieldName.size);
+ errMsg += " to be a list, was a single value";
+ throw ParserException(errMsg);
+ }
+ }
+ else
+ failInvalidFieldUnderObject(fieldName);
+ }
void SibsConfig::finished()
{
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp
index e53aa85..2626ee3 100644
--- a/src/FileUtil.cpp
+++ b/src/FileUtil.cpp
@@ -23,6 +23,11 @@ namespace sibs
{
return utf8Str;
}
+
+ FileString toFileString(const StringView &utf8Str)
+ {
+ return FileString(utf8Str.data, utf8Str.size);
+ }
#else
std::string toUtf8(const sibs::FileString &input)
{
@@ -57,6 +62,13 @@ namespace sibs
{
return utf8To16(utf8Str);
}
+
+ FileString toFileString(const StringView &utf8Str)
+ {
+ FileString result;
+ utf8::utf8to16(utf8Str.data, utf8Str.data + utf8Str.size, std::back_inserter(result));
+ return result;
+ }
FileString getLastErrorAsString()
{