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.
This commit is contained in:
parent
7fcc35c676
commit
71f15be957
@ -2337,7 +2337,8 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
|
||||
}
|
||||
}
|
||||
|
||||
if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) {
|
||||
if (si.Kind == cmGeneratorTarget::SourceKindObjectSource ||
|
||||
si.Kind == cmGeneratorTarget::SourceKindUnityBatched) {
|
||||
this->OutputSourceSpecificFlags(e2, si.Source);
|
||||
}
|
||||
if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) {
|
||||
|
@ -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)
|
||||
|
10
Tests/RunCMake/VS10Project/UnityBuildPCH-build-check.cmake
Normal file
10
Tests/RunCMake/VS10Project/UnityBuildPCH-build-check.cmake
Normal file
@ -0,0 +1,10 @@
|
||||
set(obj "${RunCMake_TEST_BINARY_DIR}/UnityBuildPCH.dir/Debug/UnityBuildPCH.obj")
|
||||
if(NOT EXISTS "${obj}")
|
||||
set(RunCMake_TEST_FAILED "Expected object file does not exist:\n ${obj}")
|
||||
return()
|
||||
endif()
|
||||
set(lib "${RunCMake_TEST_BINARY_DIR}/Debug/UnityBuildPCH.lib")
|
||||
if(EXISTS "${lib}")
|
||||
set(RunCMake_TEST_FAILED "Unexpected library file exists:\n ${lib}")
|
||||
return()
|
||||
endif()
|
4
Tests/RunCMake/VS10Project/UnityBuildPCH.c
Normal file
4
Tests/RunCMake/VS10Project/UnityBuildPCH.c
Normal file
@ -0,0 +1,4 @@
|
||||
int UnityBuildPCH(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
4
Tests/RunCMake/VS10Project/UnityBuildPCH.cmake
Normal file
4
Tests/RunCMake/VS10Project/UnityBuildPCH.cmake
Normal file
@ -0,0 +1,4 @@
|
||||
enable_language(C)
|
||||
add_library(UnityBuildPCH STATIC UnityBuildPCH.c)
|
||||
target_precompile_headers(UnityBuildPCH PRIVATE UnityBuildPCH.h)
|
||||
set_property(TARGET UnityBuildPCH PROPERTY UNITY_BUILD ON)
|
1
Tests/RunCMake/VS10Project/UnityBuildPCH.h
Normal file
1
Tests/RunCMake/VS10Project/UnityBuildPCH.h
Normal file
@ -0,0 +1 @@
|
||||
/* empty file */
|
Loading…
Reference in New Issue
Block a user