diff options
author | Mateusz Janek <stryku2393@gmail.com> | 2017-05-15 20:01:10 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-05-17 13:04:02 (GMT) |
commit | 4716f2be83f140deec28fd7c6b945c6fd401a433 (patch) | |
tree | 70d978f1f7ce45dfc19270b902000c5ffb64939f /Source/cmSourceGroupCommand.cxx | |
parent | 8bd6af0d6386d1e0b26ff594b7d42621d67b5985 (diff) | |
download | CMake-4716f2be83f140deec28fd7c6b945c6fd401a433.zip CMake-4716f2be83f140deec28fd7c6b945c6fd401a433.tar.gz CMake-4716f2be83f140deec28fd7c6b945c6fd401a433.tar.bz2 |
source_group: Restore TREE support for relative paths
The fix in commit v3.8.1~4^2 (source_group: Fix TREE with root that is
not current source dir, 2017-04-20) accidentally broke support for
specifying paths relative to the source directory. Fix it and add a
test covering the case.
While at it, fix a typo in a variable name.
Fixes: #16876
Diffstat (limited to 'Source/cmSourceGroupCommand.cxx')
-rw-r--r-- | Source/cmSourceGroupCommand.cxx | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 23048bf..d722954 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -2,8 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSourceGroupCommand.h" -#include <algorithm> -#include <iterator> #include <set> #include <sstream> @@ -15,7 +13,7 @@ namespace { const size_t RootIndex = 1; const size_t FilesWithoutPrefixKeywordIndex = 2; const size_t FilesWithPrefixKeywordIndex = 4; -const size_t PrefixKeywordIdex = 2; +const size_t PrefixKeywordIndex = 2; std::vector<std::string> tokenizePath(const std::string& path) { @@ -79,17 +77,26 @@ cmSourceGroup* addSourceGroup(const std::vector<std::string>& tokenizedPath, return sg; } -std::string prepareFilePathForTree(const std::string& path) +std::string prepareFilePathForTree(const std::string& path, + const std::string& currentSourceDir) { + if (!cmSystemTools::FileIsFullPath(path)) { + return cmSystemTools::CollapseFullPath(currentSourceDir + "/" + path); + } return cmSystemTools::CollapseFullPath(path); } std::vector<std::string> prepareFilesPathsForTree( std::vector<std::string>::const_iterator begin, - std::vector<std::string>::const_iterator end) + std::vector<std::string>::const_iterator end, + const std::string& currentSourceDir) { - std::vector<std::string> prepared(std::distance(begin, end)); - std::transform(begin, end, prepared.begin(), prepareFilePathForTree); + std::vector<std::string> prepared; + + for (; begin != end; ++begin) { + prepared.push_back(prepareFilePathForTree(*begin, currentSourceDir)); + } + return prepared; } @@ -228,13 +235,13 @@ bool cmSourceGroupCommand::checkTreeArgumentsPreconditions( } if (args[FilesWithoutPrefixKeywordIndex] != "FILES" && - args[PrefixKeywordIdex] != "PREFIX") { + args[PrefixKeywordIndex] != "PREFIX") { errorMsg = "Unknown argument \"" + args[2] + "\". Perhaps the FILES keyword is missing.\n"; return false; } - if (args[PrefixKeywordIdex] == "PREFIX" && + if (args[PrefixKeywordIndex] == "PREFIX" && (args.size() < 5 || args[FilesWithPrefixKeywordIndex] != "FILES")) { errorMsg = "Missing FILES arguments."; return false; @@ -253,13 +260,14 @@ bool cmSourceGroupCommand::processTree(const std::vector<std::string>& args, const std::string root = cmSystemTools::CollapseFullPath(args[RootIndex]); std::string prefix; size_t filesBegin = FilesWithoutPrefixKeywordIndex + 1; - if (args[PrefixKeywordIdex] == "PREFIX") { - prefix = args[PrefixKeywordIdex + 1]; + if (args[PrefixKeywordIndex] == "PREFIX") { + prefix = args[PrefixKeywordIndex + 1]; filesBegin = FilesWithPrefixKeywordIndex + 1; } const std::vector<std::string> filesVector = - prepareFilesPathsForTree(args.begin() + filesBegin, args.end()); + prepareFilesPathsForTree(args.begin() + filesBegin, args.end(), + this->Makefile->GetCurrentSourceDirectory()); if (!rootIsPrefix(root, filesVector, errorMsg)) { return false; |