BUG: fix some bad changes in progress calc
[cmake.git] / Source / cmCreateTestSourceList.cxx
bloba0ca494222582161b99acdd85f41fd6943b51a83
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCreateTestSourceList.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.44 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCreateTestSourceList.h"
18 #include "cmSourceFile.h"
20 // cmCreateTestSourceList
21 bool cmCreateTestSourceList
22 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
24 if (args.size() < 3)
26 this->SetError("called with wrong number of arguments.");
27 return false;
31 std::vector<std::string>::const_iterator i = args.begin();
32 std::string extraInclude;
33 std::string function;
34 std::vector<std::string> tests;
35 // extract extra include and function ot
36 for(; i != args.end(); i++)
38 if(*i == "EXTRA_INCLUDE")
40 ++i;
41 if(i == args.end())
43 this->SetError("incorrect arguments to EXTRA_INCLUDE");
44 return false;
46 extraInclude = "#include \"";
47 extraInclude += *i;
48 extraInclude += "\"\n";
50 else if(*i == "FUNCTION")
52 ++i;
53 if(i == args.end())
55 this->SetError("incorrect arguments to FUNCTION");
56 return false;
58 function = *i;
59 function += "(&ac, &av);\n";
61 else
63 tests.push_back(*i);
66 i = tests.begin();
68 // Name of the source list
70 const char* sourceList = i->c_str();
71 ++i;
73 // Name of the test driver
74 // make sure they specified an extension
75 if (cmSystemTools::GetFilenameExtension(*i).size() < 2)
77 this->SetError(
78 "You must specify a file extenion for the test driver file.");
79 return false;
81 std::string driver = this->Makefile->GetCurrentOutputDirectory();
82 driver += "/";
83 driver += *i;
84 ++i;
86 std::string configFile =
87 this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
89 configFile += "/Templates/TestDriver.cxx.in";
90 // Create the test driver file
92 std::vector<std::string>::const_iterator testsBegin = i;
93 std::vector<std::string> tests_func_name;
95 // The rest of the arguments consist of a list of test source files.
96 // Sadly, they can be in directories. Let's find a unique function
97 // name for the corresponding test, and push it to the tests_func_name
98 // list.
99 // For the moment:
100 // - replace spaces ' ', ':' and '/' with underscores '_'
101 std::string forwardDeclareCode;
102 for(i = testsBegin; i != tests.end(); ++i)
104 if(*i == "EXTRA_INCLUDE")
106 break;
108 std::string func_name;
109 if (cmSystemTools::GetFilenamePath(*i).size() > 0)
111 func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
112 cmSystemTools::GetFilenameWithoutLastExtension(*i);
114 else
116 func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
118 cmSystemTools::ConvertToUnixSlashes(func_name);
119 cmSystemTools::ReplaceString(func_name, " ", "_");
120 cmSystemTools::ReplaceString(func_name, "/", "_");
121 cmSystemTools::ReplaceString(func_name, ":", "_");
122 tests_func_name.push_back(func_name);
123 forwardDeclareCode += "int ";
124 forwardDeclareCode += func_name;
125 forwardDeclareCode += "(int, char*[]);\n";
128 std::string functionMapCode;
129 int numTests = 0;
130 std::vector<std::string>::iterator j;
131 for(i = testsBegin, j = tests_func_name.begin(); i != tests.end(); ++i, ++j)
133 std::string func_name;
134 if (cmSystemTools::GetFilenamePath(*i).size() > 0)
136 func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
137 cmSystemTools::GetFilenameWithoutLastExtension(*i);
139 else
141 func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
143 functionMapCode += " {\n"
144 " \"";
145 functionMapCode += func_name;
146 functionMapCode += "\",\n"
147 " ";
148 functionMapCode += *j;
149 functionMapCode += "\n"
150 " },\n";
151 numTests++;
153 if(extraInclude.size())
155 this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES",
156 extraInclude.c_str());
158 if(function.size())
160 this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION",
161 function.c_str());
163 this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS",
164 forwardDeclareCode.c_str());
165 this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES",
166 functionMapCode.c_str());
167 bool res = true;
168 if ( !this->Makefile->ConfigureFile(configFile.c_str(), driver.c_str(),
169 false, true, false) )
171 res = false;
174 // Construct the source list.
175 std::string sourceListValue;
177 cmSourceFile* sf = this->Makefile->GetOrCreateSource(driver.c_str());
178 sf->SetProperty("ABSTRACT","0");
179 sourceListValue = args[1];
181 for(i = testsBegin; i != tests.end(); ++i)
183 cmSourceFile* sf = this->Makefile->GetOrCreateSource(i->c_str());
184 sf->SetProperty("ABSTRACT","0");
185 sourceListValue += ";";
186 sourceListValue += *i;
189 this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
190 return res;