# How about let compiler executes the preprocessor step.

**URL:** https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533
**Category:** Usage
**Created:** [January 13, 2021, 9:00am UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533 "2021-01-13T09:00:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dalianduzhi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@dalianduzhi](https://discourse.cmake.org/u/dalianduzhi)
#### Post date: [January 13, 2021, 9:00am UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/1 "2021-01-13T09:00:04Z")

</div>

Hi

I want to let the compiler executes the preprocessor and get the output.  
Can CMake do this without using the add\_custcom\_command?

thanks

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [January 13, 2021, 9:27am UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/2 "2021-01-13T09:27:08Z")

</div>

Do you want the compiler to be also called normally? If so, then you could look into using `<LANG>_COMPILER_LAUNCHER` ([https://cmake.org/cmake/help/latest/prop\_tgt/lang\_compiler\_launcher.html](https://cmake.org/cmake/help/latest/prop_tgt/lang_compiler_launcher.html)) to call the compiler twice.

---

<div class="post-metadata">

### Author: ![dalianduzhi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@dalianduzhi](https://discourse.cmake.org/u/dalianduzhi)
#### Post date: [January 13, 2021, 12:44pm UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/3 "2021-01-13T12:44:59Z")

</div>

It needs the third-party tool like ccache.  
Are there any other ways?

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [January 13, 2021, 12:55pm UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/4 "2021-01-13T12:55:39Z")

</div>

Using `ccache` with CMake is exactly done with `<LANG>_COMPILER_LAUNCHER`. [https://cmake.org/cmake/help/latest/prop\_tgt/LANG\_COMPILER\_LAUNCHER.html](https://cmake.org/cmake/help/latest/prop_tgt/LANG_COMPILER_LAUNCHER.html) even contains:

> Some example tools are distcc and ccache.

---

<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: [January 13, 2021, 4:41pm UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/5 "2021-01-13T16:41:06Z")

</div>

> [@dalianduzhi](#):
>
> It needs the third-party tool like ccache.

That is one of the typical uses of the variable, but you can write your own script which takes the command line, modifies it to do the preprocessing and execute that, and then do the original compilation step as normal.

Note that the `Makefiles` generators have targets to make the preprocessing output (usually you just change the `.o` extension to `.i` and invoke it manually). For example, if you want the preprocessed output for the `CMakeFiles/mytgt.dir/myfile.o` file, `make CMakeFiles/mytgt.dir/myfile.i` should exist.

---

<div class="post-metadata">

### Author: ![dalianduzhi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@dalianduzhi](https://discourse.cmake.org/u/dalianduzhi)
#### Post date: [January 14, 2021, 12:36am UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/6 "2021-01-14T00:36:52Z")

</div>

Are there targets like this in Ninja generator?

---

<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: [January 14, 2021, 1:31pm UTC](https://discourse.cmake.org/t/how-about-let-compiler-executes-the-preprocessor-step/2533/7 "2021-01-14T13:31:09Z")

</div>

That would be [this issue](https://gitlab.kitware.com/cmake/cmake/-/issues/13838) if you’re interested in tracking it.
