[CMake] Getting Makefiles sensitive tonew/deleted files/directories?

Ken Martin ken.martin at kitware.com
Fri Mar 21 12:14:26 EDT 2008


> > Can you do the glob, configure the result out to a file, then INCLUDE
> that
> > file. I believe that will solve the problem. Something like
> >
> > file(GLOB SRC *.cpp)
> > configure_file(somefile.in somefile)
> > include(somefile)
> >
> > where somefile.in looks like
> >
> > # list of files as a comment -- ${SRC}
> >
> > This works because CMake does check (at make time) to see if any
> included
> > file in CMake has changed but is smart in that configure_file only
> writes
> > the file if it has changed. I'm pretty sure something like that will
> work.

Thinking about this some more I think you could add a custom target that
does the glob at build time, and stores the results in a file that gets
included by CMake. So what would happen is:

cmake --> files are globbed and used as well as written into a files.last

make  --> files are globbed and written into a files.last if different
(which at this point they are not)

joe schmo adds some new files into the tree

make -->  files are globbed and written into a files.last if different
(which they will be) the build will probably fail as the makefiles do not
have the new files

make --> detects that files.last is different and reruns cmake producing
valid makefiles with the new source files.


Not a great solution as the build can fail the first time new files are
added but ...meh...really the fix is to have Cmake handle this if it can be
handled without making other builds that do glob for other reasons not slow
down.

Ken



More information about the CMake mailing list