MantisBT - CMake
View Issue Details
0015273CMakeCMakepublic2014-12-01 08:252016-06-10 14:31
Nils Gladitz 
Kitware Robot 
normalfeaturealways
closedmoved 
CMake 3.1 
 
0015273: file(GLOB/GLOB_RECURSE) should provide an option to set a start directory
Generated target export files for example use:

  get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
  file(GLOB CONFIG_FILES "${_DIR}/TdngTargets-*.cmake")

This is error prone in case _DIR itself happens to use special characters interpreted by globbing.

Something like:
  file(GLOB CONFIG_FILES START_DIRECTORY "${_DIR}" "TdngTargets-*.cmake")

would be nice.
No tags attached.
Issue History
2014-12-01 08:25Nils GladitzNew Issue
2014-12-01 11:12David ColeNote Added: 0037327
2014-12-01 11:22Nils GladitzNote Added: 0037330
2014-12-01 11:48David ColeNote Added: 0037331
2014-12-01 12:00Nils GladitzNote Added: 0037332
2014-12-01 12:10David ColeNote Added: 0037333
2014-12-01 12:11David ColeNote Added: 0037334
2014-12-01 12:22Nils GladitzNote Added: 0037335
2014-12-01 12:41David ColeNote Added: 0037336
2016-06-10 14:29Kitware RobotNote Added: 0042678
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0037327)
David Cole   
2014-12-01 11:12   
If somebody implements this, perhaps the new argument name should be WORKING_DIRECTORY ... similar to the add_test, add_custom_command and execute_process arguments that exist already.
(0037330)
Nils Gladitz   
2014-12-01 11:22   
I'd argue against WORKING_DIRECTORY since in this case the working directory (as in e.g. chdir()/getcwd()) does not change and there is no external process being run.
(0037331)
David Cole   
2014-12-01 11:48   
On this line:

http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/kwsys/Glob.cxx;h=5a96aed430e552c3932dcc620d25dde687b0ca47;hb=HEAD#l376 [^]

Glob::FindFiles uses GetCurrentWorkingDirectory as prefix for the globbing expression if the input to it is not already prefixed by a full path directory name.

It may be just an implementation detail, but the implementation is the thing that is limiting you to not being allowed to have globbing characters in the name of the directory. Since you'll need to change the implementation anyway, you may as well change the working directory for the scope of the call, restoring it to its original value on the way out, of course.
(0037332)
Nils Gladitz   
2014-12-01 12:00   
Hm yes, I saw the implementation and was thinking the kwsys interface should be extended to allow other starting directories but if it means not having to touch kwsys changing the working directory should work too.
(0037333)
David Cole   
2014-12-01 12:10   
I'm surprised this is even an issue since you cannot name directories with "?" or "*" characters in them on Windows.

I guess you're allowed to have those characters in directory names on other operating systems? (I would still advise against using them, but you must have encountered this in the wild for it to be an issue?)
(0037334)
David Cole   
2014-12-01 12:11   
And even if you do change the working directory, you will have to touch kwsys to fix this issue. That's where the problem lies...
(0037335)
Nils Gladitz   
2014-12-01 12:22   
I didn't step on this myself but I think [] might be (slightly) more common than ? * (and also valid on windows).

On Linux I can indeed have a directory named "*?[]".

I overlooked that kwsys actually makes the current working directory part of the expression :\

So yes either kwsys would have to be changed or perhaps cmake could use a full path but escape it before passing it through to kwsys.
(0037336)
David Cole   
2014-12-01 12:41   
I guess I'm guilty of thinking lowest common denominator here: only ? and * may be used in globbing expressions under Windows cmd.exe -- I don't know if [] even work on Windows here.

The table in the wikipedia article would imply [] are unsupported on Windows, at least directly in cmd.exe. Perhaps they do work in the Windows API calls that CMake uses.

http://en.wikipedia.org/wiki/Glob_%28programming%29 [^]

Either way, I think this issue is a valid idea for an improvement to CMake ... hopefully somebody has time to pick it up and work on it.
(0042678)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

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.