cmEnableTestingCommand.cxx 3.37 KB
Newer Older
1
2
/*=========================================================================

3
  Program:   CMake - Cross-Platform Makefile Generator
4
5
6
7
8
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

9
10
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11

Will Schroeder's avatar
Will Schroeder committed
12
13
14
     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.
15
16
17

=========================================================================*/
#include "cmEnableTestingCommand.h"
18
#include "cmLocalGenerator.h"
19
20
21

// we do this in the final pass so that we now the subdirs have all 
// been defined
Ken Martin's avatar
Ken Martin committed
22
23
24
25
26
27
bool cmEnableTestingCommand::InitialPass(std::vector<std::string> const&)
{
  m_Makefile->AddDefinition("CMAKE_TESTING_ENABLED","1");
  return true;
}

28
void cmEnableTestingCommand::FinalPass()
29
30
31
32
33
34
{
  // initialize the DartTestfile files for the tree
  this->CreateDartTestfileForMakefile(m_Makefile);
}

void cmEnableTestingCommand::CreateDartTestfileForMakefile(cmMakefile *mf)
35
36
37
{
  // Create a full path filename for output Testfile
  std::string fname;
38
  fname = mf->GetStartOutputDirectory();
39
  fname += "/";
40
  if ( m_Makefile->IsSet("CTEST_NEW_FORMAT") )
41
    {
42
    fname += "CTestTestfile.cmake";
43
44
45
    }
  else
    {
46
    fname += "DartTestfile.txt";
47
    }
48
  
49
50
  cmSystemTools::MakeDirectory(mf->GetStartOutputDirectory());
  
51
52
53
54
55
  // Open the output Testfile
  std::ofstream fout(fname.c_str());
  if (!fout)
    {
    cmSystemTools::Error("Error Writing ", fname.c_str());
56
    cmSystemTools::ReportLastSystemError("");
57
58
59
60
61
    return;
    }
  
  fout << "# CMake generated Testfile for " << std::endl
       << "#\tSource directory: "
62
       << mf->GetStartDirectory()
63
       << std::endl
64
       << "#\tBuild directory: " << mf->GetStartOutputDirectory()
65
66
67
68
69
70
71
72
       << 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
Bill Hoffman's avatar
Bill Hoffman committed
73
74
75
       << "#" << std::endl 
       << "# The next line is critical for Dart to work" << std::endl 
       << "# Duh :-)" << std::endl << std::endl;
76

77
  // get our output directory
78
  std::string outDir = mf->GetStartOutputDirectory();
79
80
  outDir += "/";
  
81
  // write out the subdirs for the current directory
82
83
84
85
86
  std::vector<cmLocalGenerator *>& children = 
    mf->GetLocalGenerator()->GetChildren();
  
  unsigned int i;
  if (children.size())
87
88
    {
    fout << "SUBDIRS(";
89
    std::string binP = children[0]->GetMakefile()->GetStartOutputDirectory();
90
91
    cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
    fout << binP.c_str();
92
    for(i = 1; i < children.size(); ++i)
93
      {
94
      binP = children[i]->GetMakefile()->GetStartOutputDirectory();
95
96
      cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
      fout << " " << binP.c_str();
97
98
99
100
      }
    fout << ")" << std::endl << std::endl;;
    }
  fout.close();  
101
  
102
103
104
105
106
107
108
109
110
111
  // then recurse
  if (children.size())
    {
    for(i = 0; i < children.size(); ++i)
      {
      this->CreateDartTestfileForMakefile(children[i]->GetMakefile());
      }
    }
  
  
112
113
114
  return;
}