[CMake] How do I generate a preprocessed file?

Tyler Roscoe tyler at cryptio.net
Fri May 8 13:48:52 EDT 2009


On Thu, May 07, 2009 at 04:57:11PM +0200, Piotr Wyderski wrote:
> And specify a command to generate the file:
> 
> ADD_CUSTOM_COMMAND(
> 
>    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/inc.cpp
>    COMMAND YYY >inc.cpp
>    DEPENDS ${_runtime_header_list}
> )
> 
> but what shoud YYY be in order to achieve the following goal:
> 
> 1. all the entries from _runtime_header_list are enumerated
> and a single temporary file t1.cpp is created as follows:
> 
>    #include "entry_1"
>    #include "entry_2"
>    ...
>    #include "entry_n"
> 
> 2. t1 is sent to the C++ compiler (with all its options,
> definitions and include paths set as for a normal build),
> but for preprocessing stage only (i.e. g++ -E). The resulting
> C++ file is my inc.cpp.

I would probably use my favorite scripting language to generate the
file. You could probably use foreach() and file(WRITE ...) if you want a
pure CMake solution.

I don't know how to run the preprocessor by itself. If all you are
trying to do is write out a file containing the contents of entry_1 ...
entry_n, I wouldn't bother with the preprocessor; I would use a
scripting language or cat or file(READ ...) combined with file(WRITE
...).

hth,
tyler


More information about the CMake mailing list