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

Robert Haines rhaines at manchester.ac.uk
Fri Jun 5 11:04:28 EDT 2009


Hi,

On 5 Jun 2009, at 15:52, Prasad H. L. wrote:

> I tried as you have suggested. I have one more problem. I tried the
> following CMakeLists.txt
>
> --------
> project(cmake_test)
> cmake_minimum_required(VERSION 2.6)
>
> add_executable(testcmake testcmake.m4.cpp)
>
> add_custom_command(OUTPUT testcmake.m4.cpp
> 					m4 -P -s testcmake.cpp > testcmake.m4.cpp
> 					VERBATIM)
> 					
> set_source_files_properties(testcmake.m4.cpp PROPERTIES GENERATED true
> SYMBOLIC true)
> ------------------
>
> In the above testcmake.cpp is the actual file and I wish to create
> the processed file as testcmake.m4.cpp. But, I get the following error
> when I run cmake
>
> -------------------------
> CMake Error at CMakeLists.txt:6 (add_custom_command):
>  add_custom_command called with OUTPUT containing a ">".  This
> character is
>  not allowed.
>
>
> -- Configuring incomplete, errors occurred!
> -------------------------
>
> 'm4' outputs only on stdout and does not have an option to specify the
> output file. Please
> suggest me a solution for this...

You haven't quite used add_custom_command correctly. You have missed  
out the COMMAND and ARGS parts for a start. Try:

add_custom_command(
   OUTPUT testcmake.m4.cpp
   COMMAND m4
   ARGS -P -s testcmake.cpp > testcmake.m4.cpp
   VERBATIM
)

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

You could put all the files to be processed in a list and then do the  
above in a foreach() block.

Cheers,
Rob

>
> 2009/6/5 Denis Scherbakov <denis_scherbakov at yahoo.com>:
>>
>>
>>> I wanted to do some looping in macros which are not
>>> possible in GNU
>>> CPP. So, I wrote
>>> macros in m4. I wish to pre-process all my C/C++ code with
>>> m4 before
>>> handing it over to
>>> gcc. I did not find any direct way out for doing this in
>>> cmake. Any
>>> ideas how to do it with
>>> cmake?
>>
>> Use ADD_CUSTOM_COMMAND to call m4 preprocessor and OUTPUT file.cpp
>> Then use SET_SOURCE_FILES_PROPERTIES set GENERATED TRUE
>> and then include file.cpp into a list of sources for compilation.
>>
>> Denis
>>
>>
>>
>>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

-- 
Robert Haines

Research Associate, RealityGrid          Tel. : +44 (0)161 275 6067
Research Computing Services              Fax. : +44 (0)161 275 0637
University of Manchester                 Email: rhaines at manchester.ac.uk
Oxford Road                              Web  : www.realitygrid.org
Manchester, M13 9PL                           : www.rcs.manchester.ac.uk



More information about the CMake mailing list