cmake: Store hardcoded lists of sources and headers

Don't duplicate this in each cmMakefile.
This commit is contained in:
Stephen Kelly 2015-10-24 14:58:23 +02:00
parent 6bd7bd1e06
commit 780bff5279
12 changed files with 70 additions and 62 deletions

View File

@ -60,10 +60,10 @@ bool cmAuxSourceDirectoryCommand::InitialPass
std::string ext = file.substr(dotpos+1); std::string ext = file.substr(dotpos+1);
std::string base = file.substr(0, dotpos); std::string base = file.substr(0, dotpos);
// Process only source files // Process only source files
if(!base.empty() std::vector<std::string> srcExts =
&& std::find( this->Makefile->GetSourceExtensions().begin(), this->Makefile->GetCMakeInstance()->GetSourceExtensions();
this->Makefile->GetSourceExtensions().end(), ext ) if(!base.empty() &&
!= this->Makefile->GetSourceExtensions().end() ) std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
{ {
std::string fullname = templateDirectory; std::string fullname = templateDirectory;
fullname += "/"; fullname += "/";

View File

@ -383,6 +383,9 @@ void cmExtraCodeBlocksGenerator
all_files_map_t allFiles; all_files_map_t allFiles;
std::vector<std::string> cFiles; std::vector<std::string> cFiles;
std::vector<std::string> srcExts =
this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin(); for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
lg!=lgs.end(); lg++) lg!=lgs.end(); lg++)
{ {
@ -420,9 +423,7 @@ void cmExtraCodeBlocksGenerator
{ {
std::string srcext = (*si)->GetExtension(); std::string srcext = (*si)->GetExtension();
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = mf->GetSourceExtensions().begin(); ext = srcExts.begin(); ext != srcExts.end(); ++ext)
ext != mf->GetSourceExtensions().end();
++ext)
{ {
if (srcext == *ext) if (srcext == *ext)
{ {
@ -449,6 +450,9 @@ void cmExtraCodeBlocksGenerator
} }
} }
std::vector<std::string> headerExts =
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
// The following loop tries to add header files matching to implementation // The following loop tries to add header files matching to implementation
// files to the project. It does that by iterating over all // files to the project. It does that by iterating over all
// C/C++ source files, // C/C++ source files,
@ -468,8 +472,8 @@ void cmExtraCodeBlocksGenerator
// check if there's a matching header around // check if there's a matching header around
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = mf->GetHeaderExtensions().begin(); ext = headerExts.begin();
ext != mf->GetHeaderExtensions().end(); ext != headerExts.end();
++ext) ++ext)
{ {
std::string hname=headerBasename; std::string hname=headerBasename;

View File

@ -149,6 +149,11 @@ void cmExtraCodeLiteGenerator
// which may have an acompanying header, one for all other files // which may have an acompanying header, one for all other files
std::string projectType; std::string projectType;
std::vector<std::string> srcExts =
this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
std::vector<std::string> headerExts =
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
std::map<std::string, cmSourceFile*> cFiles; std::map<std::string, cmSourceFile*> cFiles;
std::set<std::string> otherFiles; std::set<std::string> otherFiles;
for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin(); for (std::vector<cmLocalGenerator*>::const_iterator lg=lgs.begin();
@ -207,9 +212,7 @@ void cmExtraCodeLiteGenerator
{ {
std::string srcext = (*si)->GetExtension(); std::string srcext = (*si)->GetExtension();
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = mf->GetSourceExtensions().begin(); ext = srcExts.begin(); ext != srcExts.end(); ++ext)
ext != mf->GetSourceExtensions().end();
++ext)
{ {
if (srcext == *ext) if (srcext == *ext)
{ {
@ -253,8 +256,8 @@ void cmExtraCodeLiteGenerator
// check if there's a matching header around // check if there's a matching header around
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = mf->GetHeaderExtensions().begin(); ext = headerExts.begin();
ext != mf->GetHeaderExtensions().end(); ext != headerExts.end();
++ext) ++ext)
{ {
std::string hname=headerBasename; std::string hname=headerBasename;

View File

@ -105,6 +105,9 @@ bool cmGlobalKdevelopGenerator
std::set<std::string> files; std::set<std::string> files;
std::string tmp; std::string tmp;
std::vector<std::string> hdrExts =
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin(); for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin();
it!=lgs.end(); it++) it!=lgs.end(); it++)
{ {
@ -160,8 +163,7 @@ bool cmGlobalKdevelopGenerator
// check if there's a matching header around // check if there's a matching header around
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = makefile->GetHeaderExtensions().begin(); ext = hdrExts.begin(); ext != hdrExts.end(); ++ext)
ext != makefile->GetHeaderExtensions().end(); ++ext)
{ {
std::string hname=headerBasename; std::string hname=headerBasename;
hname += "."; hname += ".";

View File

@ -1420,7 +1420,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf) bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
{ {
const std::vector<std::string>& hdrExts = const std::vector<std::string>& hdrExts =
this->CurrentMakefile->GetHeaderExtensions(); this->CMakeInstance->GetHeaderExtensions();
return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) != return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
hdrExts.end()); hdrExts.end());
} }

View File

@ -57,31 +57,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
// Setup the default include complaint regular expression (match nothing). // Setup the default include complaint regular expression (match nothing).
this->ComplainFileRegularExpression = "^$"; this->ComplainFileRegularExpression = "^$";
// Source and header file extensions that we can handle
// Set up a list of source and header extensions
// these are used to find files when the extension
// is not given
// The "c" extension MUST precede the "C" extension.
this->SourceFileExtensions.push_back( "c" );
this->SourceFileExtensions.push_back( "C" );
this->SourceFileExtensions.push_back( "c++" );
this->SourceFileExtensions.push_back( "cc" );
this->SourceFileExtensions.push_back( "cpp" );
this->SourceFileExtensions.push_back( "cxx" );
this->SourceFileExtensions.push_back( "m" );
this->SourceFileExtensions.push_back( "M" );
this->SourceFileExtensions.push_back( "mm" );
this->HeaderFileExtensions.push_back( "h" );
this->HeaderFileExtensions.push_back( "hh" );
this->HeaderFileExtensions.push_back( "h++" );
this->HeaderFileExtensions.push_back( "hm" );
this->HeaderFileExtensions.push_back( "hpp" );
this->HeaderFileExtensions.push_back( "hxx" );
this->HeaderFileExtensions.push_back( "in" );
this->HeaderFileExtensions.push_back( "txx" );
this->DefineFlags = " "; this->DefineFlags = " ";

View File

@ -425,17 +425,6 @@ public:
cmSourceFile* GetOrCreateSource(const std::string& sourceName, cmSourceFile* GetOrCreateSource(const std::string& sourceName,
bool generated = false); bool generated = false);
//@{
/**
* Return a list of extensions associated with source and header
* files
*/
const std::vector<std::string>& GetSourceExtensions() const
{return this->SourceFileExtensions;}
const std::vector<std::string>& GetHeaderExtensions() const
{return this->HeaderFileExtensions;}
//@}
/** /**
* Given a variable name, return its value (as a string). * Given a variable name, return its value (as a string).
* If the variable is not found in this makefile instance, the * If the variable is not found in this makefile instance, the
@ -823,8 +812,6 @@ protected:
std::vector<cmTestGenerator*> TestGenerators; std::vector<cmTestGenerator*> TestGenerators;
std::string ComplainFileRegularExpression; std::string ComplainFileRegularExpression;
std::vector<std::string> SourceFileExtensions;
std::vector<std::string> HeaderFileExtensions;
std::string DefineFlags; std::string DefineFlags;
// Track the value of the computed DEFINITIONS property. // Track the value of the computed DEFINITIONS property.

View File

@ -528,7 +528,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
cmSystemTools::ExpandListArgument(this->Sources, sourceFiles); cmSystemTools::ExpandListArgument(this->Sources, sourceFiles);
const std::vector<std::string>& headerExtensions = const std::vector<std::string>& headerExtensions =
makefile->GetHeaderExtensions(); makefile->GetCMakeInstance()->GetHeaderExtensions();
std::map<std::string, std::vector<std::string> > includedUis; std::map<std::string, std::vector<std::string> > includedUis;
std::map<std::string, std::vector<std::string> > skippedUis; std::map<std::string, std::vector<std::string> > skippedUis;

View File

@ -167,8 +167,10 @@ bool cmSourceFile::FindFullPath(std::string* error)
{ {
tryDirs[0] = ""; tryDirs[0] = "";
} }
const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); const std::vector<std::string>& srcExts =
const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions(); mf->GetCMakeInstance()->GetSourceExtensions();
std::vector<std::string> hdrExts =
mf->GetCMakeInstance()->GetHeaderExtensions();
for(const char* const* di = tryDirs; *di; ++di) for(const char* const* di = tryDirs; *di; ++di)
{ {
std::string tryPath = this->Location.GetDirectory(); std::string tryPath = this->Location.GetDirectory();

View File

@ -121,8 +121,10 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name)
// The global generator checks extensions of enabled languages. // The global generator checks extensions of enabled languages.
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
cmMakefile const* mf = this->Makefile; cmMakefile const* mf = this->Makefile;
const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); const std::vector<std::string>& srcExts =
const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions(); mf->GetCMakeInstance()->GetSourceExtensions();
const std::vector<std::string>& hdrExts =
mf->GetCMakeInstance()->GetHeaderExtensions();
if(!gg->GetLanguageFromExtension(ext.c_str()).empty() || if(!gg->GetLanguageFromExtension(ext.c_str()).empty() ||
std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end() || std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end() ||
std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end()) std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
@ -193,12 +195,14 @@ cmSourceFileLocation
// disk. One of these must match if loc refers to this source file. // disk. One of these must match if loc refers to this source file.
std::string const& ext = this->Name.substr(loc.Name.size()+1); std::string const& ext = this->Name.substr(loc.Name.size()+1);
cmMakefile const* mf = this->Makefile; cmMakefile const* mf = this->Makefile;
const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); const std::vector<std::string>& srcExts =
mf->GetCMakeInstance()->GetSourceExtensions();
if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
{ {
return true; return true;
} }
const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions(); std::vector<std::string> hdrExts =
mf->GetCMakeInstance()->GetHeaderExtensions();
if(std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end()) if(std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
{ {
return true; return true;

View File

@ -165,6 +165,30 @@ cmake::cmake()
// Make sure we can capture the build tool output. // Make sure we can capture the build tool output.
cmSystemTools::EnableVSConsoleOutput(); cmSystemTools::EnableVSConsoleOutput();
// Set up a list of source and header extensions
// these are used to find files when the extension
// is not given
// The "c" extension MUST precede the "C" extension.
this->SourceFileExtensions.push_back( "c" );
this->SourceFileExtensions.push_back( "C" );
this->SourceFileExtensions.push_back( "c++" );
this->SourceFileExtensions.push_back( "cc" );
this->SourceFileExtensions.push_back( "cpp" );
this->SourceFileExtensions.push_back( "cxx" );
this->SourceFileExtensions.push_back( "m" );
this->SourceFileExtensions.push_back( "M" );
this->SourceFileExtensions.push_back( "mm" );
this->HeaderFileExtensions.push_back( "h" );
this->HeaderFileExtensions.push_back( "hh" );
this->HeaderFileExtensions.push_back( "h++" );
this->HeaderFileExtensions.push_back( "hm" );
this->HeaderFileExtensions.push_back( "hpp" );
this->HeaderFileExtensions.push_back( "hxx" );
this->HeaderFileExtensions.push_back( "in" );
this->HeaderFileExtensions.push_back( "txx" );
} }
cmake::~cmake() cmake::~cmake()

View File

@ -182,6 +182,11 @@ class cmake
///! get the cmCachemManager used by this invocation of cmake ///! get the cmCachemManager used by this invocation of cmake
cmCacheManager *GetCacheManager() { return this->CacheManager; } cmCacheManager *GetCacheManager() { return this->CacheManager; }
const std::vector<std::string>& GetSourceExtensions() const
{return this->SourceFileExtensions;}
const std::vector<std::string>& GetHeaderExtensions() const
{return this->HeaderFileExtensions;}
/** /**
* Given a variable name, return its value (as a string). * Given a variable name, return its value (as a string).
*/ */
@ -391,6 +396,8 @@ private:
std::string CheckStampFile; std::string CheckStampFile;
std::string CheckStampList; std::string CheckStampList;
std::string VSSolutionFile; std::string VSSolutionFile;
std::vector<std::string> SourceFileExtensions;
std::vector<std::string> HeaderFileExtensions;
bool ClearBuildSystem; bool ClearBuildSystem;
bool DebugTryCompile; bool DebugTryCompile;
cmFileTimeComparison* FileComparison; cmFileTimeComparison* FileComparison;