[CMake] How to write a cmake target to create a preprocessed file?

Markus Grabner grabner at icg.tugraz.at
Fri Jun 8 03:54:06 EDT 2012


	Hi!

    Is it possible to write a cmake target to generate a preprocessed C++ 
file? I know that cmake creates Makefiles which contain the appropriate make 
targets as discussed here:

http://www.cmake.org/pipermail/cmake/2009-March/028006.html
http://www.cmake.org/pipermail/cmake/2009-May/029271.html

So I can manually change to the build directory and type "make souce.i" to 
generate the preprocessed file "source.i" from a C++ file "source.cpp". 
However, this target only seems to be available in the make file, but not in 
the cmake context, i.e., writing a cmake target such as

add_custom_target(preprocess DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/source.i)

results in an error when running "make preprocess" (with the cmake-generated 
make file). I could of course create a custom command which changes to the 
appropriate directory and executes "make source.i", but this is platform-
dependent since it requires to know in advance the name of the build tool 
("make") and the extension of the preprocessed file (".i").

So I have two questions:
*) How can I write a cmake target which creates a preprocessed file from a 
given C++ source file in a platform-independent way?
*) How can I find out the name of the preprocessed file in a platform-
independent way?

	Thanks & kind regards,
		Markus



More information about the CMake mailing list