diff options
author | Brad King <brad.king@kitware.com> | 2013-03-12 15:47:49 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-03-12 15:52:52 (GMT) |
commit | 1df49282a5649c9ad9f8769cb552423ad74adbfb (patch) | |
tree | 549c4b0663b3e0c0600f7a8d54bd6dd373e3e457 /Source | |
parent | 51fc4fb3c1bd22f038b1d6b51e039296bbc258c3 (diff) | |
download | CMake-1df49282a5649c9ad9f8769cb552423ad74adbfb.zip CMake-1df49282a5649c9ad9f8769cb552423ad74adbfb.tar.gz CMake-1df49282a5649c9ad9f8769cb552423ad74adbfb.tar.bz2 |
add_subdirectory: Compute output dir with consistent slashes (#10072)
When the command is invoked without an explicit build directory path we
compute it from the source directory path. When either the source or
build tree is the root of a Windows drive letter it will have a trailing
slash. Handle slashes consistently when substituting the current output
directory for the current source directory.
While at it, use cmSystemTools::IsSubDirectory instead of FindLastString
to verify that the source directory is a subdirectory.
Inspired-by: Graham Menhennitt <graham@menhennitt.com.au>
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddSubDirectoryCommand.cxx | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Source/cmAddSubDirectoryCommand.cxx b/Source/cmAddSubDirectoryCommand.cxx index 9efeda4..5b1c9c6 100644 --- a/Source/cmAddSubDirectoryCommand.cxx +++ b/Source/cmAddSubDirectoryCommand.cxx @@ -78,7 +78,7 @@ bool cmAddSubDirectoryCommand::InitialPass // No binary directory was specified. If the source directory is // not a subdirectory of the current directory then it is an // error. - if(!cmSystemTools::FindLastString(srcPath.c_str(), + if(!cmSystemTools::IsSubDirectory(srcPath.c_str(), this->Makefile->GetCurrentDirectory())) { cmOStringStream e; @@ -93,10 +93,15 @@ bool cmAddSubDirectoryCommand::InitialPass // Remove the CurrentDirectory from the srcPath and replace it // with the CurrentOutputDirectory. - binPath = srcPath; - cmSystemTools::ReplaceString(binPath, - this->Makefile->GetCurrentDirectory(), - this->Makefile->GetCurrentOutputDirectory()); + const char* src = this->Makefile->GetCurrentDirectory(); + const char* bin = this->Makefile->GetCurrentOutputDirectory(); + size_t srcLen = strlen(src); + size_t binLen = strlen(bin); + if(srcLen > 0 && src[srcLen-1] == '/') + { --srcLen; } + if(binLen > 0 && bin[binLen-1] == '/') + { --binLen; } + binPath = std::string(bin, binLen) + srcPath.substr(srcLen); } else { |