[CMake] how to add capability to generate preprocessed and not-yet-compiled files ?

Brad King brad.king at kitware.com
Fri Jul 14 09:26:34 EDT 2006


Alexander Neundorf wrote:
> -------- Original-Nachricht --------
> Von: Brad King <brad.king at kitware.com>
> 
>> Alexander Neundorf wrote:
>>> Hi,
>>>
>>> it would be nice if it would be possible to have for each object file
>> also a target which only preprocesses the file and one which
>> preprocesses and compiles, but not assembles the file (so that you get
>> the assembler code).
>>> Is there a way to do this with macros ? 
>>> I almost think this would have to be done in cmake itself. Probably
>> somewhere where the object rules are created additionally for each object the
>> same rule but with "-E" instead of "-c" would have to be created. It
>> wouldn't be required to be executed on all, just on direct invocation:
>>> make foo.o/pre
>>> make foo.o/as
>>>
>>>
>>> What do you think about this ?
>>> Would you accept a patch ?
>> Look in Modules/CMakeCInformation.cmake for the variable 
>> CMAKE_C_COMPILE_OBJECT.  Other modules in the Platform directory set it 
>> also.  Just duplicate the variable with one called 
>> CMAKE_C_PREPROCESS_OBJECT and then setup 
>> cmLocalUnixMakefileGenerator3.cxx to create rules with ".E" extensions 
>> instead of ".o".  You should be able to locate places that lookup 
>> *_COMPILE_OBJECT vars.  See Modules/CMakeCXXInformation.cmake for the 
>> C++ version.
> 
> Ok, yesterday I had a look at it and managed to get the rules for preprocessed files produced.
> It ended up in cmMakefileTargetGenerator::WriteObjectBuildFile().
> Problem: the rule was created in builddir/CMakeFiles/target.dir/build.make, but not in builddir/Makefile, so I had to enter "make -f CMakeFiles/target.dir/build.make main.o.E".
> What do I have to do to have this rule also appear in the Makefile in the build dir ?

There are "convenience" targets written to the builddir/Makefile for
each object file in that directory with a rule to just invoke the
appropriate build.make copy of the rule.  You'll have to locate the code
that does this and add one for the .E files also.

-Brad


More information about the CMake mailing list