[CMake] How to make FILE() append to the list of files?

Alexander Neundorf a.neundorf-work at gmx.net
Thu Nov 27 15:31:55 EST 2008


On Thursday 27 November 2008, Eric Noulard wrote:
> 2008/11/27 Robert Dailey <rcdailey at gmail.com>:
> >> find . -name "*.c" > source_files.txt
> >> edit source_files.txt and put that list of files exiplicitly into a
> >> CMakeLists.txt file.
> >>
> >> file(GLOB is a bad way to get source lists for CMake.   CMake has no way
> >> of knowing when new files have been put in the directory.
> >
> > But unless I am missing a fundamental feature somewhere, GLOB still seems
> > to be the better alternative. While it may not intrinsically know when
> > new files have appeared on the filesystem, the programmer can simply
> > re-run the CMake command to get an updated project with the newly added
> > source files without editing the CMakeLists.txt file directly.
>
> Yes but when he add a source file, he won't necessarily remember he
> MUST rerun CMake manually
> so its next attempt to "build"  the project will trigger either a
> compile error (added header missing)
> or link error (added source file not compiled).
>
> Whereas with hard-written sources files in CMakeLists.txt, the user
> will get accustomed to
> "simple" CMakeList.txt editing thus CMake will relaunch itself
> automatically when needed and
> in particular when a CMakeLists.txt is changed.

Additionally it can happen from time to time that there are files in the 
directories which you just started to write, or forgot to delete, or somebody 
else sent you, or... and which you don't want to build, but which would be 
found by the glob.
So, yes, put the files you want to have explicitely in your cmake files.

Alex


More information about the CMake mailing list