[CMake] file(GLOB …)

David Cole david.cole at kitware.com
Fri Dec 23 11:20:56 EST 2011


On Fri, Dec 23, 2011 at 10:45 AM, Rolf Eike Beer <eike at sf-mail.de> wrote:
> Daniel Dekkers wrote:
>> On 12/21/2011 05:25 PM, André Caron wrote:
>> Get rid of the file(GLOB ...). Never, ever use it unless you know
>> exactly what you're doing. Using it usually breaks something.
>>
>> On Dec 21, 2011, at 5:59 PM, David Cole wrote:
>> I agree with the advice to get rid of file(GLOB
>>
>> What's the alternative. Enumerate all your filenames by hand?
>
> Yes. This is no real problem as you need to do this only once. You can even
> use the current CMake code to MESSAGE() out whatever CMake currently finds
> using FILE(GLOB) and just copy that into your CMakeLists.txt
>
> Eike
> --
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


Just to clarify: the point of enumerating all your files in the
CMakeLists.txt file is so that when you add or remove a file, the
CMakeLists file changes, and can trigger a re-run of CMake based on
the usual "make' file dependency tracking.

If you don't do it, and you use glob instead, then CMake does not know
when you've added or removed files from the file system, and so cannot
re-run automatically when (and only when) necessary.

To use glob *and* get this sort of behavior, we'd have to institute
some sort of file-system-watcher that's always running. We don't
really want to get into the business of monitoring your disk for file
adds and removes...


:-)
David


More information about the CMake mailing list