[CMake] Using m4 as a additional preprocessor for C/C++

Denis Scherbakov denis_scherbakov at yahoo.com
Fri Jun 5 11:08:21 EDT 2009



> 'm4' outputs only on stdout and does not have an option to
> specify the
> output file. Please
> suggest me a solution for this...

I had a similar problem and also with a preprocessor. I ended up writing
a CMake script like this:

EXECUTE_PROCESS(
  COMMAND my-command "${VAR_IFILE}"
  RESULT_VARIABLE  VAR_RESULT
  OUTPUT_VARIABLE  VAR_CONTENT)
# Do whatever you want with ${VAR_CONTENT}
FILE (WRITE "${VAR_OFILE}" "${VAR_CONTENT}")
UNSET(VAR_CONTENT)

and the in a CMakeLists.txt

# ADD_CUSTOM_COMMAND( ... ${CMAKE_COMMAND} -DVAR_IFILE=/path/to/source.m4.file -DVAR_OFILE=/path/to/dest.cpp -P ${SCRIPT_ABOVE} ...)
# also SET_SOURCE_FILES_PROPERTIES and LIST(APPEND PRJ_SRCS "${VAR_OFILE}")

> Also, if I wish to do this for all CPP files, how do I
> specify it?

You could write a MACRO that will accept INPUT filename, OUTPUT filename
and a variable name for a list of sources (to completely automate
everything).

Denis



      


More information about the CMake mailing list