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

Prasad H. L. hlprasu at gmail.com
Fri Jun 5 10:52:21 EDT 2009


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...

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

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
>
>
>
>


More information about the CMake mailing list