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

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jun 17 17:02:36 EDT 2009


On Friday 05 June 2009, Robert Haines wrote:
> 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
> )

Yes. And I think since cmake 2.4 the "ARGS" is optional, so you can also do 
add_custom_command(
   OUTPUT testcmake.m4.cpp
   COMMAND m4 -P -s testcmake.cpp > testcmake.m4.cpp
   VERBATIM
)

I also think the set_source_files_properties() is not necessary.
Also I would suggest to specify always the full path, i.e. 
${CMAKE_CURRENT_BINARY_DIR}/testcmake.m4.cpp.

Alex


More information about the CMake mailing list