Precompile headers: Add support for Visual Studio generators

Tested with Visual C++ 2017 on Windows.

Co-Author: Daniel Pfeifer <daniel@pfeifer-mail.de>
This commit is contained in:
Cristian Adam 2019-07-13 12:07:30 +02:00 committed by Brad King
parent 28be170fbc
commit 519606704e
3 changed files with 21 additions and 1 deletions

View File

@ -110,6 +110,13 @@ public:
bool IsIncludeExternalMSProjectSupported() const override { return true; } bool IsIncludeExternalMSProjectSupported() const override { return true; }
/** Get encoding used by generator for generated source files
*/
codecvt::Encoding GetMakefileEncoding() const override
{
return codecvt::ANSI;
}
class TargetSet : public std::set<cmGeneratorTarget const*> class TargetSet : public std::set<cmGeneratorTarget const*>
{ {
}; };

View File

@ -1320,6 +1320,8 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
const std::string& libName, const std::string& libName,
cmGeneratorTarget* target) cmGeneratorTarget* target)
{ {
this->AddPchDependencies(target, "");
std::vector<std::string> configs; std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs); this->Makefile->GetConfigurations(configs);

View File

@ -249,6 +249,8 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() == this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
this->Makefile->GetCurrentBinaryDirectory()); this->Makefile->GetCurrentBinaryDirectory());
this->LocalGenerator->AddPchDependencies(target, "");
} }
cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
@ -2145,6 +2147,9 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) { if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) {
this->OutputSourceSpecificFlags(e2, si.Source); this->OutputSourceSpecificFlags(e2, si.Source);
} }
if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) {
e2.Element("PrecompiledHeader", "NotUsing");
}
if (!exclude_configs.empty()) { if (!exclude_configs.empty()) {
this->WriteExcludeFromBuild(e2, exclude_configs); this->WriteExcludeFromBuild(e2, exclude_configs);
} }
@ -2626,6 +2631,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
this->IPOEnabledConfigurations.insert(configName); this->IPOEnabledConfigurations.insert(configName);
} }
// Precompile Headers
std::string pchHeader =
this->GeneratorTarget->GetPchHeader(configName, linkLanguage);
if (this->MSTools && vcxproj == this->ProjectType && pchHeader.empty()) {
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
}
// Get preprocessor definitions for this directory. // Get preprocessor definitions for this directory.
std::string defineFlags = this->Makefile->GetDefineFlags(); std::string defineFlags = this->Makefile->GetDefineFlags();
if (this->MSTools) { if (this->MSTools) {
@ -2641,7 +2653,6 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
// replace this setting with "true" below. // replace this setting with "true" below.
clOptions.AddFlag("UseFullPaths", "false"); clOptions.AddFlag("UseFullPaths", "false");
} }
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)"); clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)");
} }
} }