PCH: Use per-arch .pch files only when building multiple Apple architectures
Since commit f593b354da
(PCH: Add support for multi architecture iOS
projects, 2020-04-02, v3.18.0-rc1~414^2) we use per-arch .pch files
even when compiling for just the host architecture on macOS arm64.
This breaks with compilers that do not support `-Xarch_` flags, such
as GCC. Avoid using per-arch .pch files in single-architecture builds.
Fixes: #25514
Issue: #20497
This commit is contained in:
parent
99bfb430ee
commit
ef006ebd9b
@ -1384,14 +1384,11 @@ CompileData Target::BuildCompileData(cmSourceFile* sf)
|
||||
}
|
||||
|
||||
// Add precompile headers compile options.
|
||||
std::vector<std::string> architectures =
|
||||
this->GT->GetAppleArchs(this->Config, fd.Language);
|
||||
if (architectures.empty()) {
|
||||
architectures.emplace_back();
|
||||
}
|
||||
std::vector<std::string> pchArchs =
|
||||
this->GT->GetPchArchs(this->Config, fd.Language);
|
||||
|
||||
std::unordered_map<std::string, std::string> pchSources;
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
const std::string pchSource =
|
||||
this->GT->GetPchSource(this->Config, fd.Language, arch);
|
||||
if (!pchSource.empty()) {
|
||||
|
@ -4304,6 +4304,20 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
|
||||
return list;
|
||||
}
|
||||
|
||||
std::vector<std::string> cmGeneratorTarget::GetPchArchs(
|
||||
std::string const& config, std::string const& lang) const
|
||||
{
|
||||
std::vector<std::string> pchArchs;
|
||||
if (!this->GetGlobalGenerator()->IsXcode()) {
|
||||
pchArchs = this->GetAppleArchs(config, lang);
|
||||
}
|
||||
if (pchArchs.size() < 2) {
|
||||
// We do not need per-arch PCH files when building for one architecture.
|
||||
pchArchs = { {} };
|
||||
}
|
||||
return pchArchs;
|
||||
}
|
||||
|
||||
std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
|
||||
const std::string& language,
|
||||
const std::string& arch) const
|
||||
|
@ -598,6 +598,8 @@ public:
|
||||
std::vector<BT<std::string>> GetPrecompileHeaders(
|
||||
const std::string& config, const std::string& language) const;
|
||||
|
||||
std::vector<std::string> GetPchArchs(std::string const& config,
|
||||
std::string const& lang) const;
|
||||
std::string GetPchHeader(const std::string& config,
|
||||
const std::string& language,
|
||||
const std::string& arch = std::string()) const;
|
||||
|
@ -2721,15 +2721,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> architectures;
|
||||
if (!this->GetGlobalGenerator()->IsXcode()) {
|
||||
architectures = target->GetAppleArchs(config, lang);
|
||||
}
|
||||
if (architectures.empty()) {
|
||||
architectures.emplace_back();
|
||||
} else {
|
||||
std::vector<std::string> pchArchs = target->GetPchArchs(config, lang);
|
||||
if (pchArchs.size() > 1) {
|
||||
std::string useMultiArchPch;
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
const std::string pchHeader =
|
||||
target->GetPchHeader(config, lang, arch);
|
||||
if (!pchHeader.empty()) {
|
||||
@ -2746,7 +2741,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
const std::string pchSource = target->GetPchSource(config, lang, arch);
|
||||
const std::string pchHeader = target->GetPchHeader(config, lang, arch);
|
||||
|
||||
|
@ -672,15 +672,12 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
|
||||
std::string const configUpper = cmSystemTools::UpperCase(config);
|
||||
|
||||
// Add precompile headers dependencies
|
||||
std::vector<std::string> architectures =
|
||||
this->GeneratorTarget->GetAppleArchs(config, lang);
|
||||
if (architectures.empty()) {
|
||||
architectures.emplace_back();
|
||||
}
|
||||
std::vector<std::string> pchArchs =
|
||||
this->GeneratorTarget->GetPchArchs(config, lang);
|
||||
|
||||
std::string filterArch;
|
||||
std::unordered_map<std::string, std::string> pchSources;
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
const std::string pchSource =
|
||||
this->GeneratorTarget->GetPchSource(config, lang, arch);
|
||||
if (pchSource == source.GetFullPath()) {
|
||||
@ -692,7 +689,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
|
||||
}
|
||||
|
||||
if (!pchSources.empty() && !source.GetProperty("SKIP_PRECOMPILE_HEADERS")) {
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
std::string const& pchHeader =
|
||||
this->GeneratorTarget->GetPchHeader(config, lang, arch);
|
||||
depends.push_back(pchHeader);
|
||||
|
@ -189,14 +189,11 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
|
||||
const std::string& config, const std::string& objectFileName)
|
||||
{
|
||||
std::unordered_map<std::string, std::string> pchSources;
|
||||
std::vector<std::string> architectures =
|
||||
this->GeneratorTarget->GetAppleArchs(config, language);
|
||||
if (architectures.empty()) {
|
||||
architectures.emplace_back();
|
||||
}
|
||||
std::vector<std::string> pchArchs =
|
||||
this->GeneratorTarget->GetPchArchs(config, language);
|
||||
|
||||
std::string filterArch;
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
const std::string pchSource =
|
||||
this->GeneratorTarget->GetPchSource(config, language, arch);
|
||||
if (pchSource == source->GetFullPath()) {
|
||||
@ -1500,14 +1497,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
|
||||
// Add precompile headers dependencies
|
||||
std::vector<std::string> depList;
|
||||
|
||||
std::vector<std::string> architectures =
|
||||
this->GeneratorTarget->GetAppleArchs(config, language);
|
||||
if (architectures.empty()) {
|
||||
architectures.emplace_back();
|
||||
}
|
||||
std::vector<std::string> pchArchs =
|
||||
this->GeneratorTarget->GetPchArchs(config, language);
|
||||
|
||||
std::unordered_set<std::string> pchSources;
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
const std::string pchSource =
|
||||
this->GeneratorTarget->GetPchSource(config, language, arch);
|
||||
|
||||
@ -1517,7 +1511,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
|
||||
}
|
||||
|
||||
if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
|
||||
for (const std::string& arch : architectures) {
|
||||
for (const std::string& arch : pchArchs) {
|
||||
depList.push_back(
|
||||
this->GeneratorTarget->GetPchHeader(config, language, arch));
|
||||
if (pchSources.find(source->GetFullPath()) == pchSources.end()) {
|
||||
|
Loading…
Reference in New Issue
Block a user