cmEnableTestingCommand.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // we do this in the final pass so that we now the subdirs have all
  15. // been defined
  16. bool cmEnableTestingCommand::InitialPass(std::vector<std::string> const&)
  17. {
  18. m_Makefile->AddDefinition("CMAKE_TESTING_ENABLED","1");
  19. return true;
  20. }
  21. void cmEnableTestingCommand::FinalPass()
  22. {
  23. // Create a full path filename for output Testfile
  24. std::string fname;
  25. fname = m_Makefile->GetStartOutputDirectory();
  26. fname += "/";
  27. fname += "DartTestfile.txt";
  28. cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory());
  29. // Open the output Testfile
  30. std::ofstream fout(fname.c_str());
  31. if (!fout)
  32. {
  33. cmSystemTools::Error("Error Writing ", fname.c_str());
  34. cmSystemTools::ReportLastSystemError("");
  35. return;
  36. }
  37. fout << "# CMake generated Testfile for " << std::endl
  38. << "#\tSource directory: "
  39. << m_Makefile->GetStartDirectory()
  40. << std::endl
  41. << "#\tBuild directory: " << m_Makefile->GetStartOutputDirectory()
  42. << std::endl
  43. << "# " << std::endl
  44. << "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source"
  45. << std::endl
  46. << "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands"
  47. << std::endl
  48. << "# that are excluded by CMake control structures, i.e. IF() commands."
  49. << std::endl
  50. << "#" << std::endl
  51. << "# The next line is critical for Dart to work" << std::endl
  52. << "# Duh :-)" << std::endl << std::endl;
  53. // write out the subdirs for the current directory
  54. if (!m_Makefile->GetSubDirectories().empty())
  55. {
  56. fout << "SUBDIRS(";
  57. const std::vector<std::pair<cmStdString, bool> >& subdirs = m_Makefile->GetSubDirectories();
  58. std::vector<std::pair<cmStdString, bool> >::const_iterator i = subdirs.begin();
  59. fout << (*i).first.c_str();
  60. ++i;
  61. for(; i != subdirs.end(); ++i)
  62. {
  63. fout << " " << i->first.c_str();
  64. }
  65. fout << ")" << std::endl << std::endl;;
  66. }
  67. fout.close();
  68. return;
  69. }