Merge topic 'cleanup-object-file-names'

0996f2a Hide Makefile local object info inside local generator
67734be VS: Simplify object name computation
4ae7f36 Remove unused partial OBJECT_FILES property implementation
This commit is contained in:
Brad King 2012-03-13 11:53:28 -04:00 committed by CMake Topic Stage
commit 1ee4b65a7f
18 changed files with 76 additions and 282 deletions

View File

@ -179,8 +179,6 @@ void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc"); mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1"); mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
// initialize Architectures so it can be used by
// GetTargetObjectFileDirectories
this->cmGlobalGenerator::EnableLanguage(lang, mf, optional); this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
const char* osxArch = const char* osxArch =
mf->GetDefinition("CMAKE_OSX_ARCHITECTURES"); mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
@ -3362,37 +3360,6 @@ std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
return ret; return ret;
} }
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::
GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs)
{
std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
dir += "/";
dir += this->CurrentMakefile->GetProjectName();
dir += ".build/";
dir += this->GetCMakeCFGInitDirectory();
dir += "/";
dir += target->GetName();
dir += ".build/Objects-normal/";
std::string dirsave = dir;
if(this->Architectures.size())
{
for(std::vector<std::string>::iterator i = this->Architectures.begin();
i != this->Architectures.end(); ++i)
{
dir += *i;
dirs.push_back(dir);
dir = dirsave;
}
}
else
{
dirs.push_back(dir);
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmGlobalXCodeGenerator cmGlobalXCodeGenerator

View File

@ -76,9 +76,6 @@ public:
///! What is the configurations directory variable called? ///! What is the configurations directory variable called?
virtual const char* GetCMakeCFGInitDirectory(); virtual const char* GetCMakeCFGInitDirectory();
void GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs);
void SetCurrentLocalGenerator(cmLocalGenerator*); void SetCurrentLocalGenerator(cmLocalGenerator*);
/** Return true if the generated build tree may contain multiple builds. /** Return true if the generated build tree may contain multiple builds.

View File

@ -2963,17 +2963,6 @@ cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
return ""; return "";
} }
//----------------------------------------------------------------------------
void
cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* ,
std::vector<std::string>&
)
{
cmSystemTools::Error("GetTargetObjectFileDirectories"
" called on cmLocalGenerator");
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
unsigned int cmLocalGenerator::GetBackwardsCompatibility() unsigned int cmLocalGenerator::GetBackwardsCompatibility()
{ {

View File

@ -261,14 +261,6 @@ public:
}; };
FortranFormat GetFortranFormat(const char* value); FortranFormat GetFortranFormat(const char* value);
/** Return the directories into which object files will be put.
* There maybe more than one for fat binary systems like OSX.
*/
virtual void
GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs);
/** /**
* Convert the given remote path to a relative path with respect to * Convert the given remote path to a relative path with respect to
* the given local path. The local path must be given in component * the given local path. The local path must be given in component

View File

@ -144,6 +144,20 @@ void cmLocalUnixMakefileGenerator3::Generate()
this->WriteDirectoryInformationFile(); this->WriteDirectoryInformationFile();
} }
//----------------------------------------------------------------------------
void cmLocalUnixMakefileGenerator3::AddLocalObjectFile(
cmTarget* target, cmSourceFile* sf, std::string objNoTargetDir,
bool hasSourceExtension)
{
if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str()))
{
objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
}
LocalObjectInfo& info = this->LocalObjectFiles[objNoTargetDir];
info.HasSourceExtension = hasSourceExtension;
info.push_back(LocalObjectEntry(target, sf->GetLanguage()));
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets
(std::vector<std::string>& targets) (std::vector<std::string>& targets)
@ -2267,14 +2281,3 @@ void cmLocalUnixMakefileGenerator3
} }
} }
} }
void cmLocalUnixMakefileGenerator3
::GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>& dirs)
{
std::string dir = this->Makefile->GetCurrentOutputDirectory();
dir += "/";
dir += this->GetTargetDirectory(*target);
dirs.push_back(dir);
}

View File

@ -225,24 +225,9 @@ public:
// write the target rules for the local Makefile into the stream // write the target rules for the local Makefile into the stream
void WriteLocalAllRules(std::ostream& ruleFileStream); void WriteLocalAllRules(std::ostream& ruleFileStream);
struct LocalObjectEntry void AddLocalObjectFile(cmTarget* target, cmSourceFile* sf,
{ std::string objNoTargetDir,
cmTarget* Target; bool hasSourceExtension);
std::string Language;
LocalObjectEntry(): Target(0), Language() {}
LocalObjectEntry(cmTarget* t, const char* lang):
Target(t), Language(lang) {}
};
struct LocalObjectInfo: public std::vector<LocalObjectEntry>
{
bool HasSourceExtension;
bool HasPreprocessRule;
bool HasAssembleRule;
LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
HasAssembleRule(false) {}
};
std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
{ return this->LocalObjectFiles;}
std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; } std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
@ -257,9 +242,6 @@ public:
{ {
return !this->SkipAssemblySourceRules; return !this->SkipAssemblySourceRules;
} }
// Get the directories into which the .o files will go for this target
void GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>& dirs);
// Fill the vector with the target names for the object files, // Fill the vector with the target names for the object files,
// preprocessed files and assembly files. Currently only used by the // preprocessed files and assembly files. Currently only used by the
@ -301,9 +283,6 @@ protected:
void WriteTargetRequiresRule(std::ostream& ruleFileStream, void WriteTargetRequiresRule(std::ostream& ruleFileStream,
cmTarget& target, cmTarget& target,
const std::vector<std::string>& objects); const std::vector<std::string>& objects);
void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
const char* comment, const char* output,
LocalObjectInfo const& info);
std::string GetObjectFileName(cmTarget& target, std::string GetObjectFileName(cmTarget& target,
const cmSourceFile& source, const cmSourceFile& source,
@ -378,7 +357,27 @@ private:
bool SkipPreprocessedSourceRules; bool SkipPreprocessedSourceRules;
bool SkipAssemblySourceRules; bool SkipAssemblySourceRules;
struct LocalObjectEntry
{
cmTarget* Target;
std::string Language;
LocalObjectEntry(): Target(0), Language() {}
LocalObjectEntry(cmTarget* t, const char* lang):
Target(t), Language(lang) {}
};
struct LocalObjectInfo: public std::vector<LocalObjectEntry>
{
bool HasSourceExtension;
bool HasPreprocessRule;
bool HasAssembleRule;
LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
HasAssembleRule(false) {}
};
std::map<cmStdString, LocalObjectInfo> LocalObjectFiles; std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
const char* comment, const char* output,
LocalObjectInfo const& info);
std::vector<cmStdString> LocalHelp; std::vector<cmStdString> LocalHelp;
/* does the work for each target */ /* does the work for each target */

View File

@ -337,7 +337,7 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
} }
// Compute which sources need unique object computation. // Compute which sources need unique object computation.
this->ComputeObjectNameRequirements(sourceGroups); this->ComputeObjectNameRequirements(classes);
// Write the DSP file's header. // Write the DSP file's header.
this->WriteDSPHeader(fout, libName, target, sourceGroups); this->WriteDSPHeader(fout, libName, target, sourceGroups);
@ -1795,17 +1795,6 @@ cmLocalVisualStudio6Generator
return ""; return "";
} }
void cmLocalVisualStudio6Generator
::GetTargetObjectFileDirectories(cmTarget* ,
std::vector<std::string>&
dirs)
{
std::string dir = this->Makefile->GetCurrentOutputDirectory();
dir += "/";
dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
dirs.push_back(dir);
}
std::string std::string
cmLocalVisualStudio6Generator cmLocalVisualStudio6Generator
::GetConfigName(std::string const& configuration) const ::GetConfigName(std::string const& configuration) const

View File

@ -50,9 +50,6 @@ public:
void SetBuildType(BuildType, const char* libName, cmTarget&); void SetBuildType(BuildType, const char* libName, cmTarget&);
virtual std::string GetTargetDirectory(cmTarget const& target) const; virtual std::string GetTargetDirectory(cmTarget const& target) const;
void GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs);
private: private:
std::string DSPHeaderTemplate; std::string DSPHeaderTemplate;
std::string DSPFooterTemplate; std::string DSPFooterTemplate;

View File

@ -1311,7 +1311,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
} }
// Compute which sources need unique object computation. // Compute which sources need unique object computation.
this->ComputeObjectNameRequirements(sourceGroups); this->ComputeObjectNameRequirements(classes);
// open the project // open the project
this->WriteProjectStart(fout, libName, target, sourceGroups); this->WriteProjectStart(fout, libName, target, sourceGroups);
@ -2118,19 +2118,6 @@ std::string cmLocalVisualStudio7Generator
return dir; return dir;
} }
void cmLocalVisualStudio7Generator::
GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs)
{
std::string dir = this->Makefile->GetCurrentOutputDirectory();
dir += "/";
dir += this->GetTargetDirectory(*target);
dir += "/";
dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
dirs.push_back(dir);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#include <windows.h> #include <windows.h>
static bool cmLVS6G_IsFAT(const char* dir) static bool cmLVS6G_IsFAT(const char* dir)

View File

@ -54,9 +54,6 @@ public:
void SetBuildType(BuildType,const char *name); void SetBuildType(BuildType,const char *name);
void SetPlatformName(const char* n) { this->PlatformName = n;} void SetPlatformName(const char* n) { this->PlatformName = n;}
void GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs);
void SetExtraFlagTable(cmVS7FlagTable const* table) void SetExtraFlagTable(cmVS7FlagTable const* table)
{ this->ExtraFlagTable = table; } { this->ExtraFlagTable = table; }

