MantisBT - CMake
View Issue Details
0014491CMake(No Category)public2013-10-17 11:022016-06-10 14:21
ingolf 
 
normalmajoralways
closedfixed 
linux/i386 and x86_64ubuntu / openSUSEvarious
CMake 2.8.10.2 
CMake 3.6CMake 3.6 
0014491: file(GLOB) and file(GLOB_RECURSE) indeterministic
file(GLOB) and file(GLOB_RECURSE) have indeterministic behavior. Apparently, the ordering of the files which match the specified pattern depends on the sequence in which files are delivered by the file system.

While this might be on purpose, this should at least be clearly documented -- together with a proposal to use list(SORT) afterwards if a fixed ordering is desired.

Nevertheless, I would expect the cmake output to be reproducible when all the files involved in the project (including the cmake tool itself) as well as the user environment variables have the same content.
Create an empty project directory with the following contents (all files can be empty):
./f1.abx
./folder1/8764gh.abb
./folder1/q.ab0
./folder1/zzzzz.ab_
./folder2/.abz
./folder2/_bbbb_.abd
./folder2/bea7.96.abc
./folder2/xcx.abcd
./fsbi213.ab
./z.ab5

Then use the following CMakeLists.txt:
----8<----8<----8<----8<----8<----8<----8<----8<----
cmake_minimum_required(VERSION 2.8)

file(GLOB FILES_LOCAL RELATIVE ${CMAKE_SOURCE_DIR} *.ab?)
message(STATUS "Non-recursive: ${FILES_LOCAL}")

file(GLOB_RECURSE FILES_RECURSE RELATIVE ${CMAKE_SOURCE_DIR} *.ab?)
message(STATUS "Recursive: ${FILES_RECURSE}")
----8<----8<----8<----8<----8<----8<----8<----8<----

On the same machine (with the same user environment), CMake might output

> -- Non-recursive: z.ab5;f1.abx
> -- Recursive: z.ab5;folder1/8764gh.abb;folder1/q.ab0;folder1/zzzzz.ab_;f1.abx;folder2/.abz;folder2/bea7.96.abc;folder2/_bbbb_.abd

when run in one folder and

> -- Non-recursive: f1.abx;z.ab5
> -- Recursive: f1.abx;folder2/_bbbb_.abd;folder2/.abz;folder2/bea7.96.abc;folder1/zzzzz.ab_;folder1/q.ab0;folder1/8764gh.abb;z.ab5

when run in another folder.
No tags attached.
Issue History
2013-10-17 11:02ingolfNew Issue
2016-05-18 09:38Brad KingNote Added: 0041073
2016-05-18 09:38Brad KingStatusnew => resolved
2016-05-18 09:38Brad KingResolutionopen => fixed
2016-05-18 09:38Brad KingFixed in Version => CMake 3.6
2016-05-18 09:38Brad KingTarget Version => CMake 3.6
2016-06-10 14:21Kitware RobotNote Added: 0041168
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0041073)
Brad King   
2016-05-18 09:38   
Since CMake 3.4 the order has been documented as undefined:

 Help: Document that file(GLOB*) order is undefined
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5a208f83 [^]

Now after discussion here:

 [PATCH] cmFileCommand: sort list of files from glob command
 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/16397 [^]

we've made the order deterministic:

 file: Sort GLOB results to make it deterministic
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=edcccde7 [^]
(0041168)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.