From ad3b5099263e5977d1de9bfcff715a92009e8355 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 6 Jan 2018 09:38:59 +0100 Subject: Add define.static, define.dynamic --- src/Conf.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 2 ++ 2 files changed, 65 insertions(+) (limited to 'src') 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; 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 &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; diff --git a/src/main.cpp b/src/main.cpp index c626f11..f4d022e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,6 +55,8 @@ using namespace std::chrono; // and should this force static compilation so dependencies can also be built with protection and if dependencies dont exist // as static library/source, then fail build? +// TODO: Add support for common package managers (in distros). If package with the dependency version exists in package manager, install and use it instead + #if OS_FAMILY == OS_FAMILY_POSIX #define ferr std::cerr #else -- cgit v1.2.3