Commit 1d39c1e2 authored by Brad King's avatar Brad King
Browse files

Merge branch 'pch-genex-absolute' into release-3.16

Merge-request: !4678
parents 6046baec b204bae2
......@@ -56,35 +56,34 @@ e.g. ``[["other_header.h"]]``) will be treated as is, and include directories
must be available for the compiler to find them. Other header file names
(e.g. ``project_header.h``) are interpreted as being relative to the current
source directory (e.g. :variable:`CMAKE_CURRENT_SOURCE_DIR`) and will be
included by absolute path.
Arguments to ``target_precompile_headers()`` may use "generator expressions"
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``). For example:
included by absolute path. For example:
.. code-block:: cmake
target_precompile_headers(myTarget
PUBLIC
project_header.h
"$<$<COMPILE_LANGUAGE:CXX>:cxx_only.h>"
PRIVATE
[["other_header.h"]]
<unordered_map>
)
When specifying angle brackets inside a :manual:`generator expression
<cmake-generator-expressions(7)>`, be sure to encode the closing ``>``
as ``$<ANGLE-R>``. For example:
Arguments to ``target_precompile_headers()`` may use "generator expressions"
with the syntax ``$<...>``.
See the :manual:`cmake-generator-expressions(7)` manual for available
expressions.
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``). In this case, header
file names that are not explicitly in double quotes or angle brackets
must be specified by absolute path. Also, when specifying angle brackets
inside a generator expression, be sure to encode the closing ``>`` as
``$<ANGLE-R>``. For example:
.. code-block:: cmake
target_precompile_headers(mylib PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_only.h>"
"$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
)
......
......@@ -13,14 +13,14 @@ endif()
file(STRINGS ${foobar_pch_h_header} foobar_pch_h_header_strings)
if (NOT foobar_pch_h_header_strings MATCHES ";#include <stddef.h>(;|$)")
if (NOT foobar_pch_h_header_strings MATCHES ";#include \"[^\"]*PrecompileHeaders/include/foo_C.h\";#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>(;|$)")
if (NOT foobar_pch_hxx_header_strings MATCHES ";#include \"[^\"]*PrecompileHeaders/include/foo_CXX.h\";#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()
......@@ -7,6 +7,8 @@ add_executable(foobar
)
target_include_directories(foobar PUBLIC include)
target_precompile_headers(foobar PRIVATE
"$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}/include/foo_C.h>"
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/include/foo_CXX.h>"
"$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment