file(GLOB ...) is often used to find source files. As 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 explicitely sort the list manually), this change sorts the resulting list of the file GLOB command. A more detailed rationale about reproducible builds is available at: https://reproducible-builds.org/ --- Help/command/file.rst | 3 +-- Source/cmFileCommand.cxx | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Help/command/file.rst b/Help/command/file.rst index 96ac6c7..a502134 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -103,8 +103,7 @@ Generate a list of files that match the ``<globbing-expressions>`` and store it into the ``<variable>``. Globbing expressions are similar to regular expressions, but much simpler. If ``RELATIVE`` flag is specified, the results will be returned as relative paths to the given -path. No specific order of results is defined. If order is important then -sort the list explicitly (e.g. using the :command:`list(SORT)` command). +path. The file list will be sorted. By default ``GLOB`` lists directories - directories are omited in result if ``LIST_DIRECTORIES`` is set to false. diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 6b6b913..4efa550 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1026,6 +1026,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 ) -- 2.8.1 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers