mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-03 04:10:05 -06:00
@@ -4100,7 +4100,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
|
|||||||
if (this->GetGlobalGenerator()->IsXcode()) {
|
if (this->GetGlobalGenerator()->IsXcode()) {
|
||||||
file << "#ifndef CMAKE_SKIP_PRECOMPILE_HEADERS\n";
|
file << "#ifndef CMAKE_SKIP_PRECOMPILE_HEADERS\n";
|
||||||
}
|
}
|
||||||
if (language == "CXX") {
|
if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
|
||||||
file << "#ifdef __cplusplus\n";
|
file << "#ifdef __cplusplus\n";
|
||||||
}
|
}
|
||||||
for (auto const& header_bt : headers) {
|
for (auto const& header_bt : headers) {
|
||||||
@@ -4118,7 +4118,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
|
|||||||
firstHeaderOnDisk = header_bt.Value;
|
firstHeaderOnDisk = header_bt.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (language == "CXX") {
|
if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
|
||||||
file << "#endif // __cplusplus\n";
|
file << "#endif // __cplusplus\n";
|
||||||
}
|
}
|
||||||
if (this->GetGlobalGenerator()->IsXcode()) {
|
if (this->GetGlobalGenerator()->IsXcode()) {
|
||||||
|
|||||||
@@ -2512,6 +2512,16 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
|
|||||||
static const std::array<std::string, 4> langs = { { "C", "CXX", "OBJC",
|
static const std::array<std::string, 4> langs = { { "C", "CXX", "OBJC",
|
||||||
"OBJCXX" } };
|
"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) {
|
for (const std::string& lang : langs) {
|
||||||
auto langSources = std::count_if(
|
auto langSources = std::count_if(
|
||||||
sources.begin(), sources.end(), [lang](cmSourceFile* sf) {
|
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);
|
const std::string pchHeader = target->GetPchHeader(config, lang, arch);
|
||||||
|
|
||||||
if (pchSource.empty() || pchHeader.empty()) {
|
if (pchSource.empty() || pchHeader.empty()) {
|
||||||
|
if (this->GetGlobalGenerator()->IsXcode() && haveAnyPch) {
|
||||||
|
for (auto* sf : sources) {
|
||||||
|
sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
|
||||||
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
project(PchIncludedAllLanguages C CXX)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH)
|
||||||
|
add_definitions(-DHAVE_PCH_SUPPORT)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(main
|
||||||
|
main.cpp
|
||||||
|
pch-included.c
|
||||||
|
pch-included.cpp
|
||||||
|
)
|
||||||
|
target_precompile_headers(main PRIVATE pch.h)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_test(NAME main COMMAND main)
|
||||||
@@ -28,3 +28,4 @@ if(RunCMake_GENERATOR MATCHES "Make|Ninja")
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
run_test(PchReuseFromObjLib)
|
run_test(PchReuseFromObjLib)
|
||||||
|
run_test(PchIncludedAllLanguages)
|
||||||
|
|||||||
8
Tests/RunCMake/PrecompileHeaders/pch-included.c
Normal file
8
Tests/RunCMake/PrecompileHeaders/pch-included.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef HAVE_PCH_SUPPORT
|
||||||
|
# include "pch.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int testC(void)
|
||||||
|
{
|
||||||
|
return PCH_INCLUDED;
|
||||||
|
}
|
||||||
8
Tests/RunCMake/PrecompileHeaders/pch-included.cpp
Normal file
8
Tests/RunCMake/PrecompileHeaders/pch-included.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef HAVE_PCH_SUPPORT
|
||||||
|
# include "pch.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int testCpp()
|
||||||
|
{
|
||||||
|
return PCH_INCLUDED;
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define PCH_INCLUDED 1
|
#define PCH_INCLUDED 1
|
||||||
|
|
||||||
|
int testC(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user