How to pass target_compile_options to target_precompile_headers

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

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