Build object library targets in Makefiles

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-12 10:54:37 -04:00
parent b87d7a60a0
commit 3aa741acb6
6 changed files with 58 additions and 14 deletions

View File

@ -411,6 +411,7 @@ void cmGlobalUnixMakefileGenerator3
(l->second.GetType() == cmTarget::STATIC_LIBRARY) || (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(l->second.GetType() == cmTarget::SHARED_LIBRARY) || (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(l->second.GetType() == cmTarget::MODULE_LIBRARY) || (l->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(l->second.GetType() == cmTarget::OBJECT_LIBRARY) ||
(l->second.GetType() == cmTarget::UTILITY)) (l->second.GetType() == cmTarget::UTILITY))
{ {
std::string tname = lg->GetRelativeTargetDirectory(l->second); std::string tname = lg->GetRelativeTargetDirectory(l->second);
@ -446,6 +447,7 @@ cmGlobalUnixMakefileGenerator3
(l->second.GetType() == cmTarget::STATIC_LIBRARY) || (l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(l->second.GetType() == cmTarget::SHARED_LIBRARY) || (l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(l->second.GetType() == cmTarget::MODULE_LIBRARY) || (l->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(l->second.GetType() == cmTarget::OBJECT_LIBRARY) ||
(l->second.GetType() == cmTarget::UTILITY)) (l->second.GetType() == cmTarget::UTILITY))
{ {
// Add this to the list of depends rules in this directory. // Add this to the list of depends rules in this directory.
@ -620,6 +622,7 @@ cmGlobalUnixMakefileGenerator3
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(t->second.GetType() == cmTarget::MODULE_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(t->second.GetType() == cmTarget::OBJECT_LIBRARY) ||
(t->second.GetType() == cmTarget::UTILITY))) (t->second.GetType() == cmTarget::UTILITY)))
{ {
// Add a rule to build the target by name. // Add a rule to build the target by name.
@ -706,6 +709,7 @@ cmGlobalUnixMakefileGenerator3
|| (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::STATIC_LIBRARY)
|| (t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY)
|| (t->second.GetType() == cmTarget::MODULE_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY)
|| (t->second.GetType() == cmTarget::OBJECT_LIBRARY)
|| (t->second.GetType() == cmTarget::UTILITY))) || (t->second.GetType() == cmTarget::UTILITY)))
{ {
std::string makefileName; std::string makefileName;
@ -1015,6 +1019,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(t->second.GetType() == cmTarget::MODULE_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(t->second.GetType() == cmTarget::OBJECT_LIBRARY) ||
(t->second.GetType() == cmTarget::GLOBAL_TARGET) || (t->second.GetType() == cmTarget::GLOBAL_TARGET) ||
(t->second.GetType() == cmTarget::UTILITY)) (t->second.GetType() == cmTarget::UTILITY))
{ {

View File

@ -358,6 +358,7 @@ void cmLocalUnixMakefileGenerator3
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(t->second.GetType() == cmTarget::MODULE_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(t->second.GetType() == cmTarget::OBJECT_LIBRARY) ||
(t->second.GetType() == cmTarget::UTILITY)) (t->second.GetType() == cmTarget::UTILITY))
{ {
emitted.insert(t->second.GetName()); emitted.insert(t->second.GetName());

View File

@ -101,6 +101,9 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
this->WriteModuleLibraryRules(true); this->WriteModuleLibraryRules(true);
} }
break; break;
case cmTarget::OBJECT_LIBRARY:
this->WriteObjectLibraryRules();
break;
default: default:
// If language is not known, this is an error. // If language is not known, this is an error.
cmSystemTools::Error("Unknown Library Type"); cmSystemTools::Error("Unknown Library Type");
@ -121,6 +124,29 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
this->CloseFileStreams(); this->CloseFileStreams();
} }
//----------------------------------------------------------------------------
void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
{
std::vector<std::string> commands;
std::vector<std::string> depends;
// Add post-build rules.
this->LocalGenerator->
AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
this->Target);
// Depend on the object files.
this->AppendObjectDepends(depends);
// Write the rule.
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
this->Target->GetName(),
depends, commands, true);
// Write the main driver rule to build everything in this target.
this->WriteTargetDriverRule(this->Target->GetName(), false);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules() void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
{ {

View File

@ -25,6 +25,7 @@ public:
virtual void WriteRuleFiles(); virtual void WriteRuleFiles();
protected: protected:
void WriteObjectLibraryRules();
void WriteStaticLibraryRules(); void WriteStaticLibraryRules();
void WriteSharedLibraryRules(bool relink); void WriteSharedLibraryRules(bool relink);
void WriteModuleLibraryRules(bool relink); void WriteModuleLibraryRules(bool relink);

View File

@ -65,6 +65,7 @@ cmMakefileTargetGenerator::New(cmTarget *tgt)
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
case cmTarget::OBJECT_LIBRARY:
result = new cmMakefileLibraryTargetGenerator(tgt); result = new cmMakefileLibraryTargetGenerator(tgt);
break; break;
case cmTarget::UTILITY: case cmTarget::UTILITY:
@ -1596,7 +1597,7 @@ void cmMakefileTargetGenerator
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileTargetGenerator void cmMakefileTargetGenerator
::AppendLinkDepends(std::vector<std::string>& depends) ::AppendObjectDepends(std::vector<std::string>& depends)
{ {
// Add dependencies on the compiled object files. // Add dependencies on the compiled object files.
std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath(); std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
@ -1609,19 +1610,6 @@ void cmMakefileTargetGenerator
depends.push_back(objTarget); depends.push_back(objTarget);
} }
// Add dependencies on targets that must be built first.
this->AppendTargetDepends(depends);
// Add a dependency on the rule file itself.
this->LocalGenerator->AppendRuleDepend(depends,
this->BuildFileNameFull.c_str());
// Add a dependency on the link definitions file, if any.
if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
{
depends.push_back(this->GeneratorTarget->ModuleDefinitionFile);
}
// Add dependencies on the external object files. // Add dependencies on the external object files.
for(std::vector<std::string>::const_iterator obj for(std::vector<std::string>::const_iterator obj
= this->ExternalObjects.begin(); = this->ExternalObjects.begin();
@ -1630,6 +1618,26 @@ void cmMakefileTargetGenerator
depends.push_back(*obj); depends.push_back(*obj);
} }
// Add a dependency on the rule file itself.
this->LocalGenerator->AppendRuleDepend(depends,
this->BuildFileNameFull.c_str());
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator
::AppendLinkDepends(std::vector<std::string>& depends)
{
this->AppendObjectDepends(depends);
// Add dependencies on targets that must be built first.
this->AppendTargetDepends(depends);
// Add a dependency on the link definitions file, if any.
if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
{
depends.push_back(this->GeneratorTarget->ModuleDefinitionFile);
}
// Add user-specified dependencies. // Add user-specified dependencies.
if(const char* linkDepends = if(const char* linkDepends =
this->Target->GetProperty("LINK_DEPENDS")) this->Target->GetProperty("LINK_DEPENDS"))

View File

@ -118,6 +118,9 @@ protected:
// append intertarget dependencies // append intertarget dependencies
void AppendTargetDepends(std::vector<std::string>& depends); void AppendTargetDepends(std::vector<std::string>& depends);
// Append object file dependencies.
void AppendObjectDepends(std::vector<std::string>& depends);
// Append link rule dependencies (objects, etc.). // Append link rule dependencies (objects, etc.).
void AppendLinkDepends(std::vector<std::string>& depends); void AppendLinkDepends(std::vector<std::string>& depends);