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

Prasad H. L. hlprasu at gmail.com
Fri Jun 5 12:12:40 EDT 2009


Thanks.

Is it possible to set the preprocessing to all .m4 files avoiding a
manual specification of list of files to processed?

2009/6/5 Denis Scherbakov <denis_scherbakov at yahoo.com>:
>
>
>> '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
>
>
>
>
>



-- 
Prasad H. L.
PhD Student (with Dr. Shalabh Bhatnagar)
Department of Computer Science and Automation,
Indian Institute of Science,
Bangalore - 560012


More information about the CMake mailing list