Build object library targets in Ninja

Treat OBJECT libraries as STATIC libraries but leave out the archive
step.  The object files will be left behind for reference by other
targets later.
This commit is contained in:
Brad King 2012-03-13 10:05:07 -04:00
parent f5b06cda0f
commit 61124de4c0
4 changed files with 39 additions and 7 deletions

View File

@ -664,6 +664,7 @@ cmGlobalNinjaGenerator
target->GetFullPath(configName).c_str())); target->GetFullPath(configName).c_str()));
break; break;
case cmTarget::OBJECT_LIBRARY:
case cmTarget::UTILITY: { case cmTarget::UTILITY: {
std::string path = ng->ConvertToNinjaPath( std::string path = ng->ConvertToNinjaPath(
target->GetMakefile()->GetStartOutputDirectory()); target->GetMakefile()->GetStartOutputDirectory());

View File

@ -43,10 +43,13 @@ cmNinjaNormalTargetGenerator(cmTarget* target)
this->TargetNamePDB, this->TargetNamePDB,
GetLocalGenerator()->GetConfigName()); GetLocalGenerator()->GetConfigName());
if(target->GetType() != cmTarget::OBJECT_LIBRARY)
{
// on Windows the output dir is already needed at compile time // on Windows the output dir is already needed at compile time
// ensure the directory exists (OutDir test) // ensure the directory exists (OutDir test)
std::string outpath = target->GetDirectory(this->GetConfigName()); std::string outpath = target->GetDirectory(this->GetConfigName());
cmSystemTools::MakeDirectory(outpath.c_str()); cmSystemTools::MakeDirectory(outpath.c_str());
}
} }
cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
@ -67,8 +70,15 @@ void cmNinjaNormalTargetGenerator::Generate()
// Write the build statements // Write the build statements
this->WriteObjectBuildStatements(); this->WriteObjectBuildStatements();
if(this->GetTarget()->GetType() == cmTarget::OBJECT_LIBRARY)
{
this->WriteObjectLibStatement();
}
else
{
this->WriteLinkRule(); this->WriteLinkRule();
this->WriteLinkStatement(); this->WriteLinkStatement();
}
this->GetBuildFileStream() << "\n"; this->GetBuildFileStream() << "\n";
this->GetRulesFileStream() << "\n"; this->GetRulesFileStream() << "\n";
@ -467,3 +477,21 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
this->GetTarget()); this->GetTarget());
} }
//----------------------------------------------------------------------------
void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
{
// Write a phony output that depends on all object files.
cmNinjaDeps outputs;
this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
cmNinjaDeps depends = this->GetObjects();
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(),
"Object library "
+ this->GetTargetName(),
outputs,
depends);
// Add aliases for the target name.
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
this->GetTarget());
}

View File

@ -32,6 +32,7 @@ private:
void WriteLanguagesRules(); void WriteLanguagesRules();
void WriteLinkRule(); void WriteLinkRule();
void WriteLinkStatement(); void WriteLinkStatement();
void WriteObjectLibStatement();
std::vector<std::string> ComputeLinkCmd(); std::vector<std::string> ComputeLinkCmd();
private: private:

View File

@ -34,6 +34,7 @@ cmNinjaTargetGenerator::New(cmTarget* target)
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
case cmTarget::OBJECT_LIBRARY:
return new cmNinjaNormalTargetGenerator(target); return new cmNinjaNormalTargetGenerator(target);
case cmTarget::UTILITY: case cmTarget::UTILITY:
@ -221,7 +222,8 @@ ComputeDefines(cmSourceFile *source, const std::string& language)
cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
{ {
// Static libraries never depend on other targets for linking. // Static libraries never depend on other targets for linking.
if (this->Target->GetType() == cmTarget::STATIC_LIBRARY) if (this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
return cmNinjaDeps(); return cmNinjaDeps();
cmComputeLinkInformation* cli = cmComputeLinkInformation* cli =