From 1f6ee990275f412d4cc84483051fd549710da634 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 1 Jan 2018 09:40:08 +0100 Subject: Add config parsing for cmake cmake has not integrated yet, but it will parse... Add test script to easily run tests --- src/Conf.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/FileUtil.cpp | 12 +++++++++++ 2 files changed, 76 insertions(+) (limited to 'src') 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() { -- cgit v1.2.3