[CMake] How to generate preprocessed file?

Marcel Loose loose at astron.nl
Mon Mar 23 09:09:03 EDT 2009


Hi Denis,

I think you misunderstood what I mean with preprocessed file. I mean by
a preprocessed file a file that is generated by running the C/C++
pre-processor. Here are the values of CMAKE_C_CREATE_PREPROCESSED_SOURCE
and CMAKE_CXX_CREATE_PREPROCESSED_SOURCE that I get when running CMake:

CMAKE_C_CREATE_PREPROCESSED_SOURCE = <CMAKE_C_COMPILER> <DEFINES>
<FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>

CMAKE_CXX_CREATE_PREPROCESSED_SOURCE = <CMAKE_CXX_COMPILER> <DEFINES>
<FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>

To me, that clearly suggests that CMake has (some) built-in support for
generating preprocessed files. However, it's not clear to me what I must
put in my CMakeLists.txt file to actually let CMake generate a Unix
Makefile that contains a rule to generate preprocessed files.

I don't understand exactly what you mean by using
set_source_file_properties(), because the preprocessed file is not a
source, but a target. So, maybe I should use set_target_properties().
But then again, it's not clear to me how exactly I should do that.

Best regards,
Marcel Loose.

On Mon, 2009-03-23 at 04:28 -0700, Denis Scherbakov wrote:
> Marcel,
> 
> I am not sure what you need. If you want to convert config.h.in into 
> config.h, then see CONFIGURE_FILE and #cmakedefine.
> 
> For other files you may want to check ADD_CUSTOM_COMMAND and SET_SOURCE_FILES_PROPERTIES(${FILE} PROPERTIES GENERATED TRUE)
> 
> Denis
> 
> 
> > I was trying to figure out how to generate a preprocessed
> > file. By
> > browsing the CMake modules and by printing all CMake
> > variables I
> > discovered CMAKE_<LANG>_CREATE_PREPROCESSED_SOURCE
> > variables. That
> > suggests that there is support for generating preprocessed
> > files. 
> > 
> > However, there's no mention of these variables in the
> > documentation, or
> > the FAQ or the Wiki. How should I tell CMake to add rules
> > to my Unix
> > Makefiles for generating preprocessed (.i) files?
> 
> 
> 
>       



More information about the CMake mailing list