summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/PrecompileHeaders
diff options
context:
space:
mode:
authorTobias Hieta <tobias@plex.tv>2020-08-28 07:16:04 (GMT)
committerTobias Hieta <tobias@plex.tv>2020-09-02 06:30:55 (GMT)
commit8c8f03422e3197a3414a8ed1413fcb9576df0f4b (patch)
tree526e5b6341f3f63dd848623be82448fab17f5285 /Tests/RunCMake/PrecompileHeaders
parent8c833ff0e17e63d9cbf17622abcb70a5fab240b8 (diff)
downloadCMake-8c8f03422e3197a3414a8ed1413fcb9576df0f4b.zip
CMake-8c8f03422e3197a3414a8ed1413fcb9576df0f4b.tar.gz
CMake-8c8f03422e3197a3414a8ed1413fcb9576df0f4b.tar.bz2
PCH: Template instantiation support
Adds PCH_INSTANTIATE_TEMPLATES target property for enabling template instantiation in precompiled headers. Enabled by default. Currently only supported for Clang 11 and newer. Implements #21133.
Diffstat (limited to 'Tests/RunCMake/PrecompileHeaders')
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates-check.cmake17
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates.cmake16
-rw-r--r--Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake5
3 files changed, 38 insertions, 0 deletions
diff --git a/Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates-check.cmake b/Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates-check.cmake
new file mode 100644
index 0000000..648d387
--- /dev/null
+++ b/Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates-check.cmake
@@ -0,0 +1,17 @@
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/compile_commands.json empty_dir_commands
+ REGEX "command.*-fpch-instantiate-templates.*empty.dir/cmake_pch.h")
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/compile_commands.json foo_dir_commands
+ REGEX "command.*-fpch-instantiate-templates.*foo.dir/cmake_pch.h")
+
+list(LENGTH empty_dir_commands empty_dir_commands_size)
+list(LENGTH foo_dir_commands foo_dir_commands_size)
+
+if (empty_dir_commands_size EQUAL 0)
+ set(RunCMake_TEST_FAILED "empty target should have -fpch-instantiate-templates compile option present")
+ return()
+endif()
+
+if (foo_dir_commands_size GREATER 0)
+ set(RunCMake_TEST_FAILED "foo target should not have -fpch-instantiate-templates compile option present")
+ return()
+endif()
diff --git a/Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates.cmake b/Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates.cmake
new file mode 100644
index 0000000..3aebbe0
--- /dev/null
+++ b/Tests/RunCMake/PrecompileHeaders/PchInstantiateTemplates.cmake
@@ -0,0 +1,16 @@
+enable_language(C)
+
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
+add_library(empty empty.c)
+target_precompile_headers(empty PUBLIC
+ <stdio.h>
+ <string.h>
+)
+
+add_library(foo foo.c)
+target_precompile_headers(foo PUBLIC
+ <stdio.h>
+ <string.h>
+)
+set_target_properties(foo PROPERTIES PCH_INSTANTIATE_TEMPLATES OFF)
diff --git a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake
index 381b800..74670ba 100644
--- a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake
@@ -20,4 +20,9 @@ run_test(PchReuseFromSubdir)
run_cmake(PchMultilanguage)
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
run_cmake(PchWarnInvalid)
+
+ if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
+ CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0.0)
+ run_cmake(PchInstantiateTemplates)
+ endif()
endif()