From e169953e923907706439c60033ce983729c2e404 Mon Sep 17 00:00:00 2001 From: Amitha Perera Date: Mon, 16 Jul 2001 18:40:42 -0400 Subject: [PATCH] ENH: Source and header file extensions are in variables in cmMakefile. AUX_SOURCE_DIRECTORY will only add files that have a "source" extension. --- Source/cmAuxSourceDirectoryCommand.cxx | 35 +++++--- Source/cmMakefile.cxx | 9 ++ Source/cmMakefile.h | 13 +++ Source/cmSourceFile.cxx | 120 +++++++++++-------------- Source/cmSourceFile.h | 12 +-- Source/cmSourceFilesCommand.cxx | 8 +- Source/cmSourceFilesRemoveCommand.cxx | 4 +- Source/cmTarget.cxx | 4 +- 8 files changed, 113 insertions(+), 92 deletions(-) diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx index 4f8d19cd7..1639ce0df 100644 --- a/Source/cmAuxSourceDirectoryCommand.cxx +++ b/Source/cmAuxSourceDirectoryCommand.cxx @@ -63,21 +63,30 @@ bool cmAuxSourceDirectoryCommand::InitialPass(std::vector& args) for(int i =0; i < numfiles; ++i) { std::string file = dir.GetFile(i); - // ignore files less than f.cxx in length - if(file.size() > 4) + // Split the filename into base and extension + std::string::size_type dotpos = file.rfind("."); + if( dotpos != std::string::npos ) { - // Remove the extension - std::string::size_type dotpos = file.rfind("."); + std::string ext = file.substr(dotpos+1); file = file.substr(0, dotpos); - std::string fullname = templateDirectory; - fullname += "/"; - fullname += file; - // add the file as a class file so - // depends can be done - cmSourceFile cmfile; - cmfile.SetName(fullname.c_str(), m_Makefile->GetCurrentDirectory()); - cmfile.SetIsAnAbstractClass(false); - m_Makefile->AddSource(cmfile,args[1].c_str()); + // Process only source files + if( file.size() != 0 + && std::find( m_Makefile->GetSourceExtensions().begin(), + m_Makefile->GetSourceExtensions().end(), ext ) + != m_Makefile->GetSourceExtensions().end() ) + { + std::string fullname = templateDirectory; + fullname += "/"; + fullname += file; + // add the file as a class file so + // depends can be done + cmSourceFile cmfile; + cmfile.SetName(fullname.c_str(), m_Makefile->GetCurrentDirectory(), + m_Makefile->GetSourceExtensions(), + m_Makefile->GetHeaderExtensions()); + cmfile.SetIsAnAbstractClass(false); + m_Makefile->AddSource(cmfile,args[1].c_str()); + } } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index f44961094..9ead3e3c7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -57,6 +57,15 @@ cmMakefile::cmMakefile() m_IncludeFileRegularExpression = "^.*$"; // Setup the default include complaint regular expression (match nothing). m_ComplainFileRegularExpression = "^$"; + // Source and header file extensions that we can handle + m_SourceFileExtensions.push_back( "cxx" ); + m_SourceFileExtensions.push_back( "cpp" ); + m_SourceFileExtensions.push_back( "txx" ); + m_SourceFileExtensions.push_back( "c" ); + m_SourceFileExtensions.push_back( "M" ); + m_SourceFileExtensions.push_back( "m" ); + + m_HeaderFileExtensions.push_back( "h" ); m_DefineFlags = " "; m_MakefileGenerator = 0; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index f8dfcfc77..058e1278e 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -409,6 +409,17 @@ public: std::vector& GetAuxSourceDirectories() {return m_AuxSourceDirectories;} + //@{ + /** + * Return a list of extensions associated with source and header + * files + */ + const std::vector& GetSourceExtensions() const + {return m_SourceFileExtensions;} + const std::vector& GetHeaderExtensions() const + {return m_HeaderFileExtensions;} + //@} + /** * Given a variable name, return its value (as a string). */ @@ -510,6 +521,8 @@ protected: std::string m_IncludeFileRegularExpression; std::string m_ComplainFileRegularExpression; + std::vector m_SourceFileExtensions; + std::vector m_HeaderFileExtensions; std::string m_DefineFlags; std::vector m_SourceGroups; typedef std::map RegisteredCommandsMap; diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 2081575db..152dc6e61 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -48,7 +48,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // The class must be found in dir and end in name.cxx, name.txx, // name.c or it will be considered a header file only class // and not included in the build process -void cmSourceFile::SetName(const char* name, const char* dir) +void cmSourceFile::SetName(const char* name, const char* dir, + const std::vector& sourceExts, + const std::vector& headerExts) { m_HeaderFileOnly = true; @@ -94,81 +96,59 @@ void cmSourceFile::SetName(const char* name, const char* dir) return; } - // Try various extentions - hname = pathname; - hname += ".cxx"; - if(cmSystemTools::FileExists(hname.c_str())) + // Next, try the various source extensions + for( std::vector::const_iterator ext = sourceExts.begin(); + ext != sourceExts.end(); ++ext ) { - m_SourceExtension = "cxx"; - m_HeaderFileOnly = false; - m_FullPath = hname; - return; + hname = pathname; + hname += "."; + hname += *ext; + if(cmSystemTools::FileExists(hname.c_str())) + { + m_SourceExtension = *ext; + m_HeaderFileOnly = false; + m_FullPath = hname; + return; + } } + + // Finally, try the various header extensions + for( std::vector::const_iterator ext = headerExts.begin(); + ext != headerExts.end(); ++ext ) + { + hname = pathname; + hname += "."; + hname += *ext; + if(cmSystemTools::FileExists(hname.c_str())) + { + m_SourceExtension = *ext; + m_FullPath = hname; + return; + } + } + + std::string errorMsg = "Tried"; + for( std::vector::const_iterator ext = sourceExts.begin(); + ext != sourceExts.end(); ++ext ) + { + errorMsg += " ."; + errorMsg += *ext; + } + for( std::vector::const_iterator ext = headerExts.begin(); + ext != headerExts.end(); ++ext ) + { + errorMsg += " ."; + errorMsg += *ext; + } + errorMsg += " for "; - hname = pathname; - hname += ".c"; - if(cmSystemTools::FileExists(hname.c_str())) - { - m_HeaderFileOnly = false; - m_SourceExtension = "c"; - m_FullPath = hname; - return; - } - hname = pathname; - hname += ".txx"; - if(cmSystemTools::FileExists(hname.c_str())) - { - m_HeaderFileOnly = false; - m_SourceExtension = "txx"; - m_FullPath = hname; - return; - } - // - hname = pathname; - hname += ".cpp"; - if(cmSystemTools::FileExists(hname.c_str())) - { - m_SourceExtension = "cpp"; - m_HeaderFileOnly = false; - m_FullPath = hname; - return; - } - - hname = pathname; - hname += ".m"; - if(cmSystemTools::FileExists(hname.c_str())) - { - m_SourceExtension = "m"; - m_HeaderFileOnly = false; - m_FullPath = hname; - return; - } - - hname = pathname; - hname += ".M"; - if(cmSystemTools::FileExists(hname.c_str())) - { - m_SourceExtension = "M"; - m_HeaderFileOnly = false; - m_FullPath = hname; - return; - } - - hname = pathname; - hname += ".h"; - if(cmSystemTools::FileExists(hname.c_str())) - { - m_SourceExtension = "h"; - m_FullPath = hname; - return; - } - - cmSystemTools::Error("can not find file ", hname.c_str()); - cmSystemTools::Error("Tried .cxx .c .txx .cpp .m .M .h for ", hname.c_str()); + cmSystemTools::Error("can not find file ", pathname.c_str()); + cmSystemTools::Error(errorMsg.c_str(), pathname.c_str()); } + void cmSourceFile::SetName(const char* name, const char* dir, const char *ext, - bool hfo) + bool hfo) { m_HeaderFileOnly = hfo; m_SourceName = name; diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 57a53123c..538129aa2 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -64,15 +64,17 @@ public: } /** - * Set the name of the file, given the directory - * the file should be in. Various extensions are tried on - * the name (e.g., .cxx, .cpp) in the directory to find the actual file. + * Set the name of the file, given the directory the file should be + * in. The various extensions provided are tried on the name + * (e.g., cxx, cpp) in the directory to find the actual file. */ - void SetName(const char* name, const char* dir); + void SetName(const char* name, const char* dir, + const std::vector& sourceExts, + const std::vector& headerExts); /** * Set the name of the file, given the directory the file should be in. IN - * this version the extesion is provided in the call. This is useful for + * this version the extension is provided in the call. This is useful for * generated files that do not exist prior to the build. */ void SetName(const char* name, const char* dir, const char *ext, diff --git a/Source/cmSourceFilesCommand.cxx b/Source/cmSourceFilesCommand.cxx index bc39fc55e..778c095ef 100644 --- a/Source/cmSourceFilesCommand.cxx +++ b/Source/cmSourceFilesCommand.cxx @@ -61,11 +61,15 @@ bool cmSourceFilesCommand::InitialPass(std::vector& args) (path.size() > 1 && path[1] == ':')) { file.SetName(cmSystemTools::GetFilenameName(copy.c_str()).c_str(), - path.c_str()); + path.c_str(), + m_Makefile->GetSourceExtensions(), + m_Makefile->GetHeaderExtensions()); } else { - file.SetName(i->c_str(), m_Makefile->GetCurrentDirectory()); + file.SetName(i->c_str(), m_Makefile->GetCurrentDirectory(), + m_Makefile->GetSourceExtensions(), + m_Makefile->GetHeaderExtensions()); } m_Makefile->AddSource(file, args[0].c_str()); } diff --git a/Source/cmSourceFilesRemoveCommand.cxx b/Source/cmSourceFilesRemoveCommand.cxx index 815c2b99a..e43facb2a 100644 --- a/Source/cmSourceFilesRemoveCommand.cxx +++ b/Source/cmSourceFilesRemoveCommand.cxx @@ -52,7 +52,9 @@ bool cmSourceFilesRemoveCommand::InitialPass(std::vector& args) i != args.end(); ++i) { cmSourceFile file; - file.SetName((*i).c_str(), m_Makefile->GetCurrentDirectory()); + file.SetName((*i).c_str(), m_Makefile->GetCurrentDirectory(), + m_Makefile->GetSourceExtensions(), + m_Makefile->GetHeaderExtensions()); m_Makefile->RemoveSource(file, args[0].c_str()); } return true; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 50a2c17da..ea983f9dc 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -71,7 +71,9 @@ void cmTarget::GenerateSourceFilesFromSourceLists(const cmMakefile &mf) { cmSourceFile file; file.SetIsAnAbstractClass(false); - file.SetName(temps.c_str(), mf.GetCurrentDirectory()); + file.SetName(temps.c_str(), mf.GetCurrentDirectory(), + mf.GetSourceExtensions(), + mf.GetHeaderExtensions()); m_SourceFiles.push_back(file); } }