# Portable way of invoking the C preprocessor

**URL:** https://discourse.cmake.org/t/portable-way-of-invoking-the-c-preprocessor/8825
**Category:** Usage
**Created:** [August 27, 2023, 4:09pm UTC](https://discourse.cmake.org/t/portable-way-of-invoking-the-c-preprocessor/8825 "2023-08-27T16:09:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![erlendaasland](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erlendaasland/32/1866_2.png) [@erlendaasland](https://discourse.cmake.org/u/erlendaasland)
#### Post date: [August 27, 2023, 4:09pm UTC](https://discourse.cmake.org/t/portable-way-of-invoking-the-c-preprocessor/8825/1 "2023-08-27T16:09:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 29, 2023, 2:13pm UTC](https://discourse.cmake.org/t/portable-way-of-invoking-the-c-preprocessor/8825/2 "2023-08-29T14:13:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![erlendaasland](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erlendaasland/32/1866_2.png) [@erlendaasland](https://discourse.cmake.org/u/erlendaasland)
#### Post date: [August 30, 2023, 11:51am UTC](https://discourse.cmake.org/t/portable-way-of-invoking-the-c-preprocessor/8825/3 "2023-08-30T11:51:39Z")

</div>

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