mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 02:17:27 +08:00
VisualStudio: move PCH rules to projects when possible.
This dramatically helps reduce the size of the solution files when PCH is enabled, since 2 entries per source file are removed. This also corrects a subtle issue where when UNITY + PCH was enabled, the PCH would not be used if a user explicitly tried to compile a source file from outside the unity group. This is possible via the compile source option in the Visual Studio GUI.
This commit is contained in:
@@ -2402,27 +2402,28 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
|||||||
configDefines += *ccdefs;
|
configDefines += *ccdefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add precompile headers compile options.
|
// We have pch state in the following situation:
|
||||||
std::string customAndPchOptions = options;
|
// 1. We have SKIP_PRECOMPILE_HEADERS == true
|
||||||
|
// 2. We are creating the pre-compiled header
|
||||||
|
// 3. We are a different language than the linker language AND pch is
|
||||||
|
// enabled
|
||||||
const std::string pchSource =
|
const std::string pchSource =
|
||||||
this->GeneratorTarget->GetPchSource(config, lang);
|
this->GeneratorTarget->GetPchSource(config, lang);
|
||||||
if (!pchSource.empty() && !sf.GetProperty("SKIP_PRECOMPILE_HEADERS")) {
|
const bool skipPCH =
|
||||||
std::string pchOptions;
|
pchSource.empty() || sf.GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS");
|
||||||
if (sf.GetFullPath() == pchSource) {
|
const bool makePCH = (sf.GetFullPath() == pchSource);
|
||||||
pchOptions =
|
const bool useSharedPCH =
|
||||||
this->GeneratorTarget->GetPchCreateCompileOptions(config, lang);
|
!skipPCH && (lang == this->GeneratorTarget->GetLinkerLanguage(config));
|
||||||
} else {
|
const bool useDifferentLangPCH =
|
||||||
pchOptions =
|
!skipPCH && (lang != this->GeneratorTarget->GetLinkerLanguage(config));
|
||||||
this->GeneratorTarget->GetPchUseCompileOptions(config, lang);
|
const bool needsPCHFlags =
|
||||||
}
|
(makePCH || useSharedPCH || useDifferentLangPCH);
|
||||||
customAndPchOptions = cmStrCat(customAndPchOptions, ';', pchOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have flags or defines for this config then
|
// if we have flags or defines for this config then
|
||||||
// use them
|
// use them
|
||||||
if (!flags.empty() || !options.empty() || !configDefines.empty() ||
|
if (!flags.empty() || !options.empty() || !configDefines.empty() ||
|
||||||
!includes.empty() || compileAs || noWinRT ||
|
!includes.empty() || compileAs || noWinRT || !options.empty() ||
|
||||||
!customAndPchOptions.empty()) {
|
needsPCHFlags) {
|
||||||
cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
|
cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
|
||||||
cmIDEFlagTable const* flagtable = nullptr;
|
cmIDEFlagTable const* flagtable = nullptr;
|
||||||
const std::string& srclang = source->GetLanguage();
|
const std::string& srclang = source->GetLanguage();
|
||||||
@@ -2455,15 +2456,35 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
|||||||
} else {
|
} else {
|
||||||
clOptions.Parse(flags);
|
clOptions.Parse(flags);
|
||||||
}
|
}
|
||||||
if (!customAndPchOptions.empty()) {
|
|
||||||
|
if (needsPCHFlags) {
|
||||||
|
// Add precompile headers compile options.
|
||||||
|
std::string expandedOptions;
|
||||||
|
std::string pchOptions;
|
||||||
|
if (makePCH) {
|
||||||
|
pchOptions =
|
||||||
|
this->GeneratorTarget->GetPchCreateCompileOptions(config, lang);
|
||||||
|
} else if (useSharedPCH) {
|
||||||
|
std::string pchHeader =
|
||||||
|
this->GeneratorTarget->GetPchHeader(config, lang);
|
||||||
|
clOptions.AddFlag("ForcedIncludeFiles", pchHeader);
|
||||||
|
} else if (useDifferentLangPCH) {
|
||||||
|
pchOptions =
|
||||||
|
this->GeneratorTarget->GetPchUseCompileOptions(config, lang);
|
||||||
|
}
|
||||||
|
this->LocalGenerator->AppendCompileOptions(expandedOptions,
|
||||||
|
pchOptions);
|
||||||
|
clOptions.Parse(expandedOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.empty()) {
|
||||||
std::string expandedOptions;
|
std::string expandedOptions;
|
||||||
if (configDependentOptions) {
|
if (configDependentOptions) {
|
||||||
this->LocalGenerator->AppendCompileOptions(
|
this->LocalGenerator->AppendCompileOptions(
|
||||||
expandedOptions,
|
expandedOptions,
|
||||||
genexInterpreter.Evaluate(customAndPchOptions, "COMPILE_OPTIONS"));
|
genexInterpreter.Evaluate(options, "COMPILE_OPTIONS"));
|
||||||
} else {
|
} else {
|
||||||
this->LocalGenerator->AppendCompileOptions(expandedOptions,
|
this->LocalGenerator->AppendCompileOptions(expandedOptions, options);
|
||||||
customAndPchOptions);
|
|
||||||
}
|
}
|
||||||
clOptions.Parse(expandedOptions);
|
clOptions.Parse(expandedOptions);
|
||||||
}
|
}
|
||||||
@@ -2786,6 +2807,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
|
|||||||
this->GeneratorTarget->GetPchHeader(configName, linkLanguage);
|
this->GeneratorTarget->GetPchHeader(configName, linkLanguage);
|
||||||
if (this->MSTools && vcxproj == this->ProjectType && pchHeader.empty()) {
|
if (this->MSTools && vcxproj == this->ProjectType && pchHeader.empty()) {
|
||||||
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
|
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
|
||||||
|
} else if (this->MSTools && vcxproj == this->ProjectType &&
|
||||||
|
!pchHeader.empty()) {
|
||||||
|
clOptions.AddFlag("PrecompiledHeader", "Use");
|
||||||
|
clOptions.AddFlag("PrecompiledHeaderFile", pchHeader);
|
||||||
|
std::string pchFile =
|
||||||
|
this->GeneratorTarget->GetPchFile(configName, linkLanguage);
|
||||||
|
clOptions.AddFlag("PrecompiledHeaderOutputFile", pchFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get preprocessor definitions for this directory.
|
// Get preprocessor definitions for this directory.
|
||||||
|
Reference in New Issue
Block a user