cmEnableTestingCommand.cxx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "cmSubDirectory.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. // Create a full path filename for output Testfile
  25. std::string fname;
  26. fname = m_Makefile->GetStartOutputDirectory();
  27. fname += "/";
  28. fname += "DartTestfile.txt";
  29. cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory());
  30. // Open the output Testfile
  31. std::ofstream fout(fname.c_str());
  32. if (!fout)
  33. {
  34. cmSystemTools::Error("Error Writing ", fname.c_str());
  35. cmSystemTools::ReportLastSystemError("");
  36. return;
  37. }
  38. fout << "# CMake generated Testfile for " << std::endl
  39. << "#\tSource directory: "
  40. << m_Makefile->GetStartDirectory()
  41. << std::endl
  42. << "#\tBuild directory: " << m_Makefile->GetStartOutputDirectory()
  43. << std::endl
  44. << "# " << std::endl
  45. << "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source"
  46. << std::endl
  47. << "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands"
  48. << std::endl
  49. << "# that are excluded by CMake control structures, i.e. IF() commands."
  50. << std::endl
  51. << "#" << std::endl
  52. << "# The next line is critical for Dart to work" << std::endl
  53. << "# Duh :-)" << std::endl << std::endl;
  54. // get our output directory
  55. std::string outDir = m_Makefile->GetStartOutputDirectory();
  56. outDir += "/";
  57. // write out the subdirs for the current directory
  58. if (!m_Makefile->GetSubDirectories().empty())
  59. {
  60. fout << "SUBDIRS(";
  61. const std::vector<cmSubDirectory>& subdirs
  62. = m_Makefile->GetSubDirectories();
  63. std::vector<cmSubDirectory>::const_iterator i = subdirs.begin();
  64. std::string binP = (*i).BinaryPath;
  65. cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
  66. fout << binP.c_str();
  67. ++i;
  68. for(; i != subdirs.end(); ++i)
  69. {
  70. binP = (*i).BinaryPath;
  71. cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
  72. fout << " " << binP.c_str();
  73. }
  74. fout << ")" << std::endl << std::endl;;
  75. }
  76. fout.close();
  77. return;
  78. }