2002-03-21 00:19:00 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-03-21 00:19:00 +03: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.
|
2002-03-21 00:19:00 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
2002-03-21 00:19:00 +03:00
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmCreateTestSourceList.h"
|
2002-09-28 00:24:10 +04:00
|
|
|
#include "cmSourceFile.h"
|
2002-03-21 00:19:00 +03:00
|
|
|
|
|
|
|
// cmCreateTestSourceList
|
2002-12-12 02:13:33 +03:00
|
|
|
bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args)
|
2002-03-21 00:19:00 +03:00
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
if (args.size() < 3)
|
2002-03-21 00:19:00 +03:00
|
|
|
{
|
2002-03-27 01:53:07 +03:00
|
|
|
this->SetError("called with wrong number of arguments.");
|
|
|
|
return false;
|
2002-03-21 00:19:00 +03:00
|
|
|
}
|
2002-03-27 00:42:43 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2002-12-12 02:13:33 +03:00
|
|
|
std::vector<std::string>::const_iterator i = args.begin();
|
2002-04-05 01:53:37 +04:00
|
|
|
std::string extraInclude;
|
|
|
|
std::string function;
|
|
|
|
std::vector<std::string> tests;
|
|
|
|
// extract extra include and function ot
|
|
|
|
for(; i != args.end(); i++)
|
|
|
|
{
|
|
|
|
if(*i == "EXTRA_INCLUDE")
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if(i == args.end())
|
|
|
|
{
|
|
|
|
this->SetError("incorrect arguments to EXTRA_INCLUDE");
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-28 20:31:18 +04:00
|
|
|
extraInclude = "#include \"";
|
|
|
|
extraInclude += *i;
|
|
|
|
extraInclude += "\"\n";
|
2002-04-05 01:53:37 +04:00
|
|
|
}
|
|
|
|
else if(*i == "FUNCTION")
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if(i == args.end())
|
|
|
|
{
|
|
|
|
this->SetError("incorrect arguments to FUNCTION");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
function = *i;
|
2004-04-28 20:31:18 +04:00
|
|
|
function += "(&ac, &av);\n";
|
2002-04-05 01:53:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tests.push_back(*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i = tests.begin();
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2002-03-27 00:42:43 +03:00
|
|
|
// Name of the source list
|
|
|
|
|
2002-03-21 00:19:00 +03:00
|
|
|
const char* sourceList = i->c_str();
|
|
|
|
++i;
|
2002-03-27 00:42:43 +03:00
|
|
|
|
|
|
|
// Name of the test driver
|
2002-07-31 00:19:14 +04:00
|
|
|
// make sure they specified an extension
|
2002-07-31 19:07:09 +04:00
|
|
|
if (cmSystemTools::GetFilenameExtension(*i).size() < 2)
|
2002-07-31 00:19:14 +04:00
|
|
|
{
|
2006-03-10 21:06:26 +03:00
|
|
|
this->SetError(
|
|
|
|
"You must specify a file extenion for the test driver file.");
|
2002-07-31 00:19:14 +04:00
|
|
|
return false;
|
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
std::string driver = this->Makefile->GetCurrentOutputDirectory();
|
2002-03-21 00:19:00 +03:00
|
|
|
driver += "/";
|
|
|
|
driver += *i;
|
|
|
|
++i;
|
2002-03-27 00:42:43 +03:00
|
|
|
|
2006-03-10 21:06:26 +03:00
|
|
|
std::string configFile =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
|
|
|
|
|
2004-04-28 20:31:18 +04:00
|
|
|
configFile += "/Templates/TestDriver.cxx.in";
|
2002-03-21 00:19:00 +03:00
|
|
|
// Create the test driver file
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2002-12-12 02:13:33 +03:00
|
|
|
std::vector<std::string>::const_iterator testsBegin = i;
|
2002-03-27 02:06:36 +03:00
|
|
|
std::vector<std::string> tests_func_name;
|
2002-03-27 00:42:43 +03:00
|
|
|
|
|
|
|
// The rest of the arguments consist of a list of test source files.
|
2006-03-10 21:06:26 +03:00
|
|
|
// Sadly, they can be in directories. Let's find a unique function
|
2002-03-27 02:06:36 +03:00
|
|
|
// name for the corresponding test, and push it to the tests_func_name
|
2006-03-10 21:06:26 +03:00
|
|
|
// list.
|
2002-03-27 00:42:43 +03:00
|
|
|
// For the moment:
|
|
|
|
// - replace spaces ' ', ':' and '/' with underscores '_'
|
2004-04-28 20:31:18 +04:00
|
|
|
std::string forwardDeclareCode;
|
2002-04-05 01:53:37 +04:00
|
|
|
for(i = testsBegin; i != tests.end(); ++i)
|
2002-03-21 00:19:00 +03:00
|
|
|
{
|
2002-04-05 01:53:37 +04:00
|
|
|
if(*i == "EXTRA_INCLUDE")
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2002-07-31 00:19:14 +04:00
|
|
|
std::string func_name;
|
|
|
|
if (cmSystemTools::GetFilenamePath(*i).size() > 0)
|
|
|
|
{
|
2006-03-10 21:06:26 +03:00
|
|
|
func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
|
2002-07-31 00:19:14 +04:00
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(*i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
|
|
|
|
}
|
2002-03-27 02:06:36 +03:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(func_name);
|
|
|
|
cmSystemTools::ReplaceString(func_name, " ", "_");
|
|
|
|
cmSystemTools::ReplaceString(func_name, "/", "_");
|
|
|
|
cmSystemTools::ReplaceString(func_name, ":", "_");
|
|
|
|
tests_func_name.push_back(func_name);
|
2004-04-28 20:31:18 +04:00
|
|
|
forwardDeclareCode += "int ";
|
|
|
|
forwardDeclareCode += func_name;
|
|
|
|
forwardDeclareCode += "(int, char*[]);\n";
|
2002-03-21 00:19:00 +03:00
|
|
|
}
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2004-04-28 20:31:18 +04:00
|
|
|
std::string functionMapCode;
|
2002-03-21 00:19:00 +03:00
|
|
|
int numTests = 0;
|
2002-03-27 02:06:36 +03:00
|
|
|
std::vector<std::string>::iterator j;
|
2002-04-05 01:53:37 +04:00
|
|
|
for(i = testsBegin, j = tests_func_name.begin(); i != tests.end(); ++i, ++j)
|
2002-03-21 00:19:00 +03:00
|
|
|
{
|
2002-07-31 00:19:14 +04:00
|
|
|
std::string func_name;
|
|
|
|
if (cmSystemTools::GetFilenamePath(*i).size() > 0)
|
|
|
|
{
|
2006-03-10 21:06:26 +03:00
|
|
|
func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
|
2002-07-31 00:19:14 +04:00
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(*i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
|
|
|
|
}
|
2004-04-28 20:31:18 +04:00
|
|
|
functionMapCode += " {\n"
|
|
|
|
" \"";
|
|
|
|
functionMapCode += func_name;
|
|
|
|
functionMapCode += "\",\n"
|
|
|
|
" ";
|
|
|
|
functionMapCode += *j;
|
|
|
|
functionMapCode += "\n"
|
2002-03-27 01:53:07 +03:00
|
|
|
" },\n";
|
2002-03-21 00:19:00 +03:00
|
|
|
numTests++;
|
|
|
|
}
|
2004-04-28 20:31:18 +04:00
|
|
|
if(extraInclude.size())
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES",
|
|
|
|
extraInclude.c_str());
|
2004-04-28 20:31:18 +04:00
|
|
|
}
|
2002-04-05 01:53:37 +04:00
|
|
|
if(function.size())
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION",
|
|
|
|
function.c_str());
|
2002-04-05 01:53:37 +04:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS",
|
2006-03-10 21:06:26 +03:00
|
|
|
forwardDeclareCode.c_str());
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES",
|
2006-03-10 21:06:26 +03:00
|
|
|
functionMapCode.c_str());
|
2004-05-27 20:56:52 +04:00
|
|
|
bool res = true;
|
2006-03-15 19:02:08 +03:00
|
|
|
if ( !this->Makefile->ConfigureFile(configFile.c_str(), driver.c_str(),
|
2006-03-10 21:06:26 +03:00
|
|
|
false, true, false) )
|
2004-05-27 20:56:52 +04:00
|
|
|
{
|
|
|
|
res = false;
|
|
|
|
}
|
2002-03-27 00:42:43 +03:00
|
|
|
|
|
|
|
// Create the source list
|
2002-03-21 00:19:00 +03:00
|
|
|
cmSourceFile cfile;
|
2002-06-19 20:52:16 +04:00
|
|
|
std::string sourceListValue;
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2002-08-16 19:20:18 +04:00
|
|
|
cfile.SetProperty("ABSTRACT","0");
|
2006-03-10 21:06:26 +03:00
|
|
|
cfile.SetName(cmSystemTools::GetFilenameWithoutExtension(args[1]).c_str(),
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetCurrentOutputDirectory(),
|
2006-03-10 21:06:26 +03:00
|
|
|
cmSystemTools::GetFilenameExtension(args[1]).c_str()+1,
|
2002-03-27 00:42:43 +03:00
|
|
|
false);
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddSource(cfile);
|
2003-06-06 17:06:12 +04:00
|
|
|
sourceListValue = args[1];
|
2006-03-10 21:06:26 +03:00
|
|
|
|
2002-04-05 01:53:37 +04:00
|
|
|
for(i = testsBegin; i != tests.end(); ++i)
|
2002-03-21 00:19:00 +03:00
|
|
|
{
|
2002-10-17 18:51:23 +04:00
|
|
|
cmSourceFile icfile;
|
|
|
|
icfile.SetProperty("ABSTRACT","0");
|
2006-03-10 21:06:26 +03:00
|
|
|
icfile.SetName(i->c_str(),
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetCurrentDirectory(),
|
|
|
|
this->Makefile->GetSourceExtensions(),
|
|
|
|
this->Makefile->GetHeaderExtensions());
|
|
|
|
this->Makefile->AddSource(icfile);
|
2002-06-19 20:52:16 +04:00
|
|
|
sourceListValue += ";";
|
|
|
|
sourceListValue += *i;
|
2002-03-21 00:19:00 +03:00
|
|
|
}
|
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
|
2004-05-27 20:56:52 +04:00
|
|
|
return res;
|
2002-03-21 00:19:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|