2001-06-06 21:58:18 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2001-06-06 21:58:18 +04:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2001-06-06 21:58:18 +04:00
|
|
|
|
2002-01-21 23:30:43 +03:00
|
|
|
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.
|
2001-06-06 21:58:18 +04:00
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmEnableTestingCommand.h"
|
2005-03-18 18:41:41 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2001-06-06 21:58:18 +04:00
|
|
|
|
|
|
|
// we do this in the final pass so that we now the subdirs have all
|
|
|
|
// been defined
|
2003-12-30 00:27:06 +03:00
|
|
|
bool cmEnableTestingCommand::InitialPass(std::vector<std::string> const&)
|
|
|
|
{
|
|
|
|
m_Makefile->AddDefinition("CMAKE_TESTING_ENABLED","1");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-06-06 21:58:18 +04:00
|
|
|
void cmEnableTestingCommand::FinalPass()
|
2005-03-18 18:41:41 +03:00
|
|
|
{
|
|
|
|
// initialize the DartTestfile files for the tree
|
|
|
|
this->CreateDartTestfileForMakefile(m_Makefile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmEnableTestingCommand::CreateDartTestfileForMakefile(cmMakefile *mf)
|
2001-06-06 21:58:18 +04:00
|
|
|
{
|
|
|
|
// Create a full path filename for output Testfile
|
|
|
|
std::string fname;
|
2005-03-18 18:41:41 +03:00
|
|
|
fname = mf->GetStartOutputDirectory();
|
2001-06-06 21:58:18 +04:00
|
|
|
fname += "/";
|
2005-04-04 20:22:08 +04:00
|
|
|
if ( m_Makefile->IsSet("CTEST_NEW_FORMAT") )
|
2005-04-01 23:57:55 +04:00
|
|
|
{
|
2005-04-04 20:22:08 +04:00
|
|
|
fname += "CTestTestfile.cmake";
|
2005-04-01 23:57:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-04 20:22:08 +04:00
|
|
|
fname += "DartTestfile.txt";
|
2005-04-01 23:57:55 +04:00
|
|
|
}
|
2001-06-06 21:58:18 +04:00
|
|
|
|
2005-03-18 18:41:41 +03:00
|
|
|
cmSystemTools::MakeDirectory(mf->GetStartOutputDirectory());
|
|
|
|
|
2001-06-06 21:58:18 +04:00
|
|
|
// Open the output Testfile
|
|
|
|
std::ofstream fout(fname.c_str());
|
|
|
|
if (!fout)
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Error Writing ", fname.c_str());
|
2004-09-08 00:55:25 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("");
|
2001-06-06 21:58:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fout << "# CMake generated Testfile for " << std::endl
|
|
|
|
<< "#\tSource directory: "
|
2005-03-18 18:41:41 +03:00
|
|
|
<< mf->GetStartDirectory()
|
2001-06-06 21:58:18 +04:00
|
|
|
<< std::endl
|
2005-03-18 18:41:41 +03:00
|
|
|
<< "#\tBuild directory: " << mf->GetStartOutputDirectory()
|
2001-06-06 21:58:18 +04:00
|
|
|
<< 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
|
2001-06-29 00:45:22 +04:00
|
|
|
<< "#" << std::endl
|
|
|
|
<< "# The next line is critical for Dart to work" << std::endl
|
|
|
|
<< "# Duh :-)" << std::endl << std::endl;
|
2001-06-06 21:58:18 +04:00
|
|
|
|
2005-03-15 19:22:08 +03:00
|
|
|
// get our output directory
|
2005-03-18 18:41:41 +03:00
|
|
|
std::string outDir = mf->GetStartOutputDirectory();
|
2005-03-15 19:22:08 +03:00
|
|
|
outDir += "/";
|
|
|
|
|
2001-06-06 21:58:18 +04:00
|
|
|
// write out the subdirs for the current directory
|
2005-03-18 18:41:41 +03:00
|
|
|
std::vector<cmLocalGenerator *>& children =
|
|
|
|
mf->GetLocalGenerator()->GetChildren();
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
if (children.size())
|
2001-06-06 21:58:18 +04:00
|
|
|
{
|
|
|
|
fout << "SUBDIRS(";
|
2005-03-18 18:41:41 +03:00
|
|
|
std::string binP = children[0]->GetMakefile()->GetStartOutputDirectory();
|
2005-03-15 19:22:08 +03:00
|
|
|
cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
|
|
|
|
fout << binP.c_str();
|
2005-03-18 18:41:41 +03:00
|
|
|
for(i = 1; i < children.size(); ++i)
|
2001-06-06 21:58:18 +04:00
|
|
|
{
|
2005-03-18 18:41:41 +03:00
|
|
|
binP = children[i]->GetMakefile()->GetStartOutputDirectory();
|
2005-03-15 19:22:08 +03:00
|
|
|
cmSystemTools::ReplaceString(binP, outDir.c_str(), "");
|
|
|
|
fout << " " << binP.c_str();
|
2001-06-06 21:58:18 +04:00
|
|
|
}
|
|
|
|
fout << ")" << std::endl << std::endl;;
|
|
|
|
}
|
|
|
|
fout.close();
|
2005-03-14 19:29:15 +03:00
|
|
|
|
2005-03-18 18:41:41 +03:00
|
|
|
// then recurse
|
|
|
|
if (children.size())
|
|
|
|
{
|
|
|
|
for(i = 0; i < children.size(); ++i)
|
|
|
|
{
|
|
|
|
this->CreateDartTestfileForMakefile(children[i]->GetMakefile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-06 21:58:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|