cmEnableTestingCommand.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmEnableTestingCommand.h"
  14. #include "cmLocalGenerator.h"
  15. // we do this in the final pass so that we now the subdirs have all
  16. // been defined
  17. bool cmEnableTestingCommand::InitialPass(std::vector<std::string> const&)
  18. {
  19. m_Makefile->AddDefinition("CMAKE_TESTING_ENABLED","1");
  20. return true;
  21. }
  22. void cmEnableTestingCommand::FinalPass()
  23. {
  24. // initialize the DartTestfile files for the tree
  25. this->CreateDartTestfileForMakefile(m_Makefile);
  26. }
  27. void cmEnableTestingCommand::CreateDartTestfileForMakefile(cmMakefile *mf)
  28. {
  29. // Create a full path filename for output Testfile
  30. std::string fname;
  31. fname = mf->GetStartOutputDirectory();
  32. fname += "/";
  33. if ( m_Makefile->IsSet("DART_ROOT") )
  34. {
  35. fname += "DartTestfile.txt";
  36. }
  37. else
  38. {
  39. fname += "CTestTestfile.cmake";
  40. }
  41. cmSystemTools::MakeDirectory(mf->GetStartOutputDirectory());
  42. // Open the output Testfile
  43. std::ofstream fout(fname.c_str());
  44. if (!fout)
  45. {
  46. cmSystemTools::Error("Error Writing ", fname.c_str());
  47. cmSystemTools::ReportLastSystemError("");
  48. return;
  49. }
  50. fout << "# CMake generated Testfile for " << std::endl
  51. << "#\tSource directory: "
  52. << mf->GetStartDirectory()
  53. << std::endl
  54. << "#\tBuild directory: " << mf->GetStartOutputDirectory()
  55. << std::endl
  56. << "# " << std::endl
  57. << "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source"
  58. << std::endl
  59. << "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands"
  60. << std::endl
  61. << "# that are excluded by CMake control structures, i.e. IF() commands."
  62. << std::endl
  63. << "#" << std::endl
  64. << "# The next line is critical for Dart to work" << std::endl
  65. << "# Duh :-)" << std::endl << std::endl;
  66. // get our output directory
  67. std::string outDir = mf->GetStartOutputDirectory();
  68. outDir += "/";
  69. // write out the subdirs for the current directory
  70. std::vector<cmLocalGenerator *>& children =
  71. mf->GetLocalGenerator()->GetChildren();
  72. unsigned int i;
  73. if (children.size())
  74. {
  75. fout << "SUBDIRS(";
  76. std::string binP = children[0]->GetMakefile()->GetStartOutputDirectory();
  77. cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
  78. fout << binP.c_str();
  79. for(i = 1; i < children.size(); ++i)
  80. {
  81. binP = children[i]->GetMakefile()->GetStartOutputDirectory();
  82. cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
  83. fout << " " << binP.c_str();
  84. }
  85. fout << ")" << std::endl << std::endl;;
  86. }
  87. fout.close();
  88. // then recurse
  89. if (children.size())
  90. {
  91. for(i = 0; i < children.size(); ++i)
  92. {
  93. this->CreateDartTestfileForMakefile(children[i]->GetMakefile());
  94. }
  95. }
  96. return;
  97. }