From 780bff5279c6c2d356e5c7726b656bd9c68532b8 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 24 Oct 2015 14:58:23 +0200 Subject: cmake: Store hardcoded lists of sources and headers Don't duplicate this in each cmMakefile. --- Source/cmAuxSourceDirectoryCommand.cxx | 8 ++++---- Source/cmExtraCodeBlocksGenerator.cxx | 14 +++++++++----- Source/cmExtraCodeLiteGenerator.cxx | 13 ++++++++----- Source/cmGlobalKdevelopGenerator.cxx | 6 ++++-- Source/cmGlobalXCodeGenerator.cxx | 2 +- Source/cmMakefile.cxx | 25 ------------------------- Source/cmMakefile.h | 13 ------------- Source/cmQtAutoGenerators.cxx | 2 +- Source/cmSourceFile.cxx | 6 ++++-- Source/cmSourceFileLocation.cxx | 12 ++++++++---- Source/cmake.cxx | 24 ++++++++++++++++++++++++ Source/cmake.h | 7 +++++++ 12 files changed, 70 insertions(+), 62 deletions(-) diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx index 5f5017d..92ac07d 100644 --- a/Source/cmAuxSourceDirectoryCommand.cxx +++ b/Source/cmAuxSourceDirectoryCommand.cxx @@ -60,10 +60,10 @@ bool cmAuxSourceDirectoryCommand::InitialPass std::string ext = file.substr(dotpos+1); std::string base = file.substr(0, dotpos); // Process only source files - if(!base.empty() - && std::find( this->Makefile->GetSourceExtensions().begin(), - this->Makefile->GetSourceExtensions().end(), ext ) - != this->Makefile->GetSourceExtensions().end() ) + std::vector srcExts = + this->Makefile->GetCMakeInstance()->GetSourceExtensions(); + if(!base.empty() && + std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) { std::string fullname = templateDirectory; fullname += "/"; diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 597c9d8..9348ef2 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -383,6 +383,9 @@ void cmExtraCodeBlocksGenerator all_files_map_t allFiles; std::vector cFiles; + std::vector srcExts = + this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions(); + for (std::vector::const_iterator lg=lgs.begin(); lg!=lgs.end(); lg++) { @@ -420,9 +423,7 @@ void cmExtraCodeBlocksGenerator { std::string srcext = (*si)->GetExtension(); for(std::vector::const_iterator - ext = mf->GetSourceExtensions().begin(); - ext != mf->GetSourceExtensions().end(); - ++ext) + ext = srcExts.begin(); ext != srcExts.end(); ++ext) { if (srcext == *ext) { @@ -449,6 +450,9 @@ void cmExtraCodeBlocksGenerator } } + std::vector headerExts = + this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions(); + // The following loop tries to add header files matching to implementation // files to the project. It does that by iterating over all // C/C++ source files, @@ -468,8 +472,8 @@ void cmExtraCodeBlocksGenerator // check if there's a matching header around for(std::vector::const_iterator - ext = mf->GetHeaderExtensions().begin(); - ext != mf->GetHeaderExtensions().end(); + ext = headerExts.begin(); + ext != headerExts.end(); ++ext) { std::string hname=headerBasename; diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index f4a6537..67aa157 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -149,6 +149,11 @@ void cmExtraCodeLiteGenerator // which may have an acompanying header, one for all other files std::string projectType; + std::vector srcExts = + this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions(); + std::vector headerExts = + this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions(); + std::map cFiles; std::set otherFiles; for (std::vector::const_iterator lg=lgs.begin(); @@ -207,9 +212,7 @@ void cmExtraCodeLiteGenerator { std::string srcext = (*si)->GetExtension(); for(std::vector::const_iterator - ext = mf->GetSourceExtensions().begin(); - ext != mf->GetSourceExtensions().end(); - ++ext) + ext = srcExts.begin(); ext != srcExts.end(); ++ext) { if (srcext == *ext) { @@ -253,8 +256,8 @@ void cmExtraCodeLiteGenerator // check if there's a matching header around for(std::vector::const_iterator - ext = mf->GetHeaderExtensions().begin(); - ext != mf->GetHeaderExtensions().end(); + ext = headerExts.begin(); + ext != headerExts.end(); ++ext) { std::string hname=headerBasename; diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx index 7c6c48c..018ab24 100644 --- a/Source/cmGlobalKdevelopGenerator.cxx +++ b/Source/cmGlobalKdevelopGenerator.cxx @@ -105,6 +105,9 @@ bool cmGlobalKdevelopGenerator std::set files; std::string tmp; + std::vector hdrExts = + this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions(); + for (std::vector::const_iterator it=lgs.begin(); it!=lgs.end(); it++) { @@ -160,8 +163,7 @@ bool cmGlobalKdevelopGenerator // check if there's a matching header around for(std::vector::const_iterator - ext = makefile->GetHeaderExtensions().begin(); - ext != makefile->GetHeaderExtensions().end(); ++ext) + ext = hdrExts.begin(); ext != hdrExts.end(); ++ext) { std::string hname=headerBasename; hname += "."; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 9a5c367..5737bee 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1420,7 +1420,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt) bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf) { const std::vector& hdrExts = - this->CurrentMakefile->GetHeaderExtensions(); + this->CMakeInstance->GetHeaderExtensions(); return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) != hdrExts.end()); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 361aa99..3bf34e2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -57,31 +57,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, // Setup the default include complaint regular expression (match nothing). 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 = " "; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 725448b..f3dbb74 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -425,17 +425,6 @@ public: cmSourceFile* GetOrCreateSource(const std::string& sourceName, bool generated = false); - //@{ - /** - * Return a list of extensions associated with source and header - * files - */ - const std::vector& GetSourceExtensions() const - {return this->SourceFileExtensions;} - const std::vector& GetHeaderExtensions() const - {return this->HeaderFileExtensions;} - //@} - /** * Given a variable name, return its value (as a string). * If the variable is not found in this makefile instance, the @@ -823,8 +812,6 @@ protected: std::vector TestGenerators; std::string ComplainFileRegularExpression; - std::vector SourceFileExtensions; - std::vector HeaderFileExtensions; std::string DefineFlags; // Track the value of the computed DEFINITIONS property. diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index fc690f8..b16eccd 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -528,7 +528,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) cmSystemTools::ExpandListArgument(this->Sources, sourceFiles); const std::vector& headerExtensions = - makefile->GetHeaderExtensions(); + makefile->GetCMakeInstance()->GetHeaderExtensions(); std::map > includedUis; std::map > skippedUis; diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 37383be..a9ac549 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -167,8 +167,10 @@ bool cmSourceFile::FindFullPath(std::string* error) { tryDirs[0] = ""; } - const std::vector& srcExts = mf->GetSourceExtensions(); - const std::vector& hdrExts = mf->GetHeaderExtensions(); + const std::vector& srcExts = + mf->GetCMakeInstance()->GetSourceExtensions(); + std::vector hdrExts = + mf->GetCMakeInstance()->GetHeaderExtensions(); for(const char* const* di = tryDirs; *di; ++di) { std::string tryPath = this->Location.GetDirectory(); diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index b8d5c02..00d5d6a 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -121,8 +121,10 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name) // The global generator checks extensions of enabled languages. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); cmMakefile const* mf = this->Makefile; - const std::vector& srcExts = mf->GetSourceExtensions(); - const std::vector& hdrExts = mf->GetHeaderExtensions(); + const std::vector& srcExts = + mf->GetCMakeInstance()->GetSourceExtensions(); + const std::vector& hdrExts = + mf->GetCMakeInstance()->GetHeaderExtensions(); if(!gg->GetLanguageFromExtension(ext.c_str()).empty() || std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.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. std::string const& ext = this->Name.substr(loc.Name.size()+1); cmMakefile const* mf = this->Makefile; - const std::vector& srcExts = mf->GetSourceExtensions(); + const std::vector& srcExts = + mf->GetCMakeInstance()->GetSourceExtensions(); if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) { return true; } - const std::vector& hdrExts = mf->GetHeaderExtensions(); + std::vector hdrExts = + mf->GetCMakeInstance()->GetHeaderExtensions(); if(std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end()) { return true; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 7268241..16417fc 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -165,6 +165,30 @@ cmake::cmake() // Make sure we can capture the build tool output. 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() diff --git a/Source/cmake.h b/Source/cmake.h index 9d28cba..6b0e83f 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -182,6 +182,11 @@ class cmake ///! get the cmCachemManager used by this invocation of cmake cmCacheManager *GetCacheManager() { return this->CacheManager; } + const std::vector& GetSourceExtensions() const + {return this->SourceFileExtensions;} + const std::vector& GetHeaderExtensions() const + {return this->HeaderFileExtensions;} + /** * Given a variable name, return its value (as a string). */ @@ -391,6 +396,8 @@ private: std::string CheckStampFile; std::string CheckStampList; std::string VSSolutionFile; + std::vector SourceFileExtensions; + std::vector HeaderFileExtensions; bool ClearBuildSystem; bool DebugTryCompile; cmFileTimeComparison* FileComparison; -- cgit v0.12