[CMake] Run clean before automatically re-running cmake?
Matthew Woehlke
mw_triad at users.sourceforge.net
Wed Feb 12 11:53:38 EST 2014
On 2014-02-12 11:35, Abe Bachrach wrote:
> The Makefile that cmake generates includes a rule to automatically re-run
> cmake if any of the input CMakelists.txt files change.
>
> Currently, if you change the name of an executable target (or library), it
> will leave the old file in the output location, and then after re-running
> cmake, the Makefile will not have any record of it, so running make clean
> won't remove it.
>
> I would rather have the rule call make clean before re-running cmake so
> that such stray outputs are not left around.
>
> Is there any way to accomplish this?
What you really want is to record the "old" list of output files, re-run
CMake, then remove any files on that list that no longer have rules to
generate them. If you do a complete 'clean' you will delete and have to
rebuild more than is necessary (which might even be nothing e.g. if
CMake is being re-run because you added a debugging message).
While that's probably hard to impossible¹ with 'make', I mention it
because this feature (as described above) has at least been discussed
for ninja², which does have the ability to implement it. (I'm not sure
if it actually has been implemented or not, though.)
(¹ Use of recursive makefiles here doesn't help; probably each makefile
would have to implement this logic, and each parent would have to know
how to deal with directories that no longer exist in the build.)
(¹ http://martine.github.io/ninja/)
--
Matthew
More information about the CMake
mailing list