Merge topic 'fix-source-classification'

01e979a VS: Add CMakeLists.txt re-run rules at start of generation
9a2c60e Classify known header file extensions as headers
1c48992 Always compile sources with known language
This commit is contained in:
David Cole 2012-04-03 15:58:42 -04:00 committed by CMake Topic Stage
commit 7ecf76a19b
10 changed files with 66 additions and 54 deletions

View File

@ -30,6 +30,7 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGeneratorTarget::ClassifySources() void cmGeneratorTarget::ClassifySources()
{ {
cmsys::RegularExpression header(CM_HEADER_REGEX);
bool isObjLib = this->Target->GetType() == cmTarget::OBJECT_LIBRARY; bool isObjLib = this->Target->GetType() == cmTarget::OBJECT_LIBRARY;
std::vector<cmSourceFile*> badObjLib; std::vector<cmSourceFile*> badObjLib;
std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles(); std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
@ -58,6 +59,10 @@ void cmGeneratorTarget::ClassifySources()
this->ExternalObjects.push_back(sf); this->ExternalObjects.push_back(sf);
if(isObjLib) { badObjLib.push_back(sf); } if(isObjLib) { badObjLib.push_back(sf); }
} }
else if(sf->GetLanguage())
{
this->ObjectSources.push_back(sf);
}
else if(ext == "def") else if(ext == "def")
{ {
this->ModuleDefinitionFile = sf->GetFullPath(); this->ModuleDefinitionFile = sf->GetFullPath();
@ -68,6 +73,10 @@ void cmGeneratorTarget::ClassifySources()
this->IDLSources.push_back(sf); this->IDLSources.push_back(sf);
if(isObjLib) { badObjLib.push_back(sf); } if(isObjLib) { badObjLib.push_back(sf); }
} }
else if(header.find(sf->GetFullPath().c_str()))
{
this->HeaderSources.push_back(sf);
}
else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str())) else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
{ {
// We only get here if a source file is not an external object // We only get here if a source file is not an external object
@ -75,10 +84,6 @@ void cmGeneratorTarget::ClassifySources()
// No message or diagnosis should be given. // No message or diagnosis should be given.
this->ExtraSources.push_back(sf); this->ExtraSources.push_back(sf);
} }
else if(sf->GetLanguage())
{
this->ObjectSources.push_back(sf);
}
else else
{ {
this->ExtraSources.push_back(sf); this->ExtraSources.push_back(sf);

View File

@ -95,6 +95,16 @@ void cmGlobalVisualStudioGenerator::Generate()
// of Visual Studio. // of Visual Studio.
this->ConfigureCMakeVisualStudioMacros(); this->ConfigureCMakeVisualStudioMacros();
// Add CMakeLists.txt with custom command to rerun CMake.
for(std::vector<cmLocalGenerator*>::const_iterator
lgi = this->LocalGenerators.begin();
lgi != this->LocalGenerators.end(); ++lgi)
{
cmLocalVisualStudioGenerator* lg =
static_cast<cmLocalVisualStudioGenerator*>(*lgi);
lg->AddCMakeListsRules();
}
// Run all the local generators. // Run all the local generators.
this->cmGlobalGenerator::Generate(); this->cmGlobalGenerator::Generate();
} }

View File

