summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Help/command/target_precompile_headers.rst4
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake14
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake5
3 files changed, 22 insertions, 1 deletions
diff --git a/Help/command/target_precompile_headers.rst b/Help/command/target_precompile_headers.rst
index 3a32f4147e..d283948cef 100644
--- a/Help/command/target_precompile_headers.rst
+++ b/Help/command/target_precompile_headers.rst
@@ -47,6 +47,9 @@ with the syntax ``$<...>``.
See the :manual:`cmake-generator-expressions(7)` manual for available
expressions. See the :manual:`cmake-compile-features(7)` manual for
information on compile features and a list of supported compilers.
+The ``$<COMPILE_LANGUAGE:...>`` generator expression is particularly
+useful for specifying a language-specific header to precompile for
+only one language (e.g. ``CXX`` and not ``C``).
Usage
^^^^^
@@ -56,6 +59,7 @@ Usage
target_precompile_headers(<target>
PUBLIC
project_header.h
+ "$<$<COMPILE_LANGUAGE:CXX>:cxx_only.h>"
PRIVATE
[["other_header.h"]]
<unordered_map>
diff --git a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake
index 44fe2dafa0..e0b753a4e9 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage-check.cmake
@@ -15,3 +15,17 @@ if (NOT EXISTS ${foobar_pch_hxx_header})
set(RunCMake_TEST_FAILED "Generated foobar C++ pch header ${foobar_pch_hxx_header} does not exist")
return()
endif()
+
+file(STRINGS ${foobar_pch_h_header} foobar_pch_h_header_strings)
+
+if (NOT foobar_pch_h_header_strings MATCHES ";#include <stddef.h>(;|$)")
+ set(RunCMake_TEST_FAILED "Generated foo pch header\n ${foobar_pch_h_header}\nhas bad content:\n ${foobar_pch_h_header_strings}")
+ return()
+endif()
+
+file(STRINGS ${foobar_pch_hxx_header} foobar_pch_hxx_header_strings)
+
+if (NOT foobar_pch_hxx_header_strings MATCHES ";#include <cstddef>(;|$)")
+ set(RunCMake_TEST_FAILED "Generated foo pch header\n ${foobar_pch_hxx_header}\nhas bad content:\n ${foobar_pch_hxx_header_strings}")
+ return()
+endif()
diff --git a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake
index 7a837daf01..cdc42b2a2d 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake
@@ -6,4 +6,7 @@ add_executable(foobar
main.cpp
)
target_include_directories(foobar PUBLIC include)
-target_precompile_headers(foobar PRIVATE "<stddef.h>")
+target_precompile_headers(foobar PRIVATE
+ "$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>"
+ "$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
+ )