# Question about the precompiled-header feature of CMake 3.16.x

**URL:** https://discourse.cmake.org/t/question-about-the-precompiled-header-feature-of-cmake-3-16-x/682
**Category:** Usage
**Created:** [February 21, 2020, 5:10pm UTC](https://discourse.cmake.org/t/question-about-the-precompiled-header-feature-of-cmake-3-16-x/682 "2020-02-21T17:10:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mmoelle1](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mmoelle1/32/382_2.png) [@mmoelle1](https://discourse.cmake.org/u/mmoelle1)
#### Post date: [February 21, 2020, 5:10pm UTC](https://discourse.cmake.org/t/question-about-the-precompiled-header-feature-of-cmake-3-16-x/682/1 "2020-02-21T17:10:20Z")

</div>

I started to use the precompiled-header feature introduced with Make 3.16.x (Thank you for this!)  
It all works fine when using it in the planned way. What I would like to achieve is to extract the compile instruction used for a target that makes use of the precompiled headers and write it to a file. I require this file within a just-in-time compilation framework.

See this mini example:  
add\_executable(demo demo.cpp)  
target\_precompile\_headers(demo PUBLIC “${CMAKE\_CURRENT\_SOURCE\_DIR}/demo.hpp”)

What I tried so far is this  
add\_custom\_target(genexdebug COMMAND ${CMAKE\_COMMAND} -E echo “$\<FILTER:$\<TARGET\_OBJECTS:demo\>,INCLUDE, \*.${CMAKE\_PCH\_EXTENSION}\>”)

which outputs:  
/home/\<…\>/build-gcc-5.5.0/libket/CMakeFiles/demo.dir/cmake\_pch.hxx.gch

Is it possible to strip away the “.gch” suffix inside the generator expression? If so, I could piece together the compile instructions from CMAKE\_CXX\_COMPILE\_OPTIONS\_CREATE\_PCH (-Winvalid-pch-xc+±header-include\<PCH\_HEADER\>).

Alternatively, can I evaluate CMAKE\_CXX\_COMPILE\_OPTIONS\_CREATE\_PCH for the target “demo” so that \<PCH\_HEADER\> gets replaced by /home/\<…\>/build-gcc-5.5.0/libket/CMakeFiles/demo.dir/cmake\_pch.hxx?

Thanks very much in advanced,  
Matthias

---

<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: [February 28, 2020, 8:04pm UTC](https://discourse.cmake.org/t/question-about-the-precompiled-header-feature-of-cmake-3-16-x/682/2 "2020-02-28T20:04:25Z")

</div>

This sounds like something CMake should probably add to its `compile_commands.json` output. It’s probably worth an issue if one doesn’t already exist.

Cc: @cristianadam

---

<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: [February 28, 2020, 8:10pm UTC](https://discourse.cmake.org/t/question-about-the-precompiled-header-feature-of-cmake-3-16-x/682/3 "2020-02-28T20:10:05Z")

</div>

Note that the compilation database format may not have an easy answer to some of the questions about where we’d put the information we have. It is TU-oriented, so you may just get the conglomerate input file rather than a list of individual headers in the format. This may be sufficient, but I’m not 100% sure.

---

<div class="post-metadata">

### Author: ![cristianadam](https://discourse.cmake.org/user_avatar/discourse.cmake.org/cristianadam/32/124_2.png) [@cristianadam](https://discourse.cmake.org/u/cristianadam)
#### Post date: [February 29, 2020, 11:13pm UTC](https://discourse.cmake.org/t/question-about-the-precompiled-header-feature-of-cmake-3-16-x/682/4 "2020-02-29T23:13:28Z")

</div>

`compile_commands.json` will contain the command line used to compile the PCH. See [CMAKE\_EXPORT\_COMPILE\_COMMANDS](https://cmake.org/cmake/help/v3.17/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html).

The [cmake-file-api](https://cmake.org/cmake/help/v3.17/manual/cmake-file-api.7.html) can also be used to query the information.

`CMAKE_CXX_COMPILE_OPTIONS_CREATE_PCH` variable is for CMake internal usage, and it’s not available via generator expressions.
