From 3b9e04accb46127b837bc93e90d32060c63349ee Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Tue, 14 Sep 2021 16:49:16 +0200 Subject: PCH: MSVC: Restrict OBJECT library INTERFACE_LINK_LIBRARIES usage The pch object file could cause problems when the reused pch is passed through an OBJECT library, which would use INTERFACE_LINK_LIBRARIES to link the pch object file. Fixes: #22630 --- Source/cmLocalGenerator.cxx | 3 ++- .../PrecompileHeaders/PchLibObjLibExe.cmake | 24 ++++++++++++++++++++++ .../RunCMake/PrecompileHeaders/RunCMakeTest.cmake | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/PrecompileHeaders/PchLibObjLibExe.cmake diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8be015e..5042874 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2654,7 +2654,8 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) cmStrCat(" ", this->ConvertToOutputFormat(pchSourceObj, SHELL)), true); - } else { + } else if (reuseTarget->GetType() == + cmStateEnums::OBJECT_LIBRARY) { target->Target->AppendProperty( "INTERFACE_LINK_LIBRARIES", cmStrCat("$<$) + +add_library(object_lib OBJECT ${CMAKE_BINARY_DIR}/empty2.cpp) +target_precompile_headers(object_lib REUSE_FROM base_lib_static) + +add_library(mid_lib_static STATIC ${CMAKE_BINARY_DIR}/empty3.cpp) +target_link_libraries(mid_lib_static PRIVATE object_lib) + +add_executable(exec main.cpp) +target_link_libraries(exec PRIVATE mid_lib_static) +set_target_properties(exec PROPERTIES MSVC_RUNTIME_LIBRARY MultiThreaded$<$:Debug>) + +target_precompile_headers(exec PRIVATE ) + +enable_testing() +add_test(NAME exec COMMAND exec) diff --git a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake index e723e03..ca5b52e 100644 --- a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake +++ b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake @@ -29,3 +29,4 @@ if(RunCMake_GENERATOR MATCHES "Make|Ninja") endif() run_test(PchReuseFromObjLib) run_test(PchIncludedAllLanguages) +run_test(PchLibObjLibExe) -- cgit v0.12