# How to pass target\_compile\_options to target\_precompile\_headers

**URL:** https://discourse.cmake.org/t/how-to-pass-target-compile-options-to-target-precompile-headers/13947
**Category:** Usage
**Created:** [April 17, 2025, 7:58am UTC](https://discourse.cmake.org/t/how-to-pass-target-compile-options-to-target-precompile-headers/13947 "2025-04-17T07:58:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Marcel\_Behlau](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marcel_behlau/32/5509_2.png) [@Marcel\_Behlau](https://discourse.cmake.org/u/Marcel_Behlau)
#### Post date: [April 17, 2025, 7:58am UTC](https://discourse.cmake.org/t/how-to-pass-target-compile-options-to-target-precompile-headers/13947/1 "2025-04-17T07:58:45Z")

</div>

Hi,

i observed the problem, that set target\_compile\_options are not used within target\_precompile\_headers.

My expectation is, that the set target\_compile\_options also used within the target\_precompile\_headers, since both are using the same target.

I created a minimal example: [target\_compile\_options with target\_precompile\_headers problem · GitHub](https://gist.github.com/marcel-behlau-elfin/c317a2cf8bf0363156916ba6f65105ec)

I would expect, that my code fails by the missing return state. But this happens, as long the subindex.h is somehow affected by the PCH, not.

If i disable PCH or remove the include, the compiler complains.

> In file included from /tmp/example/main.cpp:3:  
> /tmp/example/subindex.h: In member function ‘bool SubIndex::operator=(const SubIndex&)’:  
> /tmp/example/subindex.h:11:60: error: no return statement in function returning non-void [-Werror=return-type]  
> 11 | bool operator=(const SubIndex& rhs) { index = rhs.index; }

I tried to set compile options globally via

add\_compile\_options(-Werror -Wall -Wextra)

But this also not used while PCH compilation.

Is there a way to set compile options for PCH?

Thank you very much in advance and best regards,

Marcel
