From 0bb8fff4d481f5076639d28b55daf76dd2b2ea0f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 7 Jan 2018 12:04:20 +0100 Subject: Add c/c++ language version option, compile c/cc files with c compiler --- src/Conf.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src') diff --git a/src/Conf.cpp b/src/Conf.cpp index f8b53e3..9f63833 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -792,6 +792,14 @@ namespace sibs { parseCmake(name, value, cmakeDirDynamic, cmakeArgsDynamic); } + else if(currentObject.equals("lang.c")) + { + parseCLang(name, value); + } + else if(currentObject.equals("lang.cpp")) + { + parseCppLang(name, value); + } else { string errMsg = "Invalid config object \""; @@ -801,6 +809,74 @@ namespace sibs } } + void SibsConfig::parseCLang(const StringView &fieldName, const ConfigValue &fieldValue) + { + if(fieldName.equals("version")) + { + // TODO: Support several versions (a list of versions where the latest possible version is used)? + if(fieldValue.isSingle()) + { + const StringView &cVersionStr = fieldValue.asSingle(); + if(cVersionStr.equals("c89") || cVersionStr.equals("ansi")) + { + cVersion = CVersion::C89; + } + else if(cVersionStr.equals("c99")) + { + cVersion = CVersion::C99; + } + else if(cVersionStr.equals("c11")) + { + cVersion = CVersion::C11; + } + else + { + string errMsg = "Expected lang.c.version to be c89, c99 or c11, was "; + errMsg += string(cVersionStr.data, cVersionStr.size); + throw ParserException(errMsg); + } + } + else + throw ParserException("Expected lang.c.version to be a single value, was a list"); + } + else + failInvalidFieldUnderObject(fieldName); + } + + void SibsConfig::parseCppLang(const StringView &fieldName, const ConfigValue &fieldValue) + { + if(fieldName.equals("version")) + { + // TODO: Support several versions (a list of versions where the latest possible version is used)? + if(fieldValue.isSingle()) + { + const StringView &cppVersionStr = fieldValue.asSingle(); + if(cppVersionStr.equals("c++11")) + { + cppVersion = CPPVersion::CPP11; + } + else if(cppVersionStr.equals("c++14")) + { + cppVersion = CPPVersion::CPP14; + } + else if(cppVersionStr.equals("c++17")) + { + cppVersion = CPPVersion::CPP17; + } + else + { + string errMsg = "Expected lang.cpp.version to be c89, c99 or c11, was "; + errMsg += string(cppVersionStr.data, cppVersionStr.size); + throw ParserException(errMsg); + } + } + else + throw ParserException("Expected lang.cpp.version to be a single value, was a list"); + } + else + failInvalidFieldUnderObject(fieldName); + } + void SibsConfig::parsePlatformConfigs(const StringView &fieldName, const ConfigValue &fieldValue) { for(int i = 0; i < NUM_CONFIGS; ++i) -- cgit v1.2.3