ENH: Added AddTest, and GenerateTestfile routines
This commit is contained in:
parent
6282d41c2a
commit
84dc25e9f5
|
@ -383,6 +383,87 @@ void cmMakefile::GenerateMakefile()
|
|||
}
|
||||
// now do the generation
|
||||
m_MakefileGenerator->GenerateMakefile();
|
||||
|
||||
// generate any testing files
|
||||
this->GenerateTestfile();
|
||||
}
|
||||
|
||||
void cmMakefile::GenerateTestfile()
|
||||
{
|
||||
if (m_Tests.empty() && this->GetSubDirectories().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a full path filename for output Testfile
|
||||
std::string fname;
|
||||
fname = this->GetCurrentOutputDirectory();
|
||||
fname += "/";
|
||||
fname += "Testfile";
|
||||
|
||||
// Open the output Testfile
|
||||
std::ofstream fout(fname.c_str());
|
||||
if (!fout)
|
||||
{
|
||||
cmSystemTools::Error("Error Writing ", fname.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
fout << "# CMake generated Testfile for " << std::endl
|
||||
<< "#\tSource directory: "
|
||||
<< this->GetCurrentDirectory()
|
||||
<< std::endl
|
||||
<< "#\tBuild directory: " << this->GetCurrentOutputDirectory()
|
||||
<< std::endl
|
||||
<< "# " << std::endl
|
||||
<< "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source"
|
||||
<< std::endl
|
||||
<< "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands"
|
||||
<< std::endl
|
||||
<< "# that are excluded by CMake control structures, i.e. IF() commands."
|
||||
<< std::endl
|
||||
<< "#"
|
||||
<< std::endl << std::endl;
|
||||
|
||||
// write out the subdirs for the current directory
|
||||
if (!this->GetSubDirectories().empty())
|
||||
{
|
||||
fout << "SUBDIRS(";
|
||||
const std::vector<std::string>& subdirs = this->GetSubDirectories();
|
||||
std::vector<std::string>::const_iterator i = subdirs.begin();
|
||||
fout << (*i).c_str();
|
||||
++i;
|
||||
for(; i != subdirs.end(); ++i)
|
||||
{
|
||||
fout << " " << (*i).c_str();
|
||||
}
|
||||
fout << ")" << std::endl << std::endl;;
|
||||
}
|
||||
|
||||
|
||||
// write out each test
|
||||
std::vector<std::vector<std::string> >::iterator testIt;
|
||||
std::vector<std::string>::iterator it;
|
||||
|
||||
// for each test
|
||||
for (testIt = m_Tests.begin(); testIt != m_Tests.end(); ++testIt)
|
||||
{
|
||||
if (!(*testIt).empty())
|
||||
{
|
||||
// for each arg in the test
|
||||
fout << "ADD_TEST(";
|
||||
it = (*testIt).begin();
|
||||
fout << (*it).c_str();
|
||||
++it;
|
||||
for (; it != (*testIt).end(); ++it)
|
||||
{
|
||||
fout << " " << (*it).c_str();
|
||||
}
|
||||
fout << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
fout << std::endl;
|
||||
}
|
||||
|
||||
void cmMakefile::AddSource(cmSourceFile& cmfile, const char *srclist)
|
||||
|
@ -489,6 +570,11 @@ void cmMakefile::AddDefinition(const char* name, bool value)
|
|||
}
|
||||
}
|
||||
|
||||
void cmMakefile::AddTest(const std::vector<std::string> &args)
|
||||
{
|
||||
m_Tests.push_back(args);
|
||||
}
|
||||
|
||||
void cmMakefile::SetProjectName(const char* p)
|
||||
{
|
||||
m_ProjectName = p;
|
||||
|
|
|
@ -111,6 +111,17 @@ public:
|
|||
*/
|
||||
void GenerateMakefile();
|
||||
|
||||
/**
|
||||
* Produce the output testfile. This produces a file in the build directory
|
||||
* called Testfile with a syntax similar to CMakeLists.txt. It contains
|
||||
* the SUBDIRS() and ADD_TEST() commands from the source CMakeLists.txt
|
||||
* file with CMake variables expanded. Only the subdirs and tests
|
||||
* within the valid control structures are replicated in Testfile
|
||||
* (i.e. SUBDIRS() and ADD_TEST() commands within IF() commands that are
|
||||
* not entered by CMake are not replicated in Testfile).
|
||||
*/
|
||||
void GenerateTestfile();
|
||||
|
||||
/**
|
||||
* Print the object state to std::cout.
|
||||
*/
|
||||
|
@ -211,6 +222,11 @@ public:
|
|||
*/
|
||||
void AddDefinition(const char* name, bool);
|
||||
|
||||
/**
|
||||
* Add a test to the build.
|
||||
*/
|
||||
void AddTest(const std::vector<std::string> &args);
|
||||
|
||||
/**
|
||||
* Specify the name of the project for this build.
|
||||
*/
|
||||
|
@ -510,6 +526,8 @@ protected:
|
|||
std::vector<std::string> m_Utilities;
|
||||
std::vector<std::string> m_UtilityDirectories;
|
||||
std::vector<std::string> m_ListFiles; // list of command files loaded
|
||||
std::vector<std::vector<std::string> > m_Tests; // list of tests and args
|
||||
|
||||
|
||||
cmTarget::LinkLibraries m_LinkLibraries;
|
||||
|
||||
|
|
Loading…
Reference in New Issue