View File

@ -83,75 +83,48 @@ bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalVisualStudioGenerator::CountObjectNames( void
const std::vector<cmSourceGroup>& groups, cmLocalVisualStudioGenerator::ComputeObjectNameRequirements(
std::map<cmStdString, int>& counts) std::vector<cmSourceFile*> const& sources
{ )
for(unsigned int i = 0; i < groups.size(); ++i)
{
cmSourceGroup sg = groups[i];
std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
s != srcs.end(); ++s)
{
const cmSourceFile* sf = *s;
if(this->SourceFileCompiles(sf))
{
std::string objectName = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(
sf->GetFullPath()));
objectName += ".obj";
counts[objectName] += 1;
}
}
this->CountObjectNames(sg.GetGroupChildren(), counts);
}
}
//----------------------------------------------------------------------------
void cmLocalVisualStudioGenerator::InsertNeedObjectNames(
const std::vector<cmSourceGroup>& groups,
std::map<cmStdString, int>& count)
{
for(unsigned int i = 0; i < groups.size(); ++i)
{
cmSourceGroup sg = groups[i];
std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
s != srcs.end(); ++s)
{
const cmSourceFile* sf = *s;
if(this->SourceFileCompiles(sf))
{
std::string objectName = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
objectName += ".obj";
if(count[objectName] > 1)
{
this->NeedObjectName.insert(sf);
}
}
}
this->InsertNeedObjectNames(sg.GetGroupChildren(), count);
}
}
//----------------------------------------------------------------------------
void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
(std::vector<cmSourceGroup> const& sourceGroups)
{ {
// Clear the current set of requirements. // Clear the current set of requirements.
this->NeedObjectName.clear(); this->NeedObjectName.clear();
// Count the number of object files with each name. Note that // Count the number of object files with each name. Note that
// windows file names are not case sensitive. // windows file names are not case sensitive.
std::map<cmStdString, int> objectNameCounts; std::map<cmStdString, int> counts;
this->CountObjectNames(sourceGroups, objectNameCounts); for(std::vector<cmSourceFile*>::const_iterator s = sources.begin();
s != sources.end(); ++s)
{
const cmSourceFile* sf = *s;
if(this->SourceFileCompiles(sf))
{
std::string objectName = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(
sf->GetFullPath()));
objectName += ".obj";
counts[objectName] += 1;
}
}
// For all source files producing duplicate names we need unique // For all source files producing duplicate names we need unique
// object name computation. // object name computation.
this->InsertNeedObjectNames(sourceGroups, objectNameCounts); for(std::vector<cmSourceFile*>::const_iterator s = sources.begin();
s != sources.end(); ++s)
{
const cmSourceFile* sf = *s;
if(this->SourceFileCompiles(sf))
{
std::string objectName = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
objectName += ".obj";
if(counts[objectName] > 1)
{
this->NeedObjectName.insert(sf);
}
}
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -65,12 +65,8 @@ protected:
MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran); MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran);
// Safe object file name generation. // Safe object file name generation.
void ComputeObjectNameRequirements(std::vector<cmSourceGroup> const&); void ComputeObjectNameRequirements(std::vector<cmSourceFile*> const&);
bool SourceFileCompiles(const cmSourceFile* sf); bool SourceFileCompiles(const cmSourceFile* sf);
void CountObjectNames(const std::vector<cmSourceGroup>& groups,
std::map<cmStdString, int>& count);
void InsertNeedObjectNames(const std::vector<cmSourceGroup>& groups,
std::map<cmStdString, int>& count);
std::set<const cmSourceFile*> NeedObjectName; std::set<const cmSourceFile*> NeedObjectName;
friend class cmVisualStudio10TargetGenerator; friend class cmVisualStudio10TargetGenerator;

View File

@ -33,16 +33,3 @@ cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const
// No per-target directory for this generator (yet). // No per-target directory for this generator (yet).
return ""; return "";
} }
//----------------------------------------------------------------------------
void cmLocalXCodeGenerator::
GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs)
{
cmGlobalXCodeGenerator* g =
(cmGlobalXCodeGenerator*)this->GetGlobalGenerator();
g->SetCurrentLocalGenerator(this);
g->GetTargetObjectFileDirectories(target,
dirs);
}

View File

@ -27,9 +27,6 @@ public:
cmLocalXCodeGenerator(); cmLocalXCodeGenerator();
virtual ~cmLocalXCodeGenerator(); virtual ~cmLocalXCodeGenerator();
void GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>&
dirs);
virtual std::string GetTargetDirectory(cmTarget const& target) const; virtual std::string GetTargetDirectory(cmTarget const& target) const;
private: private:

