From 59cbc28b92bf0cd91f760985edcde625a6fbcf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Wed, 22 Aug 2012 12:26:56 +0200 Subject: [PATCH 1/3] Ninja: prepare msvc pdb cleanup --- Source/cmNinjaNormalTargetGenerator.cxx | 30 ++++++++++++------------- Source/cmNinjaTargetGenerator.cxx | 6 +++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index a923d6068..59db29564 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -459,23 +459,23 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } } - std::string path; if (!this->TargetNameImport.empty()) { - path = this->GetLocalGenerator()->ConvertToOutputFormat( - targetOutputImplib.c_str(), cmLocalGenerator::SHELL); - vars["TARGET_IMPLIB"] = path; - EnsureParentDirectoryExists(path); + const std::string impLibPath = this->GetLocalGenerator() + ->ConvertToOutputFormat(targetOutputImplib.c_str(), + cmLocalGenerator::SHELL); + vars["TARGET_IMPLIB"] = impLibPath; + EnsureParentDirectoryExists(impLibPath); } cmMakefile* mf = this->GetMakefile(); if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) { - path = this->GetTargetPDB(); + const std::string pdbPath = this->GetTargetPDB(); vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(path.c_str()).c_str(), + ConvertToNinjaPath(pdbPath.c_str()).c_str(), cmLocalGenerator::SHELL); - EnsureParentDirectoryExists(path); + EnsureParentDirectoryExists(pdbPath); } else { @@ -494,9 +494,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() if (mf->IsOn("CMAKE_COMPILER_IS_MINGW")) { - path = GetTarget()->GetSupportDirectory(); - vars["OBJECT_DIR"] = ConvertToNinjaPath(path.c_str()); - EnsureDirectoryExists(path); + const std::string objPath = GetTarget()->GetSupportDirectory(); + vars["OBJECT_DIR"] = ConvertToNinjaPath(objPath.c_str()); + EnsureDirectoryExists(objPath); // ar.exe can't handle backslashes in rsp files (implictly used by gcc) std::string& linkLibraries = vars["LINK_LIBRARIES"]; std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/'); @@ -527,10 +527,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for // the link commands. if (!preLinkCmdLines.empty()) { - path = this->GetLocalGenerator()->ConvertToOutputFormat( - this->GetMakefile()->GetHomeOutputDirectory(), - cmLocalGenerator::SHELL); - preLinkCmdLines.push_back("cd " + path); + const std::string homeOutDir = this->GetLocalGenerator() + ->ConvertToOutputFormat(this->GetMakefile()->GetHomeOutputDirectory(), + cmLocalGenerator::SHELL); + preLinkCmdLines.push_back("cd " + homeOutDir); } vars["PRE_LINK"] = diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b6bdfdcdf..328ca2d73 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -542,9 +542,11 @@ cmNinjaTargetGenerator if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) { + const std::string pdbPath = this->GetTargetPDB(); vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(GetTargetPDB().c_str()).c_str(), - cmLocalGenerator::SHELL); + ConvertToNinjaPath(pdbPath.c_str()).c_str(), + cmLocalGenerator::SHELL); + EnsureParentDirectoryExists(pdbPath); } if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS")) From 4bb4787780e51d18b9744f52bfa635818dd34ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Wed, 22 Aug 2012 12:37:55 +0200 Subject: [PATCH 2/3] Ninja:split out setting of msvc TARGET_PDB --- Source/cmNinjaNormalTargetGenerator.cxx | 11 +-------- Source/cmNinjaTargetGenerator.cxx | 31 ++++++++++++++----------- Source/cmNinjaTargetGenerator.h | 7 ++++-- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 59db29564..9dc860ee9 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -468,16 +468,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } cmMakefile* mf = this->GetMakefile(); - if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || - mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) - { - const std::string pdbPath = this->GetTargetPDB(); - vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(pdbPath.c_str()).c_str(), - cmLocalGenerator::SHELL); - EnsureParentDirectoryExists(pdbPath); - } - else + if (!this->SetMsvcTargetPdbVariable(vars)) { // It is common to place debug symbols at a specific place, // so we need a plain target name in the rule available. diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 328ca2d73..b89602e2f 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -311,6 +311,21 @@ std::string cmNinjaTargetGenerator::GetTargetPDB() const return targetFullPathPDB.c_str(); } +bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const +{ + cmMakefile* mf = this->GetMakefile(); + if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || + mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) + { + const std::string pdbPath = this->GetTargetPDB(); + vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( + ConvertToNinjaPath(pdbPath.c_str()).c_str(), + cmLocalGenerator::SHELL); + EnsureParentDirectoryExists(pdbPath); + return true; + } + return false; +} void cmNinjaTargetGenerator @@ -537,17 +552,7 @@ cmNinjaTargetGenerator vars["DEP_FILE"] = objectFileName + ".d";; EnsureParentDirectoryExists(objectFileName); - // TODO move to GetTargetPDB - cmMakefile* mf = this->GetMakefile(); - if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || - mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) - { - const std::string pdbPath = this->GetTargetPDB(); - vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - ConvertToNinjaPath(pdbPath.c_str()).c_str(), - cmLocalGenerator::SHELL); - EnsureParentDirectoryExists(pdbPath); - } + this->SetMsvcTargetPdbVariable(vars); if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS")) { @@ -643,14 +648,14 @@ cmNinjaTargetGenerator void cmNinjaTargetGenerator -::EnsureDirectoryExists(const std::string& dir) +::EnsureDirectoryExists(const std::string& dir) const { cmSystemTools::MakeDirectory(dir.c_str()); } void cmNinjaTargetGenerator -::EnsureParentDirectoryExists(const std::string& path) +::EnsureParentDirectoryExists(const std::string& path) const { EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str())); } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 84573cec2..0c52fc409 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -44,6 +44,9 @@ public: std::string GetTargetName() const; protected: + + bool SetMsvcTargetPdbVariable(cmNinjaVars&) const; + cmGeneratedFileStream& GetBuildFileStream() const; cmGeneratedFileStream& GetRulesFileStream() const; @@ -112,8 +115,8 @@ protected: // Helper to add flag for windows .def file. void AddModuleDefinitionFlag(std::string& flags); - void EnsureDirectoryExists(const std::string& dir); - void EnsureParentDirectoryExists(const std::string& path); + void EnsureDirectoryExists(const std::string& dir) const; + void EnsureParentDirectoryExists(const std::string& path) const; // write rules for Mac OS X Application Bundle content. struct MacOSXContentGeneratorType : From 709fa59562569b6c6a8244f5ba53b60ebf840a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Wed, 22 Aug 2012 12:42:16 +0200 Subject: [PATCH 3/3] Ninja: remove GetTargetPDB because it is used only once --- Source/cmNinjaTargetGenerator.cxx | 27 +++++++++++---------------- Source/cmNinjaTargetGenerator.h | 1 - 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b89602e2f..0256aa93e 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -295,21 +295,6 @@ std::string cmNinjaTargetGenerator::GetTargetName() const return this->Target->GetName(); } -std::string cmNinjaTargetGenerator::GetTargetPDB() const -{ - std::string targetFullPathPDB; - if(this->Target->GetType() == cmTarget::EXECUTABLE || - this->Target->GetType() == cmTarget::STATIC_LIBRARY || - this->Target->GetType() == cmTarget::SHARED_LIBRARY || - this->Target->GetType() == cmTarget::MODULE_LIBRARY) - { - targetFullPathPDB = this->Target->GetDirectory(this->GetConfigName()); - targetFullPathPDB += "/"; - targetFullPathPDB += this->Target->GetPDBName(this->GetConfigName()); - } - - return targetFullPathPDB.c_str(); -} bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const { @@ -317,7 +302,17 @@ bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) { - const std::string pdbPath = this->GetTargetPDB(); + std::string pdbPath; + if(this->Target->GetType() == cmTarget::EXECUTABLE || + this->Target->GetType() == cmTarget::STATIC_LIBRARY || + this->Target->GetType() == cmTarget::SHARED_LIBRARY || + this->Target->GetType() == cmTarget::MODULE_LIBRARY) + { + pdbPath = this->Target->GetDirectory(this->GetConfigName()); + pdbPath += "/"; + pdbPath += this->Target->GetPDBName(this->GetConfigName()); + } + vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( ConvertToNinjaPath(pdbPath.c_str()).c_str(), cmLocalGenerator::SHELL); diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 0c52fc409..cd20694b4 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -40,7 +40,6 @@ public: virtual void Generate() = 0; - std::string GetTargetPDB() const; std::string GetTargetName() const; protected: