summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-10-19 15:28:40 (GMT)
committerBrad King <brad.king@kitware.com>2021-10-19 15:50:07 (GMT)
commit71f15be957b1a4fc37edbfd70809c759e92227a2 (patch)
treeed1e0be02e4f8b4bc8c576494ee43166ab2bddb5 /Tests/RunCMake/VS10Project/RunCMakeTest.cmake
parent7fcc35c676b46fc30cb67425bfc72c7de040d6bf (diff)
downloadCMake-71f15be957b1a4fc37edbfd70809c759e92227a2.zip
CMake-71f15be957b1a4fc37edbfd70809c759e92227a2.tar.gz
CMake-71f15be957b1a4fc37edbfd70809c759e92227a2.tar.bz2
VS: Fix compilation of single source with PCH in Unity Build
Sources that are part of a unity build are normally not compiled individually. However, the VS IDE allows a single source to be compiled. This can also be achieved on the command line: msbuild my.vcxproj ... -t:ClCompile -p:SelectedFiles=<src> where `<src>` is the path in the vcxproj `ClCompile` entry. In a target with precompiled headers, the source needs PCH settings to support individual compilation even if the normal unity build does not.
Diffstat (limited to 'Tests/RunCMake/VS10Project/RunCMakeTest.cmake')
-rw-r--r--Tests/RunCMake/VS10Project/RunCMakeTest.cmake15
1 files changed, 15 insertions, 0 deletions
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
index d5ed136..f945b43 100644
--- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -64,6 +64,21 @@ if (RunCMake_GENERATOR MATCHES "Visual Studio 1[0-4] 201[0-5]" OR
else()
run_cmake(UnityBuildNative)
run_cmake(UnityBuildNativeGrouped)
+
+ function(run_UnityBuildPCH)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/UnityBuildPCH-build)
+ run_cmake(UnityBuildPCH)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(vcxproj "${RunCMake_TEST_BINARY_DIR}/UnityBuildPCH.vcxproj")
+ if(EXISTS "${vcxproj}")
+ file(STRINGS ${vcxproj} vcxproj_strings REGEX "ClCompile[^\n]*UnityBuildPCH\\.c")
+ endif()
+ if(vcxproj_strings MATCHES "Include=\"([^\"]+)\"")
+ set(src "${CMAKE_MATCH_1}")
+ run_cmake_command(UnityBuildPCH-build ${CMAKE_COMMAND} --build . --config Debug --target UnityBuildPCH -- -t:ClCompile -p:SelectedFiles=${src})
+ endif()
+ endfunction()
+ run_UnityBuildPCH()
endif()
run_cmake(VsDotnetTargetFramework)