summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-03-13 10:05:07 -0400
committerBrad King <brad.king@kitware.com>2012-03-16 10:18:36 -0400
commit61124de4c06b1195e79ee71326b902baf23c4c32 (patch)
tree827dc5df380c74bb7ea8186fcc63d446b5fd31c5
parentf5b06cda0f187929ac68ed64595c22d4e6ec773c (diff)
downloadcmake-61124de4c06b1195e79ee71326b902baf23c4c32.tar.gz
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.
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx1
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx40
-rw-r--r--Source/cmNinjaNormalTargetGenerator.h1
-rw-r--r--Source/cmNinjaTargetGenerator.cxx4
4 files changed, 39 insertions, 7 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 03c8be963b..9cbd502333 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -664,6 +664,7 @@ cmGlobalNinjaGenerator
target->GetFullPath(configName).c_str()));
break;
+ case cmTarget::OBJECT_LIBRARY:
case cmTarget::UTILITY: {
std::string path = ng->ConvertToNinjaPath(
target->GetMakefile()->GetStartOutputDirectory());
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 92421815a5..685944582b 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -43,10 +43,13 @@ cmNinjaNormalTargetGenerator(cmTarget* target)
this->TargetNamePDB,
GetLocalGenerator()->GetConfigName());
- // on Windows the output dir is already needed at compile time
- // ensure the directory exists (OutDir test)
- std::string outpath = target->GetDirectory(this->GetConfigName());
- cmSystemTools::MakeDirectory(outpath.c_str());
+ if(target->GetType() != cmTarget::OBJECT_LIBRARY)
+ {
+ // on Windows the output dir is already needed at compile time
+ // ensure the directory exists (OutDir test)
+ std::string outpath = target->GetDirectory(this->GetConfigName());
+ cmSystemTools::MakeDirectory(outpath.c_str());
+ }
}
cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
@@ -67,8 +70,15 @@ void cmNinjaNormalTargetGenerator::Generate()
// Write the build statements
this->WriteObjectBuildStatements();
- this->WriteLinkRule();
- this->WriteLinkStatement();
+ if(this->GetTarget()->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ this->WriteObjectLibStatement();
+ }
+ else
+ {
+ this->WriteLinkRule();
+ this->WriteLinkStatement();
+ }
this->GetBuildFileStream() << "\n";
this->GetRulesFileStream() << "\n";
@@ -467,3 +477,21 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
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());
+}
diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h
index 99f5a133b6..1702cafe85 100644
--- a/Source/cmNinjaNormalTargetGenerator.h
+++ b/Source/cmNinjaNormalTargetGenerator.h
@@ -32,6 +32,7 @@ private:
void WriteLanguagesRules();
void WriteLinkRule();
void WriteLinkStatement();
+ void WriteObjectLibStatement();
std::vector<std::string> ComputeLinkCmd();
private:
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index cc67434872..2a784056a7 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -34,6 +34,7 @@ cmNinjaTargetGenerator::New(cmTarget* target)
case cmTarget::SHARED_LIBRARY:
case cmTarget::STATIC_LIBRARY:
case cmTarget::MODULE_LIBRARY:
+ case cmTarget::OBJECT_LIBRARY:
return new cmNinjaNormalTargetGenerator(target);
case cmTarget::UTILITY:
@@ -221,7 +222,8 @@ ComputeDefines(cmSourceFile *source, const std::string& language)
cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
{
// 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();
cmComputeLinkInformation* cli =