ENH: improve backwards compatibility

This commit is contained in:
Ken Martin 2008-01-19 15:09:36 -05:00
parent abf2054765
commit c3ab83150c
2 changed files with 99 additions and 11 deletions

View File

@ -35,6 +35,92 @@
#include <memory> // auto_ptr
//----------------------------------------------------------------------
class cmCTestSubdirCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
virtual cmCommand* Clone()
{
cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
c->TestHandler = this->TestHandler;
return c;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const& args);
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "subdirs";}
// Unused methods
virtual const char* GetTerseDocumentation() { return ""; }
virtual const char* GetFullDocumentation() { return ""; }
cmTypeMacro(cmCTestSubdirCommand, cmCommand);
cmCTestTestHandler* TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string>::const_iterator it;
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
for ( it = args.begin(); it != args.end(); ++ it )
{
cmSystemTools::ChangeDirectory(cwd.c_str());
std::string fname = cwd;
fname += "/";
fname += *it;
if ( !cmSystemTools::FileExists(fname.c_str()) )
{
// No subdirectory? So what...
continue;
}
cmSystemTools::ChangeDirectory(fname.c_str());
const char* testFilename;
if( cmSystemTools::FileExists("CTestTestfile.cmake") )
{
// does the CTestTestfile.cmake exist ?
testFilename = "CTestTestfile.cmake";
}
else
{
// No CTestTestfile? Who cares...
cmSystemTools::ChangeDirectory(cwd.c_str());
continue;
}
fname += "/";
fname += testFilename;
bool readit =
this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
fname.c_str());
cmSystemTools::ChangeDirectory(cwd.c_str());
if(!readit)
{
std::string m = "Could not find include file: ";
m += fname;
this->SetError(m.c_str());
return false;
}
}
return true;
}
//----------------------------------------------------------------------
class cmCTestAddSubdirectoryCommand : public cmCommand
{
@ -1258,18 +1344,24 @@ void cmCTestTestHandler::GetListOfTests()
newCom1->TestHandler = this;
cm.AddCommand(newCom1);
// Add handler for ADD_SUBDIRECTORY
cmCTestAddSubdirectoryCommand* newCom2 =
new cmCTestAddSubdirectoryCommand;
// Add handler for SUBDIRS
cmCTestSubdirCommand* newCom2 =
new cmCTestSubdirCommand;
newCom2->TestHandler = this;
cm.AddCommand(newCom2);
// Add handler for SET_SOURCE_FILES_PROPERTIES
cmCTestSetTestsPropertiesCommand* newCom3
= new cmCTestSetTestsPropertiesCommand;
// Add handler for ADD_SUBDIRECTORY
cmCTestAddSubdirectoryCommand* newCom3 =
new cmCTestAddSubdirectoryCommand;
newCom3->TestHandler = this;
cm.AddCommand(newCom3);
// Add handler for SET_SOURCE_FILES_PROPERTIES
cmCTestSetTestsPropertiesCommand* newCom4
= new cmCTestSetTestsPropertiesCommand;
newCom4->TestHandler = this;
cm.AddCommand(newCom4);
const char* testFilename;
if( cmSystemTools::FileExists("CTestTestfile.cmake") )
{

View File

@ -275,11 +275,7 @@ void cmLocalGenerator::GenerateTestFiles()
size_t i;
for(i = 0; i < this->Children.size(); ++i)
{
fout << "ADD_SUBDIRECTORY(";
std::string srcP =
this->Children[i]->GetMakefile()->GetStartDirectory();
fout << this->Convert(srcP.c_str(),START);
fout << " ";
fout << "SUBDIRS(";
std::string outP =
this->Children[i]->GetMakefile()->GetStartOutputDirectory();
fout << this->Convert(outP.c_str(),START_OUTPUT);