diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-03-28 07:15:16 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:58 +0200 |
commit | c6e8fe8125f8900f3019716aa1cfbf18ff8264bd (patch) | |
tree | 8eefe81c1cffe59cf6aeea75741f6f92c3edcb40 | |
parent | 615093ac7f3f647855b60b3a65352140bc44b378 (diff) |
Add support for absolute paths in include_dirs config
-rw-r--r-- | backend/ninja/Ninja.cpp | 13 | ||||
-rw-r--r-- | include/FileUtil.hpp | 1 | ||||
-rw-r--r-- | src/CmakeModule.cpp | 13 | ||||
-rw-r--r-- | src/FileUtil.cpp | 21 |
4 files changed, 42 insertions, 6 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 87370cf..99b276e 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -796,10 +796,17 @@ namespace backend #endif for(const auto &includeDir : config.getIncludeDirs()) { - string includeDirRelative = "../../../"; - includeDirRelative += includeDir; globalIncDir += " "; - globalIncDir += getIncludeOptionFlag(config.getCompiler(), includeDirRelative); + if(isPathAbsolute(includeDir)) + { + globalIncDir += getIncludeOptionFlag(config.getCompiler(), includeDir); + } + else + { + string includeDirRelative = "../../../"; + includeDirRelative += includeDir; + globalIncDir += getIncludeOptionFlag(config.getCompiler(), includeDirRelative); + } } auto parentGlobalIncludeDirCallback = globalIncludeDirCallback; diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp index b88d58a..0108b24 100644 --- a/include/FileUtil.hpp +++ b/include/FileUtil.hpp @@ -72,6 +72,7 @@ namespace sibs Result<FileString> getRealPath(const _tinydir_char_t *path); bool pathEquals(const std::string &path, const std::string &otherPath); Result<u64> getFileLastModifiedTime(const _tinydir_char_t *path); + bool isPathAbsolute(const std::string &path); } #endif //SIBS_FILEUTIL_HPP diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp index 8c97b6e..a690948 100644 --- a/src/CmakeModule.cpp +++ b/src/CmakeModule.cpp @@ -190,10 +190,17 @@ namespace sibs #endif for(const auto &includeDir : config.getIncludeDirs()) { - FileString includeDirRelative = FileString("../../../"); - includeDirRelative += toFileString(includeDir); cflags += TINYDIR_STRING(" "); - cflags += getIncludeOptionFlag(config.getCompiler(), includeDirRelative); + if(isPathAbsolute(includeDir)) + { + cflags += getIncludeOptionFlag(config.getCompiler(), toFileString(includeDir)); + } + else + { + FileString includeDirRelative = FileString("../../../"); + includeDirRelative += toFileString(includeDir); + cflags += getIncludeOptionFlag(config.getCompiler(), includeDirRelative); + } } cxxflags = cflags; diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index a03161f..1fd86d6 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -178,6 +178,27 @@ namespace sibs } #endif +#if OS_FAMILY == OS_FAMILY_POSIX + bool isPathAbsolute(const std::string &path) + { + return !path.empty() && path[0] == '/'; + } +#else + static bool isAlpha(char c) + { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); + } + + bool isPathAbsolute(const std::string &path) + { + if(path.size() >= 3 && isAlpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) + return true; + else if(path.size() >= 4 && memcmp(path.data(), "\\\\?\\", 4) == 0) + return true; + return false; + } +#endif + // TODO: Handle failure (directory doesn't exist, no permission etc) void walkDir(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc) { |