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?
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?