CMake/Source/cmCreateTestSourceList.cxx

155 lines
4.9 KiB
C++
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCreateTestSourceList.h"
2002-09-28 00:24:10 +04:00
#include "cmSourceFile.h"
// cmCreateTestSourceList
bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
if (args.size() < 3) {
this->SetError("called with wrong number of arguments.");
return false;
}
2006-03-10 21:06:26 +03:00
std::vector<std::string>::const_iterator i = args.begin();
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;
}
extraInclude = "#include \"";
extraInclude += *i;
extraInclude += "\"\n";
} else if (*i == "FUNCTION") {
++i;
if (i == args.end()) {
this->SetError("incorrect arguments to FUNCTION");
return false;
}
function = *i;
function += "(&ac, &av);\n";
} else {
tests.push_back(*i);
}
}
i = tests.begin();
2006-03-10 21:06:26 +03:00
// Name of the source list
const char* sourceList = i->c_str();
++i;
// Name of the test driver
2002-07-31 00:19:14 +04:00
// make sure they specified an extension
if (cmSystemTools::GetFilenameExtension(*i).size() < 2) {
2006-03-10 21:06:26 +03:00
this->SetError(
2012-02-26 22:44:20 +04:00
"You must specify a file extension for the test driver file.");
2002-07-31 00:19:14 +04:00
return false;
}
std::string driver = this->Makefile->GetCurrentBinaryDirectory();
driver += "/";
driver += *i;
++i;
std::string configFile = cmSystemTools::GetCMakeRoot();
2006-03-15 19:02:08 +03:00
configFile += "/Templates/TestDriver.cxx.in";
// Create the test driver file
2006-03-10 21:06:26 +03:00
std::vector<std::string>::const_iterator testsBegin = i;
std::vector<std::string> tests_func_name;
// 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
// name for the corresponding test, and push it to the tests_func_name
2006-03-10 21:06:26 +03:00
// list.
// For the moment:
// - replace spaces ' ', ':' and '/' with underscores '_'
std::string forwardDeclareCode;
for (i = testsBegin; i != tests.end(); ++i) {
if (*i == "EXTRA_INCLUDE") {
break;
}
2002-07-31 00:19:14 +04:00
std::string func_name;
if (!cmSystemTools::GetFilenamePath(*i).empty()) {
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 {
2002-07-31 00:19:14 +04:00
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
cmSystemTools::ConvertToUnixSlashes(func_name);
std::replace(func_name.begin(), func_name.end(), ' ', '_');
std::replace(func_name.begin(), func_name.end(), '/', '_');
std::replace(func_name.begin(), func_name.end(), ':', '_');
tests_func_name.push_back(func_name);
forwardDeclareCode += "int ";
forwardDeclareCode += func_name;
forwardDeclareCode += "(int, char*[]);\n";
}
2006-03-10 21:06:26 +03:00
std::string functionMapCode;
int numTests = 0;
std::vector<std::string>::iterator j;
for (i = testsBegin, j = tests_func_name.begin(); i != tests.end();
++i, ++j) {
2002-07-31 00:19:14 +04:00
std::string func_name;
if (!cmSystemTools::GetFilenamePath(*i).empty()) {
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 {
2002-07-31 00:19:14 +04:00
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
functionMapCode += " {\n"
" \"";
functionMapCode += func_name;
functionMapCode += "\",\n"
" ";
functionMapCode += *j;
functionMapCode += "\n"
" },\n";
numTests++;
}
if (!extraInclude.empty()) {
2006-03-15 19:02:08 +03:00
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES",
extraInclude.c_str());
}
if (!function.empty()) {
2006-03-15 19:02:08 +03:00
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION",
function.c_str());
}
2006-03-15 19:02:08 +03:00
this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS",
forwardDeclareCode.c_str());
2006-03-15 19:02:08 +03:00
this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES",
functionMapCode.c_str());
bool res = true;
if (!this->Makefile->ConfigureFile(configFile.c_str(), driver.c_str(), false,
true, false)) {
res = false;
}
// Construct the source list.
std::string sourceListValue;
{
cmSourceFile* sf = this->Makefile->GetOrCreateSource(driver);
sf->SetProperty("ABSTRACT", "0");
sourceListValue = args[1];
}
for (i = testsBegin; i != tests.end(); ++i) {
cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
sf->SetProperty("ABSTRACT", "0");
sourceListValue += ";";
sourceListValue += *i;
}
2006-03-15 19:02:08 +03:00
this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
return res;
}