summaryrefslogtreecommitdiff
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2016-05-14 12:30:36 +0200
committerBrad King <brad.king@kitware.com>2016-05-17 10:12:11 -0400
commitedcccde7d65944b3744c4567bd1d452211829702 (patch)
treeee784327c065d207b0fa24e7cf32078a6c82e68c /Source/cmFileCommand.cxx
parentd9fd2f5402eeaa345691313658e02b51038f570b (diff)
downloadcmake-edcccde7d65944b3744c4567bd1d452211829702.tar.gz
file: Sort GLOB results to make it deterministic (#14491)
Even though the `file(GLOB)` documentation specifically warns against using it to collect a list of source files, projects often do it anyway. Since it uses `readdir()`, the list of files will be unsorted. This list is often passed directly to add_executable / add_library. Linking binaries with an unsorted list will make it unreproducible, which means that the produced binary will differ depending on the unpredictable `readdir()` order. To solve those reproducibility issues in a lot of programs (which don't explicitly `list(SORT)` the list manually), sort the resulting list of the `file(GLOB)` command. A more detailed rationale about reproducible builds is available [here](https://reproducible-builds.org/).
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx1
1 files changed, 1 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 5363a992f0..4e72f36138 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -823,6 +823,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
std::vector<std::string>::size_type cc;
std::vector<std::string>& files = g.GetFiles();
+ std::sort(files.begin(), files.end());
for (cc = 0; cc < files.size(); cc++) {
if (!first) {
output += ";";