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
This commit is contained in:
Cristian Adam
2021-09-14 16:49:16 +02:00
committed by Brad King
parent c9a29ce55d
commit 3b9e04accb
3 changed files with 27 additions and 1 deletions

View File

@@ -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("$<$<CONFIG:", config,

View File

@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.16)
project(PchLibObjLibExe CXX)
foreach(i 1 2 3)
file(WRITE ${CMAKE_BINARY_DIR}/empty${i}.cpp "void nothing${i}() {}\n")
endforeach()
add_library(base_lib_static STATIC ${CMAKE_BINARY_DIR}/empty1.cpp)
target_precompile_headers(base_lib_static PRIVATE <vector>)
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$<$<CONFIG:Debug>:Debug>)
target_precompile_headers(exec PRIVATE <string>)
enable_testing()
add_test(NAME exec COMMAND exec)

View File

@@ -29,3 +29,4 @@ if(RunCMake_GENERATOR MATCHES "Make|Ninja")
endif()
run_test(PchReuseFromObjLib)
run_test(PchIncludedAllLanguages)
run_test(PchLibObjLibExe)