PCH: Fix Xcode non-pch language exclusion

Fix a regression caused by commit bbcdac4e5d (PCH: Fix all-language
precompile header support in Xcode, 2021-08-07, v3.22.0-rc1~140^2).

Fixes: #23138
This commit is contained in:
Cristian Adam
2022-04-11 10:50:22 -07:00
committed by Brad King
parent fcf1fcfd0c
commit 476c6a8910
3 changed files with 24 additions and 4 deletions

View File

@@ -2510,12 +2510,12 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
static const std::array<std::string, 4> langs = { { "C", "CXX", "OBJC",
"OBJCXX" } };
bool haveAnyPch = false;
std::set<std::string> pchLangSet;
if (this->GetGlobalGenerator()->IsXcode()) {
for (const std::string& lang : langs) {
const std::string pchHeader = target->GetPchHeader(config, lang, "");
if (!pchHeader.empty()) {
haveAnyPch = true;
pchLangSet.emplace(lang);
}
}
}
@@ -2560,9 +2560,11 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
const std::string pchHeader = target->GetPchHeader(config, lang, arch);
if (pchSource.empty() || pchHeader.empty()) {
if (this->GetGlobalGenerator()->IsXcode() && haveAnyPch) {
if (this->GetGlobalGenerator()->IsXcode() && !pchLangSet.empty()) {
for (auto* sf : sources) {
sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
if (pchLangSet.find(sf->GetLanguage()) == pchLangSet.end()) {
sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
}
}
}
continue;

View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(PchIncludedAllLanguages C CXX)
if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH)
add_definitions(-DHAVE_PCH_SUPPORT)
endif()
add_executable(main
main.cpp
empty.c
pch-included.cpp
)
target_precompile_headers(main PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/pch.h>)
enable_testing()
add_test(NAME main COMMAND main)

View File

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