[CMake] C/C++ dependency scanner
Bill Hoffman
bill.hoffman at kitware.com
Thu Mar 18 21:49:49 EDT 2010
Steven Wilson wrote:
> Hey all,
>
> I have a large project whose source files start as files with an
> alternate extension (.bc). Those files are mostly generic C files that
> have some C++ like features that are preprocessed into vanilla C files
> using a custom C pre-processor. My project uses an
> add_custom_command() call to put the file through the necessary steps to
> go from .bc to a .c file. By the time it becomes a .c file, the C
> preprocessor(and the custom preprocessor) has already run and all the
> header files, etc have been put into the .c file. I need a way to
> generate a list of dependencies (ie header files) for the original .bc
> file so that my add_custom_command() call can use those file names in
> the DEPEND section so that the .c file gets regenerated correctly when
> any of the dependencies change.
>
> I know different techniques for getting this information into CMake once
> the list is compiled for any give source file, but I'm not sure how to
> generate the list. Can CMake's C dependency scanner be invoked (using
> cmake -E cmake_depends) to create this kind of list. The .bc files are
> generic C (from a preprocessor scanning point of view) so CMake's
> dependency scanner should be able to produce this information. If
> cmake -E cmake_depends cannot function for this task, does anyone know
> of another tool that could be forced into service for this type of
> functionality?
>
I have a hack of an idea that might work....
If you could changed your bc -> c generator to put in the #include lines
, but with if blockers around it:
#if FOOL_CMAKE_DEPEND_SCANNER
#include "foo.h"
#include "bar.h"
#endif
Since CMake ignores #if directives will depend on foo and bar, but the c
compiler will not expand them.
-Bill
More information about the CMake
mailing list