View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014491CMake(No Category)public2013-10-17 11:022016-06-10 14:21
Reporteringolf 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
Platformlinux/i386 and x86_64OSubuntu / openSUSEOS Versionvarious
Product VersionCMake 2.8.10.2 
Target VersionCMake 3.6Fixed in VersionCMake 3.6 
Summary0014491: file(GLOB) and file(GLOB_RECURSE) indeterministic
Descriptionfile(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.
Steps To ReproduceCreate 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.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0041073)
Brad King (manager)
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 (administrator)
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.

 Issue History
Date Modified Username Field Change
2013-10-17 11:02 ingolf New Issue
2016-05-18 09:38 Brad King Note Added: 0041073
2016-05-18 09:38 Brad King Status new => resolved
2016-05-18 09:38 Brad King Resolution open => fixed
2016-05-18 09:38 Brad King Fixed in Version => CMake 3.6
2016-05-18 09:38 Brad King Target Version => CMake 3.6
2016-06-10 14:21 Kitware Robot Note Added: 0041168
2016-06-10 14:21 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team