ENH: Source and header file extensions are in variables in cmMakefile.

AUX_SOURCE_DIRECTORY will only add files that have a "source" extension.
This commit is contained in:
Amitha Perera 2001-07-16 18:40:42 -04:00
parent fdfe7a357e
commit e169953e92
8 changed files with 113 additions and 92 deletions

View File

@ -63,21 +63,30 @@ bool cmAuxSourceDirectoryCommand::InitialPass(std::vector<std::string>& 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());
}
}
}
}

View File

@ -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;

View File

@ -409,6 +409,17 @@ public:
std::vector<std::string>& GetAuxSourceDirectories()
{return m_AuxSourceDirectories;}
//@{
/**
* Return a list of extensions associated with source and header
* files
*/
const std::vector<std::string>& GetSourceExtensions() const
{return m_SourceFileExtensions;}
const std::vector<std::string>& 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<std::string> m_SourceFileExtensions;
std::vector<std::string> m_HeaderFileExtensions;
std::string m_DefineFlags;
std::vector<cmSourceGroup> m_SourceGroups;
typedef std::map<std::string, cmCommand*> RegisteredCommandsMap;

View File

@ -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<std::string>& sourceExts,
const std::vector<std::string>& 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<std::string>::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<std::string>::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<std::string>::const_iterator ext = sourceExts.begin();
ext != sourceExts.end(); ++ext )
{
errorMsg += " .";
errorMsg += *ext;
}
for( std::vector<std::string>::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;

View File

@ -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<std::string>& sourceExts,
const std::vector<std::string>& 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,

View File

@ -61,11 +61,15 @@ bool cmSourceFilesCommand::InitialPass(std::vector<std::string>& 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());
}

View File

@ -52,7 +52,9 @@ bool cmSourceFilesRemoveCommand::InitialPass(std::vector<std::string>& 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;

View File

@ -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);
}
}