Build object library targets in VS

Treat OBJECT libraries as STATIC libraries.  The VS project file format
provides no way to avoid running the librarian so hide the resulting
.lib away next to the object files as it should never be referenced.
The object files will be left behind for reference by other targets
later.
This commit is contained in:
Brad King 2012-03-12 10:55:07 -04:00
parent 3aa741acb6
commit 3a53005f7d
3 changed files with 76 additions and 21 deletions

View File

@ -127,6 +127,7 @@ void cmLocalVisualStudio6Generator::OutputDSPFile()
switch(l->second.GetType()) switch(l->second.GetType())
{ {
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
case cmTarget::OBJECT_LIBRARY:
this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second); this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
break; break;
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
@ -1240,8 +1241,18 @@ void cmLocalVisualStudio6Generator
outputNameMinSizeRel = target.GetFullName("MinSizeRel"); outputNameMinSizeRel = target.GetFullName("MinSizeRel");
outputNameRelWithDebInfo = target.GetFullName("RelWithDebInfo"); outputNameRelWithDebInfo = target.GetFullName("RelWithDebInfo");
} }
else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
{
outputName = target.GetName();
outputName += ".lib";
outputNameDebug = outputName;
outputNameRelease = outputName;
outputNameMinSizeRel = outputName;
outputNameRelWithDebInfo = outputName;
}
// Compute the output directory for the target. // Compute the output directory for the target.
std::string outputDirOld;
std::string outputDirDebug; std::string outputDirDebug;
std::string outputDirRelease; std::string outputDirRelease;
std::string outputDirMinSizeRel; std::string outputDirMinSizeRel;
@ -1251,6 +1262,11 @@ void cmLocalVisualStudio6Generator
target.GetType() == cmTarget::SHARED_LIBRARY || target.GetType() == cmTarget::SHARED_LIBRARY ||
target.GetType() == cmTarget::MODULE_LIBRARY) target.GetType() == cmTarget::MODULE_LIBRARY)
{ {
#ifdef CM_USE_OLD_VS6
outputDirOld =
removeQuotes(this->ConvertToOptionallyRelativeOutputPath
(target.GetDirectory().c_str()));
#endif
outputDirDebug = outputDirDebug =
removeQuotes(this->ConvertToOptionallyRelativeOutputPath( removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
target.GetDirectory("Debug").c_str())); target.GetDirectory("Debug").c_str()));
@ -1264,6 +1280,14 @@ void cmLocalVisualStudio6Generator
removeQuotes(this->ConvertToOptionallyRelativeOutputPath( removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
target.GetDirectory("RelWithDebInfo").c_str())); target.GetDirectory("RelWithDebInfo").c_str()));
} }
else if(target.GetType() == cmTarget::OBJECT_LIBRARY)
{
std::string outputDir = cmake::GetCMakeFilesDirectoryPostSlash();
outputDirDebug = outputDir + "Debug";
outputDirRelease = outputDir + "Release";
outputDirMinSizeRel = outputDir + "MinSizeRel";
outputDirRelWithDebInfo = outputDir + "RelWithDebInfo";
}
// Compute the proper link information for the target. // Compute the proper link information for the target.
std::string optionsDebug; std::string optionsDebug;
@ -1432,7 +1456,8 @@ void cmLocalVisualStudio6Generator
libnameExports.c_str()); libnameExports.c_str());
cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG", cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
mfcFlag); mfcFlag);
if(target.GetType() == cmTarget::STATIC_LIBRARY ) if(target.GetType() == cmTarget::STATIC_LIBRARY ||
target.GetType() == cmTarget::OBJECT_LIBRARY)
{ {
cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_DEBUG", cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_DEBUG",
staticLibOptionsDebug.c_str()); staticLibOptionsDebug.c_str());
@ -1531,7 +1556,7 @@ void cmLocalVisualStudio6Generator
(exePath.c_str())).c_str()); (exePath.c_str())).c_str());
#endif #endif
if(targetBuilds) if(targetBuilds || target.GetType() == cmTarget::OBJECT_LIBRARY)
{ {
cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_DEBUG", cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_DEBUG",
outputDirDebug.c_str()); outputDirDebug.c_str());
@ -1541,13 +1566,11 @@ void cmLocalVisualStudio6Generator
outputDirMinSizeRel.c_str()); outputDirMinSizeRel.c_str());
cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELWITHDEBINFO", cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELWITHDEBINFO",
outputDirRelWithDebInfo.c_str()); outputDirRelWithDebInfo.c_str());
#ifdef CM_USE_OLD_VS6 if(!outputDirOld.empty())
std::string outPath = target.GetDirectory(); {
cmSystemTools::ReplaceString cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY",
(line, "OUTPUT_DIRECTORY", outputDirOld.c_str());
removeQuotes(this->ConvertToOptionallyRelativeOutputPath }
(outPath.c_str())).c_str());
#endif
} }
cmSystemTools::ReplaceString(line, cmSystemTools::ReplaceString(line,

View File

@ -642,6 +642,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
bool targetBuilds = true; bool targetBuilds = true;
switch(target.GetType()) switch(target.GetType())
{ {
case cmTarget::OBJECT_LIBRARY:
targetBuilds = false; // TODO: PDB for object library?
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
projectType = "typeStaticLibrary"; projectType = "typeStaticLibrary";
configType = "4"; configType = "4";
@ -1001,6 +1003,22 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
} }
switch(target.GetType()) switch(target.GetType())
{ {
case cmTarget::OBJECT_LIBRARY:
{
std::string libpath = this->GetTargetDirectory(target);
libpath += "/";
libpath += configName;
libpath += "/";
libpath += target.GetName();
libpath += ".lib";
const char* tool =
this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
fout << "\t\t\t<Tool\n"
<< "\t\t\t\tName=\"" << tool << "\"\n";
fout << "\t\t\t\tOutputFile=\""
<< this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
break;
}
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
{ {
std::string targetNameFull = target.GetFullName(configName); std::string targetNameFull = target.GetFullName(configName);

View File

@ -148,7 +148,7 @@ void cmVisualStudio10TargetGenerator::Generate()
this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str()); this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
this->Target->SetProperty("GENERATOR_FILE_NAME_EXT", this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
".vcxproj"); ".vcxproj");
if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY) if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
{ {
if(!this->ComputeClOptions()) if(!this->ComputeClOptions())
{ {
@ -359,6 +359,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
configType += "DynamicLibrary"; configType += "DynamicLibrary";
break; break;
case cmTarget::OBJECT_LIBRARY:
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
configType += "StaticLibrary"; configType += "StaticLibrary";
break; break;
@ -389,7 +390,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
mfcLine += useOfMfcValue + "</UseOfMfc>\n"; mfcLine += useOfMfcValue + "</UseOfMfc>\n";
this->WriteString(mfcLine.c_str(), 2); this->WriteString(mfcLine.c_str(), 2);
if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY && if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
this->ClOptions[*i]->UsingUnicode() || this->ClOptions[*i]->UsingUnicode() ||
this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
{ {
@ -1006,20 +1007,29 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
} }
else else
{ {
std::string targetNameFull =
this->Target->GetFullName(config->c_str());
std::string intermediateDir = this->LocalGenerator-> std::string intermediateDir = this->LocalGenerator->
GetTargetDirectory(*this->Target); GetTargetDirectory(*this->Target);
intermediateDir += "/"; intermediateDir += "/";
intermediateDir += *config; intermediateDir += *config;
intermediateDir += "/"; intermediateDir += "/";
std::string outDir;
std::string targetNameFull;
if(ttype == cmTarget::OBJECT_LIBRARY)
{
outDir = intermediateDir;
targetNameFull = this->Target->GetName();
targetNameFull += ".lib";
}
else
{
outDir = this->Target->GetDirectory(config->c_str()) + "/";
targetNameFull = this->Target->GetFullName(config->c_str());
}
this->ConvertToWindowsSlash(intermediateDir); this->ConvertToWindowsSlash(intermediateDir);
std::string outDir = this->Target->GetDirectory(config->c_str());
this->ConvertToWindowsSlash(outDir); this->ConvertToWindowsSlash(outDir);
this->WritePlatformConfigTag("OutDir", config->c_str(), 3); this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
*this->BuildFileStream << outDir *this->BuildFileStream << outDir
<< "\\"
<< "</OutDir>\n"; << "</OutDir>\n";
this->WritePlatformConfigTag("IntDir", config->c_str(), 3); this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
@ -1253,11 +1263,15 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
*this->BuildFileStream << configName *this->BuildFileStream << configName
<< "</AssemblerListingLocation>\n"; << "</AssemblerListingLocation>\n";
this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3); this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
this->WriteString("<ProgramDataBaseFileName>", 3); if(this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
*this->BuildFileStream << this->Target->GetDirectory(configName.c_str()) {
<< "/" // TODO: PDB for object library?
<< this->Target->GetPDBName(configName.c_str()) this->WriteString("<ProgramDataBaseFileName>", 3);
<< "</ProgramDataBaseFileName>\n"; *this->BuildFileStream << this->Target->GetDirectory(configName.c_str())
<< "/"
<< this->Target->GetPDBName(configName.c_str())
<< "</ProgramDataBaseFileName>\n";
}
this->WriteString("</ClCompile>\n", 2); this->WriteString("</ClCompile>\n", 2);
} }
@ -1568,7 +1582,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1); this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
*this->BuildFileStream << "\n"; *this->BuildFileStream << "\n";
// output cl compile flags <ClCompile></ClCompile> // output cl compile flags <ClCompile></ClCompile>
if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY) if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
{ {
this->WriteClOptions(*i, includes); this->WriteClOptions(*i, includes);
// output rc compile flags <ResourceCompile></ResourceCompile> // output rc compile flags <ResourceCompile></ResourceCompile>