summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@gmail.com>2021-08-07 15:07:55 (GMT)
committerCristian Adam <cristian.adam@gmail.com>2021-09-13 15:12:11 (GMT)
commitbbcdac4e5d53de12013c6af6395b28e4816f7823 (patch)
tree1d18f8ca2efc885fac477e2ce832bb161fdddd1d /Source
parentcc94429c61fcdff73ff78430692ff12ed1fff29b (diff)
downloadCMake-bbcdac4e5d53de12013c6af6395b28e4816f7823.zip
CMake-bbcdac4e5d53de12013c6af6395b28e4816f7823.tar.gz
CMake-bbcdac4e5d53de12013c6af6395b28e4816f7823.tar.bz2
PCH: Fix all-language precompile header support in Xcode
Fixes: #22384
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorTarget.cxx4
-rw-r--r--Source/cmLocalGenerator.cxx15
2 files changed, 17 insertions, 2 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 17237bb..bb751d6 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -4100,7 +4100,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
if (this->GetGlobalGenerator()->IsXcode()) {
file << "#ifndef CMAKE_SKIP_PRECOMPILE_HEADERS\n";
}
- if (language == "CXX") {
+ if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
file << "#ifdef __cplusplus\n";
}
for (auto const& header_bt : headers) {
@@ -4118,7 +4118,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
firstHeaderOnDisk = header_bt.Value;
}
}
- if (language == "CXX") {
+ if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
file << "#endif // __cplusplus\n";
}
if (this->GetGlobalGenerator()->IsXcode()) {
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 028952a..016653b 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -2512,6 +2512,16 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
static const std::array<std::string, 4> langs = { { "C", "CXX", "OBJC",
"OBJCXX" } };
+ bool haveAnyPch = false;
+ if (this->GetGlobalGenerator()->IsXcode()) {
+ for (const std::string& lang : langs) {
+ const std::string pchHeader = target->GetPchHeader(config, lang, "");
+ if (!pchHeader.empty()) {
+ haveAnyPch = true;
+ }
+ }
+ }
+
for (const std::string& lang : langs) {
auto langSources = std::count_if(
sources.begin(), sources.end(), [lang](cmSourceFile* sf) {
@@ -2552,6 +2562,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) {
+ for (auto* sf : sources) {
+ sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
+ }
+ }
continue;
}