# Restricting target\_precompile\_headers to one language?

**URL:** <https://discourse.cmake.org/t/restricting-target-precompile-headers-to-one-language/7284>\
**Category:** Code\
**Created:** [January 19, 2023, 7:51pm UTC](https://discourse.cmake.org/t/restricting-target-precompile-headers-to-one-language/7284 "2023-01-19T19:51:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfsone](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kfsone/32/1880_2.png) [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Post date:** [January 19, 2023, 7:52pm UTC](https://discourse.cmake.org/t/restricting-target-precompile-headers-to-one-language/7284/1 "2023-01-19T19:52:00Z")

</div>

Attempting to use target\_precompile\_headers with a long list of C+±only header files for a C+±only target in a multi-language project.

Is it possible to tell CMake that a given target only uses a specific subset of the language’s enabled?

```auto
cmake_minimum_required (VERSION 3.24)
project (Ours LANGUAGES C CXX OBJC OBJCXX)
add_library (just_c c.c)
if (mac) add_library (mac1.m mac2.mm) endif ()
add_library (just_cpp cpp.c)

# Fail:
target_precompile_headers (just_cpp PRIVATE cpp_h1.h ... cpp_h421.h)

```

I assume I have to use a `$<$<COMPILE_LANGUAGE:CXX>>` generator expression, but that adds a bit of complexity to construct. I was hoping for a way to restrict a target to one language (`set_target_properties (just_cpp PROPERTIES LANGUAGE[S] CXX)`), but this doesn’t seem to affect target\_precompile\_headers?
