diff options
author | Jim Miller <millerjv@crd.ge.com> | 2001-06-06 00:34:01 (GMT) |
---|---|---|
committer | Jim Miller <millerjv@crd.ge.com> | 2001-06-06 00:34:01 (GMT) |
commit | 84dc25e9f5cde423b0b5b23542f305ac6837fb31 (patch) | |
tree | 4e40a6c85a5e7915cc512a142e18e7c01d017476 | |
parent | 6282d41c2a8ca5129565f17dfb9eacdead83c898 (diff) | |
download | CMake-84dc25e9f5cde423b0b5b23542f305ac6837fb31.zip CMake-84dc25e9f5cde423b0b5b23542f305ac6837fb31.tar.gz CMake-84dc25e9f5cde423b0b5b23542f305ac6837fb31.tar.bz2 |
ENH: Added AddTest, and GenerateTestfile routines
-rw-r--r-- | Source/cmMakefile.cxx | 86 | ||||
-rw-r--r-- | Source/cmMakefile.h | 20 |
2 files changed, 105 insertions, 1 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 446729e..a12ac2b 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 8e1db98..fccd779 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -110,6 +110,17 @@ public: * Produce the output makefile. */ 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. @@ -212,6 +223,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. */ void SetProjectName(const char*); @@ -510,7 +526,9 @@ 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; std::string m_IncludeFileRegularExpression; |