[CMake] Automatically listing source files with GLOB (Re: How to make FILE() append to the list of files?)

David Cole david.cole at kitware.com
Mon Dec 1 13:18:30 EST 2008


The root problem here is one of expense. It is an expensive question to ask
"has a single file been added or removed from this directory tree of
thousands of source code files..." So we never ask that question. (Doing two
file(GLOB's and comparing the results to say "has there been a change"? is
more expensive than just doing it once and assuming there has been a
change...)
In the end, the developer always has to be trained about how to add a source
file to a project.

If you and all of your developers *always* work like this (#1):
- make any changes you like
- run cmake
- run make (or build with an IDE)
...then the file(GLOB technique is feasible because your developers always
run cmake before building.

If instead you work like this (#2):
- make any changes you like
- run make (or build with an IDE)
...then the file(GLOB technique does not work when you have added a source
file. But the explicit listing of those files in CMakeLists.txt still
works...

The developers need to know that if they add source files then cmake has to
be re-run. *Unless* you explicitly list the sources in CMakeLists -- then
cmake automatically reruns because the CMakeLists has changed...

Explicit listing of sources in CMakeLists.txt always works. file(GLOB only
works sometimes depending on dev workflow preference.

That's why we always recommend explicitly listing sources.

Ignore our advice if you wish, but file(GLOB will always be an unreliable
technique unless you have a magic way of enforcing workflow #1.


HTH,
David



On Mon, Dec 1, 2008 at 12:56 PM, Bart Janssens <bart.janssens at lid.kviv.be>wrote:

> On Mon, Dec 1, 2008 at 4:50 PM,  <David.Karr at l-3com.com> wrote:
> >>Yes but when he add a source file, he won't necessarily remember he
> >>MUST rerun CMake manually [...]
> >>
> >>Whereas with hard-written sources files in CMakeLists.txt, the user
> >>will get accustomed to "simple" CMakeList.txt editing [...]
> >>
> >>[...]
>
> > Actually, when I was last faced with this task I decided the easier
> > alternative for me was to cut and paste a lot of boring directory
> > listings into my CMakeLists.txt files.  (This was in a much earlier
> > version of CMake, and IIRC there was some problem with file globbing
> > back then that was fixed soon afterward.)
>
> Just thinking out loud here, but would it be possible for the trigger
> that determines whether CMake should be rerun or not to check if any
> files were added/removed? That would make the globbing method as
> convenient as the manual editing.
>
> Cheers,
>
> --
> Bart Janssens
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081201/3db6019c/attachment.htm>


More information about the CMake mailing list