From b688d4fd22850c287f191f142660781ded72e919 Mon Sep 17 00:00:00 2001 From: Shane Parris Date: Mon, 5 Mar 2018 14:31:16 -0500 Subject: [PATCH] file(GLOB): Ensure entire file list is sorted --- Source/cmFileCommand.cxx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index b5215a55ba..90b943b87c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -757,8 +757,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector const& args, } } - std::ostringstream outputStream; - bool first = true; + std::vector files; bool warnFollowedSymlinks = false; while (i != args.end()) { if (*i == "LIST_DIRECTORIES") { @@ -848,15 +847,8 @@ bool cmFileCommand::HandleGlobCommand(std::vector const& args, warnFollowedSymlinks = true; } - std::vector& files = g.GetFiles(); - std::sort(files.begin(), files.end()); - for (std::string const& file : files) { - if (!first) { - outputStream << ";"; - } - outputStream << file; - first = false; - } + std::vector& foundFiles = g.GetFiles(); + files.insert(files.end(), foundFiles.begin(), foundFiles.end()); ++i; } } @@ -880,7 +872,10 @@ bool cmFileCommand::HandleGlobCommand(std::vector const& args, } break; } - this->Makefile->AddDefinition(variable, outputStream.str().c_str()); + + std::sort(files.begin(), files.end()); + files.erase(std::unique(files.begin(), files.end()), files.end()); + this->Makefile->AddDefinition(variable, cmJoin(files, ";").c_str()); return true; }