Portable way of invoking the C preprocessor

I’ve been searching the web (including the CMake docs) for a portable way of invoking the preprocessor. In my case, specifically the C preprocessor. Until now, I haven’t found promising results, so unless someone can point me in the right direction, I guess I will have to define my own custom command for this (probably generalising it down to MSVC and GCC compatible compilers).

The Makefiles generators have rules for builddir/of/target/CMakeFiles/tgt.dir/filename.ext.i to get preprocessed output. I think the Ninja generators may have something similar as a feature request. I don’t think the IDE generators get these kinds of things though.

1 Like

I found the undocumented CMAKE_<LANG>_CREATE_PREPROCESSED_SOURCE variable, which seems to be a step in the right direction.