@ -74,24 +74,6 @@ void cmLocalVisualStudio10Generator::Generate()
{ {
cmTargets &tgts = this->Makefile->GetTargets(); cmTargets &tgts = this->Makefile->GetTargets();
// Create the regeneration custom rule.
if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
{
// Create a rule to regenerate the build system when the target
// specification source changes.
if(cmSourceFile* sf = this->CreateVCProjBuildRule())
{
// Add the rule to targets that need it.
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{
if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
{
l->second.AddSourceFile(sf);
}
}
}
}
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{ {
if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator) if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)

View File

@ -85,6 +85,23 @@ void cmLocalVisualStudio6Generator::AddHelperCommands()
this->CreateCustomTargetsAndCommands(lang); this->CreateCustomTargetsAndCommands(lang);
} }
void cmLocalVisualStudio6Generator::AddCMakeListsRules()
{
cmTargets &tgts = this->Makefile->GetTargets();
for(cmTargets::iterator l = tgts.begin();
l != tgts.end(); l++)
{
// Add a rule to regenerate the build system when the target
// specification source changes.
const char* suppRegenRule =
this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
if (!cmSystemTools::IsOn(suppRegenRule))
{
this->AddDSPBuildRule(l->second);
}
}
}
void cmLocalVisualStudio6Generator::Generate() void cmLocalVisualStudio6Generator::Generate()
{ {
this->OutputDSPFile(); this->OutputDSPFile();
@ -107,18 +124,6 @@ void cmLocalVisualStudio6Generator::OutputDSPFile()
// Create the DSP or set of DSP's for libraries and executables // Create the DSP or set of DSP's for libraries and executables
cmTargets &tgts = this->Makefile->GetTargets(); cmTargets &tgts = this->Makefile->GetTargets();
for(cmTargets::iterator l = tgts.begin();
l != tgts.end(); l++)
{
// Add a rule to regenerate the build system when the target
// specification source changes.
const char* suppRegenRule =
this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
if (!cmSystemTools::IsOn(suppRegenRule))
{
this->AddDSPBuildRule(l->second);
}
}
// build any targets // build any targets
for(cmTargets::iterator l = tgts.begin(); for(cmTargets::iterator l = tgts.begin();

View File

@ -34,6 +34,7 @@ public:
virtual ~cmLocalVisualStudio6Generator(); virtual ~cmLocalVisualStudio6Generator();
virtual void AddHelperCommands(); virtual void AddHelperCommands();
virtual void AddCMakeListsRules();
/** /**
* Generate the makefile for this directory. * Generate the makefile for this directory.

View File

@ -100,6 +100,28 @@ void cmLocalVisualStudio7Generator::Generate()
this->WriteStampFiles(); this->WriteStampFiles();
} }
void cmLocalVisualStudio7Generator::AddCMakeListsRules()
{
cmTargets &tgts = this->Makefile->GetTargets();
// Create the regeneration custom rule.
if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
{
// Create a rule to regenerate the build system when the target
// specification source changes.
if(cmSourceFile* sf = this->CreateVCProjBuildRule())
{
// Add the rule to targets that need it.
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{
if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
{
l->second.AddSourceFile(sf);
}
}
}
}
}
void cmLocalVisualStudio7Generator::FixGlobalTargets() void cmLocalVisualStudio7Generator::FixGlobalTargets()
{ {
// Visual Studio .NET 2003 Service Pack 1 will not run post-build // Visual Studio .NET 2003 Service Pack 1 will not run post-build
@ -156,24 +178,6 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles()
// Get the set of targets in this directory. // Get the set of targets in this directory.
cmTargets &tgts = this->Makefile->GetTargets(); cmTargets &tgts = this->Makefile->GetTargets();
// Create the regeneration custom rule.
if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
{
// Create a rule to regenerate the build system when the target
// specification source changes.
if(cmSourceFile* sf = this->CreateVCProjBuildRule())
{
// Add the rule to targets that need it.
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{
if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
{
l->second.AddSourceFile(sf);
}
}
}
}
// Create the project file for each target. // Create the project file for each target.
for(cmTargets::iterator l = tgts.begin(); for(cmTargets::iterator l = tgts.begin();
l != tgts.end(); l++) l != tgts.end(); l++)

View File

@ -64,6 +64,7 @@ public:
virtual void ReadAndStoreExternalGUID(const char* name, virtual void ReadAndStoreExternalGUID(const char* name,
const char* path); const char* path);
virtual void AddCMakeListsRules();
protected: protected:
void CreateSingleVCProj(const char *lname, cmTarget &tgt); void CreateSingleVCProj(const char *lname, cmTarget &tgt);
private: private:

View File

@ -58,6 +58,8 @@ public:
virtual std::string ComputeLongestObjectDirectory(cmTarget&) const = 0; virtual std::string ComputeLongestObjectDirectory(cmTarget&) const = 0;
virtual void AddCMakeListsRules() = 0;
protected: protected:
virtual const char* ReportErrorLabel() const; virtual const char* ReportErrorLabel() const;
virtual bool CustomCommandUseLocal() const { return false; } virtual bool CustomCommandUseLocal() const { return false; }

View File

@ -778,8 +778,7 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
("Source Files", ("Source Files",
"\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp" "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp"
"|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$"); "|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$");
this->AddSourceGroup("Header Files", this->AddSourceGroup("Header Files", CM_HEADER_REGEX);
"\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
this->AddSourceGroup("CMake Rules", "\\.rule$"); this->AddSourceGroup("CMake Rules", "\\.rule$");
this->AddSourceGroup("Resources", "\\.plist$"); this->AddSourceGroup("Resources", "\\.plist$");
this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$"); this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");

View File

@ -116,4 +116,7 @@ private:
std::vector<std::string> Depends; std::vector<std::string> Depends;
}; };
// TODO: Factor out into platform information modules.
#define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"
#endif #endif