# target\_precompile\_headers, generate an .h precompiled header file instead of .hxx ?

**URL:** <https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815>\
**Category:** Code\
**Created:** [January 11, 2022, 1:03pm UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815 "2022-01-11T13:03:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amzh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@amzh](https://discourse.cmake.org/u/amzh)\
**Post date:** [January 11, 2022, 1:03pm UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815/1 "2022-01-11T13:03:06Z")

</div>

Hello,

The documentation says

> The list of header files is used to generate a header file named `cmake_pch.h|xx` which is used to generate the precompiled header file

What 's the proper way of telling CMake how to generate exactly cmake\_pch.h instead of .hxx ? Is that only controlled by CMake’s project command ?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [January 11, 2022, 8:53pm UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815/2 "2022-01-11T20:53:25Z")

</div>

I don’t think there’s a way to control it, and I’d ask why you’d even need or want to. That file is an internal implementation detail of CMake and arguably shouldn’t even be mentioned in the documentation. The project should not be relying on that file having any particular name, nor try to reference or use it directly.

---

<div class="post-metadata">

**Author:** ![amzh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@amzh](https://discourse.cmake.org/u/amzh)\
**Post date:** [January 12, 2022, 11:23am UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815/3 "2022-01-12T11:23:31Z")

</div>

I need it for the reason that my framework can’t compile with a .hxx one, as far as I can understand due to c sources.

What do you mean reference or use ‘directly’, isn’t that the prefix header project uses?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [January 12, 2022, 8:03pm UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815/4 "2022-01-12T20:03:38Z")

</div>

The project doesn’t need to explicitly include the `cmake_pch.hxx` file. CMake injects it on the compiler command line for you where needed. If it is creating a `cmake_pch.hxx` file, my recollection is that it means CMake thinks the source to use it with is a C++ file, not a C file. I think there are separate `cmake_pch.h` and `cmake_pch.hxx` files for C and C++ sources, but it’s been a while since I looked at that. @cristianadam would know the details and could comment further.

---

<div class="post-metadata">

**Author:** ![amzh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@amzh](https://discourse.cmake.org/u/amzh)\
**Post date:** [January 13, 2022, 11:26am UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815/5 "2022-01-13T11:26:38Z")

</div>

Thanks for that, that’s what I assumed.
