Merge topic 'ninja-target-pdb-cleanup'

709fa59 Ninja: remove GetTargetPDB because it is used only once
4bb4787 Ninja:split out setting of msvc TARGET_PDB
59cbc28 Ninja: prepare msvc pdb cleanup
This commit is contained in:
David Cole 2012-08-24 14:24:35 -04:00 committed by CMake Topic Stage
commit ed01420c23
3 changed files with 42 additions and 47 deletions

View File

@ -459,25 +459,16 @@ 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();
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
ConvertToNinjaPath(path.c_str()).c_str(),
cmLocalGenerator::SHELL);
EnsureParentDirectoryExists(path);
}
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.
@ -494,9 +485,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 +518,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"] =

View File

@ -292,23 +292,33 @@ std::string cmNinjaTargetGenerator::GetTargetName() const
return this->Target->GetName();
}
std::string cmNinjaTargetGenerator::GetTargetPDB() const
bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) 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)
cmMakefile* mf = this->GetMakefile();
if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID"))
{
targetFullPathPDB = this->Target->GetDirectory(this->GetConfigName());
targetFullPathPDB += "/";
targetFullPathPDB += this->Target->GetPDBName(this->GetConfigName());
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());
}
return targetFullPathPDB.c_str();
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
ConvertToNinjaPath(pdbPath.c_str()).c_str(),
cmLocalGenerator::SHELL);
EnsureParentDirectoryExists(pdbPath);
return true;
}
return false;
}
void
cmNinjaTargetGenerator
::WriteLanguageRules(const std::string& language)
@ -534,15 +544,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"))
{
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
ConvertToNinjaPath(GetTargetPDB().c_str()).c_str(),
cmLocalGenerator::SHELL);
}
this->SetMsvcTargetPdbVariable(vars);
if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
{
@ -638,14 +640,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()));
}

View File

@ -40,10 +40,12 @@ public:
virtual void Generate() = 0;
std::string GetTargetPDB() const;
std::string GetTargetName() const;
protected:
bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
cmGeneratedFileStream& GetBuildFileStream() const;
cmGeneratedFileStream& GetRulesFileStream() const;
@ -112,8 +114,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 :