View File

@ -489,16 +489,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
srcFullPath.c_str()); srcFullPath.c_str());
// add this to the list of objects for this local generator // add this to the list of objects for this local generator
if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str())) this->LocalGenerator->AddLocalObjectFile(
{ this->Target, &source, objNoTargetDir, hasSourceExtension);
objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
}
cmLocalUnixMakefileGenerator3::LocalObjectInfo& info =
this->LocalGenerator->LocalObjectFiles[objNoTargetDir];
info.HasSourceExtension = hasSourceExtension;
info.push_back(
cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -1101,17 +1101,6 @@ void cmTarget::DefineProperties(cmake *cm)
"better if VS_GLOBAL_QtVersion is set to the version " "better if VS_GLOBAL_QtVersion is set to the version "
"FindQt4.cmake found. For example, \"4.7.3\""); "FindQt4.cmake found. For example, \"4.7.3\"");
#if 0
cm->DefineProperty
("OBJECT_FILES", cmProperty::TARGET,
"Used to get the resulting list of object files that make up a "
"target.",
"This can be used to put object files from one library "
"into another library. It is a read only property. It "
"converts the source list for the target into a list of full "
"paths to object names that will be produced by the target.");
#endif
#define CM_TARGET_FILE_TYPES_DOC \ #define CM_TARGET_FILE_TYPES_DOC \
"There are three kinds of target files that may be built: " \ "There are three kinds of target files that may be built: " \
"archive, library, and runtime. " \ "archive, library, and runtime. " \
@ -2612,54 +2601,6 @@ const char *cmTarget::GetProperty(const char* prop)
return this->GetProperty(prop, cmProperty::TARGET); return this->GetProperty(prop, cmProperty::TARGET);
} }
//----------------------------------------------------------------------------
void cmTarget::ComputeObjectFiles()
{
if (this->IsImported())
{
return;
}
#if 0
std::vector<std::string> dirs;
this->Makefile->GetLocalGenerator()->
GetTargetObjectFileDirectories(this,
dirs);
std::string objectFiles;
std::string objExtensionLookup1 = "CMAKE_";
std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
for(std::vector<std::string>::iterator d = dirs.begin();
d != dirs.end(); ++d)
{
for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
s != this->SourceFiles.end(); ++s)
{
cmSourceFile* sf = *s;
if(const char* lang = sf->GetLanguage())
{
std::string lookupObj = objExtensionLookup1 + lang;
lookupObj += objExtensionLookup2;
const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
if(obj)
{
if(objectFiles.size())
{
objectFiles += ";";
}
std::string objFile = *d;
objFile += "/";
objFile += this->Makefile->GetLocalGenerator()->
GetSourceObjectName(*sf);
objFile += obj;
objectFiles += objFile;
}
}
}
}
this->SetProperty("OBJECT_FILES", objectFiles.c_str());
#endif
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char *cmTarget::GetProperty(const char* prop, const char *cmTarget::GetProperty(const char* prop,
cmProperty::ScopeType scope) cmProperty::ScopeType scope)

View File

@ -403,9 +403,6 @@ public:
// Define the properties // Define the properties
static void DefineProperties(cmake *cm); static void DefineProperties(cmake *cm);
// Compute the OBJECT_FILES property only when requested
void ComputeObjectFiles();
/** Get the macro to define when building sources in this target. /** Get the macro to define when building sources in this target.
If no macro should be defined null is returned. */ If no macro should be defined null is returned. */
const char* GetExportMacro(); const char* GetExportMacro();

View File

@ -877,9 +877,6 @@ void cmVisualStudio10TargetGenerator::WriteCLSources()
void cmVisualStudio10TargetGenerator::ComputeObjectNames() void cmVisualStudio10TargetGenerator::ComputeObjectNames()
{ {
// We may be modifying the source groups temporarily, so make a copy.
std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
// get the classes from the source lists then add them to the groups // get the classes from the source lists then add them to the groups
std::vector<cmSourceFile*>const & classes = this->Target->GetSourceFiles(); std::vector<cmSourceFile*>const & classes = this->Target->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator i = classes.begin(); for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
@ -891,13 +888,10 @@ void cmVisualStudio10TargetGenerator::ComputeObjectNames()
{ {
this->ModuleDefinitionFile = (*i)->GetFullPath(); this->ModuleDefinitionFile = (*i)->GetFullPath();
} }
cmSourceGroup& sourceGroup =
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
sourceGroup.AssignSource(*i);
} }
// Compute which sources need unique object computation. // Compute which sources need unique object computation.
this->LocalGenerator->ComputeObjectNameRequirements(sourceGroups); this->LocalGenerator->ComputeObjectNameRequirements(classes);
} }
bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(