From faba2972543b2a647dcb44f03a3643fe988d770f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 9 Jun 2019 12:32:05 +0200 Subject: Add for directories in config. Needed by some cmake projects --- include/Conf.hpp | 6 +++--- src/Conf.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/include/Conf.hpp b/include/Conf.hpp index eae79d4..03b2e46 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -418,6 +418,9 @@ namespace sibs std::string versionStr; PackageVersion version; Platform platform; + std::vector includeDirs; + std::vector exposeIncludeDirs; + std::vector ignoreDirs; protected: virtual void processObject(StringView name) override; virtual void processField(StringView name, const ConfigValue &value) override; @@ -444,10 +447,7 @@ namespace sibs PackageType packageType; std::vector packageListDependencies; std::vector gitDependencies; - std::vector includeDirs; - std::vector exposeIncludeDirs; std::vector platforms; - std::vector ignoreDirs; std::unordered_map defines; OptimizationLevel optimizationLevel; std::vector debugStaticLibs; diff --git a/src/Conf.cpp b/src/Conf.cpp index aade4f7..1962517 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -450,6 +450,17 @@ namespace sibs bool objectDefined; }; + static void replaceAll(std::string &input, const std::string &oldStr, const std::string &newStr) { + size_t index = 0; + while(true) { + index = input.find(oldStr, index); + if(index == std::string::npos) + break; + input.replace(index, oldStr.size(), newStr); + index += newStr.size(); + } + } + Result Config::readFromFile(const _tinydir_char_t *filepath, SibsConfig &config) { Result fileContentResult = getFileContent(filepath); @@ -515,6 +526,36 @@ namespace sibs return Result::Err("Packaging is only supported for projects that are of type executable"); } + std::string outDir = std::string("sibs-build/") + asString(config.platform) + "/"; + if(config.packaging) + { + outDir += "package"; + } + else + { + switch(config.getOptimizationLevel()) + { + case OPT_LEV_DEBUG: + outDir += "debug"; + break; + case OPT_LEV_RELEASE: + outDir += "release"; + break; + } + } + + for(std::string &includeDir : config.includeDirs) { + replaceAll(includeDir, "$out", outDir); + } + + for(std::string &exposeIncludeDir : config.exposeIncludeDirs) { + replaceAll(exposeIncludeDir, "$out", outDir); + } + + for(std::string &ignoreDir : config.ignoreDirs) { + replaceAll(ignoreDir, "$out", outDir); + } + return parseResult; } @@ -527,23 +568,25 @@ namespace sibs exit(6); } - buildPath = projectPath + TINYDIR_STRING("/sibs-build/") + toFileString(asString(sibsConfig.platform)) + TINYDIR_STRING("/"); + std::string outDir = std::string("sibs-build/") + asString(sibsConfig.platform) + "/"; if(sibsConfig.packaging) { - buildPath += TINYDIR_STRING("package"); + outDir += "package"; } else { switch(sibsConfig.getOptimizationLevel()) { case OPT_LEV_DEBUG: - buildPath += TINYDIR_STRING("debug"); + outDir += "debug"; break; case OPT_LEV_RELEASE: - buildPath += TINYDIR_STRING("release"); + outDir += "release"; break; } } + + buildPath = projectPath + TINYDIR_STRING("/") + toFileString(outDir); } const char* asString(OptimizationLevel optLevel) -- cgit v1.2.3