summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx134
1 files changed, 116 insertions, 18 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 214e92c..d7c0611 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -4,7 +4,9 @@
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
+#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
+#include "cmCustomCommandLines.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionEvaluationFile.h"
@@ -38,15 +40,15 @@
#endif
#include <algorithm>
-#include <assert.h>
+#include <cassert>
+#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <memory>
#include <sstream>
-#include <stdio.h>
-#include <string.h>
#include <unordered_set>
#include <utility>
#include <vector>
@@ -649,8 +651,7 @@ void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
const std::string& name) const
{
- GeneratorTargetMap::const_iterator ti =
- this->GeneratorTargetSearchIndex.find(name);
+ auto ti = this->GeneratorTargetSearchIndex.find(name);
if (ti != this->GeneratorTargetSearchIndex.end()) {
return ti->second;
}
@@ -1757,8 +1758,7 @@ void cmLocalGenerator::AddLanguageFlagsForLinking(
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
const std::string& name) const
{
- GeneratorTargetMap::const_iterator imported =
- this->ImportedGeneratorTargets.find(name);
+ auto imported = this->ImportedGeneratorTargets.find(name);
if (imported != this->ImportedGeneratorTargets.end()) {
return imported->second;
}
@@ -1959,8 +1959,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
std::vector<std::string>& stds = langStdMap[lang];
- std::vector<std::string>::const_iterator stdIt =
- std::find(stds.begin(), stds.end(), standard);
+ auto stdIt = std::find(stds.begin(), stds.end(), standard);
if (stdIt == stds.end()) {
std::string e =
lang + "_STANDARD is set to invalid value '" + standard + "'";
@@ -1969,8 +1968,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
return;
}
- std::vector<std::string>::const_iterator defaultStdIt =
- std::find(stds.begin(), stds.end(), defaultStd);
+ auto defaultStdIt = std::find(stds.begin(), stds.end(), defaultStd);
if (defaultStdIt == stds.end()) {
std::string e = "CMAKE_" + lang +
"_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) +
@@ -2275,23 +2273,124 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target,
return;
}
+ const char* pchReuseFrom =
+ target->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
+
auto pch_sf = this->Makefile->GetOrCreateSource(
pchSource, false, cmSourceFileLocationKind::Known);
std::string pchFile = pchHeader;
if (!this->GetGlobalGenerator()->IsXcode()) {
+ if (!pchReuseFrom) {
+ target->AddSource(pchSource, true);
+ }
+
// Exclude the pch files from linking
if (this->Makefile->IsOn("CMAKE_LINK_PCH")) {
- cmSystemTools::ReplaceString(pchFile, (lang == "C" ? ".h" : ".hxx"),
- pchExtension);
- pch_sf->SetProperty("OBJECT_OUTPUTS", pchFile.c_str());
+
+ auto replaceExtension = [](const std::string& str,
+ const std::string& ext) -> std::string {
+ auto dot_pos = str.rfind('.');
+ std::string result;
+ if (dot_pos != std::string::npos) {
+ result = str.substr(0, dot_pos);
+ }
+ result += ext;
+ return result;
+ };
+
+ if (!pchReuseFrom) {
+ std::string pchSourceObj = target->GetPchFileObject(config, lang);
+
+ pchFile = replaceExtension(pchSourceObj, pchExtension);
+ pch_sf->SetProperty("OBJECT_OUTPUTS", pchFile.c_str());
+ } else {
+ auto reuseTarget =
+ this->GlobalGenerator->FindGeneratorTarget(pchReuseFrom);
+
+ if (this->Makefile->IsOn("CMAKE_PCH_COPY_COMPILE_PDB")) {
+
+ const std::string pdb_prefix =
+ this->GetGlobalGenerator()->IsMultiConfig()
+ ? cmStrCat(this->GlobalGenerator->GetCMakeCFGIntDir(), "/")
+ : "";
+
+ const std::string target_compile_pdb_dir =
+ cmStrCat(target->GetLocalGenerator()->GetCurrentBinaryDirectory(),
+ "/", target->GetName(), ".dir/");
+
+ const std::string copy_script =
+ cmStrCat(target_compile_pdb_dir, "copy_idb_pdb.cmake");
+ cmGeneratedFileStream file(copy_script);
+
+ file << "# CMake generated file\n";
+ for (auto extension : { ".pdb", ".idb" }) {
+ const std::string from_file = cmStrCat(
+ reuseTarget->GetLocalGenerator()->GetCurrentBinaryDirectory(),
+ "/", pchReuseFrom, ".dir/${PDB_PREFIX}", pchReuseFrom,
+ extension);
+
+ const std::string to_dir = cmStrCat(
+ target->GetLocalGenerator()->GetCurrentBinaryDirectory(), "/",
+ target->GetName(), ".dir/${PDB_PREFIX}");
+
+ file << "if (EXISTS \"" << from_file << "\")\n";
+ file << " file(COPY \"" << from_file << "\""
+ << " DESTINATION \"" << to_dir << "\")\n";
+ file << "endif()\n";
+ }
+
+ cmCustomCommandLines commandLines;
+ cmCustomCommandLine currentLine;
+ currentLine.push_back(cmSystemTools::GetCMakeCommand());
+ currentLine.push_back(cmStrCat("-DPDB_PREFIX=", pdb_prefix));
+ currentLine.push_back("-P");
+ currentLine.push_back(copy_script);
+ commandLines.push_back(std::move(currentLine));
+
+ const std::string no_main_dependency;
+ const std::vector<std::string> no_deps;
+ const char* no_message = "";
+ const char* no_current_dir = nullptr;
+ std::vector<std::string> no_byproducts;
+
+ std::vector<std::string> outputs;
+ outputs.push_back(cmStrCat(target_compile_pdb_dir, pdb_prefix,
+ pchReuseFrom, ".pdb"));
+
+ if (this->GetGlobalGenerator()->IsMultiConfig()) {
+ this->Makefile->AddCustomCommandToTarget(
+ target->GetName(), outputs, no_deps, commandLines,
+ cmTarget::PRE_BUILD, no_message, no_current_dir);
+ } else {
+ cmImplicitDependsList no_implicit_depends;
+ cmSourceFile* copy_rule = this->Makefile->AddCustomCommandToOutput(
+ outputs, no_byproducts, no_deps, no_main_dependency,
+ no_implicit_depends, commandLines, no_message, no_current_dir);
+
+ if (copy_rule) {
+ target->AddSource(copy_rule->ResolveFullPath());
+ }
+ }
+
+ target->Target->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
+ target_compile_pdb_dir.c_str());
+ }
+
+ std::string pchSourceObj = reuseTarget->GetPchFileObject(config, lang);
+
+ // Link to the pch object file
+ target->Target->SetProperty(
+ "LINK_FLAGS",
+ this->ConvertToOutputFormat(pchSourceObj, SHELL).c_str());
+
+ pchFile = replaceExtension(pchSourceObj, pchExtension);
+ }
} else {
pchFile += pchExtension;
pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str());
}
- target->AddSource(pchSource, true);
-
for (auto& str : { std::ref(useOptionList), std::ref(createOptionList) }) {
cmSystemTools::ReplaceString(str, "<PCH_HEADER>", pchHeader);
cmSystemTools::ReplaceString(str, "<PCH_FILE>", pchFile);
@@ -2867,8 +2966,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(
const std::string& sin, std::string const& dir_max)
{
// Look for an existing mapped name for this object file.
- std::map<std::string, std::string>::iterator it =
- this->UniqueObjectNamesMap.find(sin);
+ auto it = this->UniqueObjectNamesMap.find(sin);
// If no entry exists create one.
if (it == this->UniqueObjectNamesMap.end()) {