mirror of
https://github.com/reactos/CMake.git
synced 2024-11-24 03:59:58 +00:00
ENH: Add set and get test propety command
This commit is contained in:
parent
ec3f3b5a2d
commit
bebc745824
@ -24,6 +24,7 @@
|
||||
#include "cmGetCMakePropertyCommand.cxx"
|
||||
#include "cmGetDirectoryPropertyCommand.cxx"
|
||||
#include "cmGetTargetPropertyCommand.cxx"
|
||||
#include "cmGetTestPropertyCommand.cxx"
|
||||
#include "cmITKWrapTclCommand.cxx"
|
||||
#include "cmIncludeExternalMSProjectCommand.cxx"
|
||||
#include "cmLinkLibrariesCommand.cxx"
|
||||
@ -32,6 +33,7 @@
|
||||
#include "cmRemoveCommand.cxx"
|
||||
#include "cmSetDirectoryPropertiesCommand.cxx"
|
||||
#include "cmSetTargetPropertiesCommand.cxx"
|
||||
#include "cmSetTestsPropertiesCommand.cxx"
|
||||
#include "cmSourceGroupCommand.cxx"
|
||||
#include "cmVTKMakeInstantiatorCommand.cxx"
|
||||
#include "cmVTKWrapJavaCommand.cxx"
|
||||
@ -64,6 +66,7 @@ void GetPredefinedCommands(std::list<cmCommand*>&
|
||||
commands.push_back(new cmGetCMakePropertyCommand);
|
||||
commands.push_back(new cmGetDirectoryPropertyCommand);
|
||||
commands.push_back(new cmGetTargetPropertyCommand);
|
||||
commands.push_back(new cmGetTestPropertyCommand);
|
||||
commands.push_back(new cmITKWrapTclCommand);
|
||||
commands.push_back(new cmIncludeExternalMSProjectCommand);
|
||||
commands.push_back(new cmLinkLibrariesCommand);
|
||||
@ -73,6 +76,7 @@ void GetPredefinedCommands(std::list<cmCommand*>&
|
||||
commands.push_back(new cmRemoveCommand);
|
||||
commands.push_back(new cmSetDirectoryPropertiesCommand);
|
||||
commands.push_back(new cmSetTargetPropertiesCommand);
|
||||
commands.push_back(new cmSetTestsPropertiesCommand);
|
||||
commands.push_back(new cmSourceGroupCommand);
|
||||
commands.push_back(new cmVTKMakeInstantiatorCommand);
|
||||
commands.push_back(new cmVTKWrapJavaCommand);
|
||||
|
47
Source/cmGetTestPropertyCommand.cxx
Normal file
47
Source/cmGetTestPropertyCommand.cxx
Normal file
@ -0,0 +1,47 @@
|
||||
/*=========================================================================
|
||||
|
||||
Program: CMake - Cross-Platform Makefile Generator
|
||||
Module: $RCSfile$
|
||||
Language: C++
|
||||
Date: $Date$
|
||||
Version: $Revision$
|
||||
|
||||
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
||||
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
||||
|
||||
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.
|
||||
|
||||
=========================================================================*/
|
||||
#include "cmGetTestPropertyCommand.h"
|
||||
|
||||
#include "cmake.h"
|
||||
#include "cmTest.h"
|
||||
|
||||
// cmGetTestPropertyCommand
|
||||
bool cmGetTestPropertyCommand::InitialPass(
|
||||
std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 3 )
|
||||
{
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string testName = args[0];
|
||||
std::string var = args[1];
|
||||
cmTest *test = m_Makefile->GetTest(testName.c_str());
|
||||
if (test)
|
||||
{
|
||||
const char *prop = test->GetProperty(args[2].c_str());
|
||||
if (prop)
|
||||
{
|
||||
m_Makefile->AddDefinition(var.c_str(), prop);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
m_Makefile->AddDefinition(var.c_str(), "NOTFOUND");
|
||||
return true;
|
||||
}
|
||||
|
66
Source/cmGetTestPropertyCommand.h
Normal file
66
Source/cmGetTestPropertyCommand.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*=========================================================================
|
||||
|
||||
Program: CMake - Cross-Platform Makefile Generator
|
||||
Module: $RCSfile$
|
||||
Language: C++
|
||||
Date: $Date$
|
||||
Version: $Revision$
|
||||
|
||||
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
||||
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
||||
|
||||
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.
|
||||
|
||||
=========================================================================*/
|
||||
#ifndef cmGetTestPropertyCommand_h
|
||||
#define cmGetTestPropertyCommand_h
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmGetTestPropertyCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
virtual cmCommand* Clone()
|
||||
{
|
||||
return new cmGetTestPropertyCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the input file.
|
||||
*/
|
||||
virtual bool InitialPass(std::vector<std::string> const& args);
|
||||
|
||||
/**
|
||||
* The name of the command as specified in CMakeList.txt.
|
||||
*/
|
||||
virtual const char* GetName() { return "GET_TEST_PROPERTY";}
|
||||
|
||||
/**
|
||||
* Succinct documentation.
|
||||
*/
|
||||
virtual const char* GetTerseDocumentation()
|
||||
{
|
||||
return "Get a property of the test.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Longer documentation.
|
||||
*/
|
||||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" GET_TEST_PROPERTY(test VAR property)\n"
|
||||
"Get a property from the Test. The value of the property is"
|
||||
"stored in the variable VAR. If the property is not found,"
|
||||
"CMake will report an error.";
|
||||
}
|
||||
|
||||
cmTypeMacro(cmGetTestPropertyCommand, cmCommand);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -156,14 +156,14 @@ void cmLocalGenerator::GenerateTestFiles()
|
||||
fout << "ADD_TEST(";
|
||||
fout << test->GetName() << " \"" << test->GetCommand() << "\"";
|
||||
|
||||
std::vector<cmStdString>::iterator argit;
|
||||
std::vector<cmStdString>::const_iterator argit;
|
||||
for (argit = test->GetArguments().begin();
|
||||
argit != test->GetArguments().end(); ++argit)
|
||||
{
|
||||
// Just double-quote all arguments so they are re-parsed
|
||||
// correctly by the test system.
|
||||
fout << " \"";
|
||||
for(std::string::iterator c = argit->begin(); c != argit->end(); ++c)
|
||||
for(std::string::const_iterator c = argit->begin(); c != argit->end(); ++c)
|
||||
{
|
||||
// Escape quotes within arguments. We should escape
|
||||
// backslashes too but we cannot because it makes the result
|
||||
|
@ -2621,3 +2621,8 @@ const std::vector<cmTest*> *cmMakefile::GetTests() const
|
||||
return &m_Tests;
|
||||
}
|
||||
|
||||
std::vector<cmTest*> *cmMakefile::GetTests()
|
||||
{
|
||||
return &m_Tests;
|
||||
}
|
||||
|
||||
|
@ -637,6 +637,7 @@ public:
|
||||
*/
|
||||
cmTest* GetTest(const char* testName) const;
|
||||
const std::vector<cmTest*> *GetTests() const;
|
||||
std::vector<cmTest*> *GetTests();
|
||||
|
||||
/**
|
||||
* Get a list of macros as a ; separated string
|
||||
|
110
Source/cmSetTestsPropertiesCommand.cxx
Normal file
110
Source/cmSetTestsPropertiesCommand.cxx
Normal file
@ -0,0 +1,110 @@
|
||||
/*=========================================================================
|
||||
|
||||
Program: CMake - Cross-Platform Makefile Generator
|
||||
Module: $RCSfile$
|
||||
Language: C++
|
||||
Date: $Date$
|
||||
Version: $Revision$
|
||||
|
||||
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
||||
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
||||
|
||||
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.
|
||||
|
||||
=========================================================================*/
|
||||
#include "cmSetTestsPropertiesCommand.h"
|
||||
|
||||
#include "cmake.h"
|
||||
#include "cmTest.h"
|
||||
|
||||
// cmSetTestsPropertiesCommand
|
||||
bool cmSetTestsPropertiesCommand::InitialPass(
|
||||
std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 1 )
|
||||
{
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
// first collect up the list of files
|
||||
std::vector<std::string> propertyPairs;
|
||||
bool doingFiles = true;
|
||||
int numFiles = 0;
|
||||
std::vector<std::string>::const_iterator j;
|
||||
for(j= args.begin(); j != args.end();++j)
|
||||
{
|
||||
if(*j == "PROPERTIES")
|
||||
{
|
||||
doingFiles = false;
|
||||
// now loop through the rest of the arguments, new style
|
||||
++j;
|
||||
while (j != args.end())
|
||||
{
|
||||
propertyPairs.push_back(*j);
|
||||
++j;
|
||||
if(j == args.end())
|
||||
{
|
||||
this->SetError("called with incorrect number of arguments.");
|
||||
return false;
|
||||
}
|
||||
propertyPairs.push_back(*j);
|
||||
++j;
|
||||
}
|
||||
// break out of the loop because j is already == end
|
||||
break;
|
||||
}
|
||||
else if (doingFiles)
|
||||
{
|
||||
numFiles++;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(propertyPairs.size() == 0)
|
||||
{
|
||||
this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<cmTest*> &tests = *m_Makefile->GetTests();
|
||||
// now loop over all the targets
|
||||
int i;
|
||||
unsigned int k;
|
||||
for(i = 0; i < numFiles; ++i)
|
||||
{
|
||||
bool found = false;
|
||||
// if the file is already in the makefile just set properites on it
|
||||
std::vector<cmTest*>::iterator it;
|
||||
for ( it = tests.begin(); it != tests.end(); ++ it )
|
||||
{
|
||||
cmTest* test = *it;
|
||||
if ( test->GetName() == args[i] )
|
||||
{
|
||||
// now loop through all the props and set them
|
||||
for (k = 0; k < propertyPairs.size(); k = k + 2)
|
||||
{
|
||||
test->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if file is not already in the makefile, then add it
|
||||
if ( ! found )
|
||||
{
|
||||
std::string message = "Can not find test to add properties to: ";
|
||||
message += args[i];
|
||||
this->SetError(message.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
65
Source/cmSetTestsPropertiesCommand.h
Normal file
65
Source/cmSetTestsPropertiesCommand.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*=========================================================================
|
||||
|
||||
Program: CMake - Cross-Platform Makefile Generator
|
||||
Module: $RCSfile$
|
||||
Language: C++
|
||||
Date: $Date$
|
||||
Version: $Revision$
|
||||
|
||||
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
||||
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
||||
|
||||
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.
|
||||
|
||||
=========================================================================*/
|
||||
#ifndef cmSetTestsPropertiesCommand_h
|
||||
#define cmSetTestsPropertiesCommand_h
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmSetTestsPropertiesCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
virtual cmCommand* Clone()
|
||||
{
|
||||
return new cmSetTestsPropertiesCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the input file.
|
||||
*/
|
||||
virtual bool InitialPass(std::vector<std::string> const& args);
|
||||
|
||||
/**
|
||||
* The name of the command as specified in CMakeList.txt.
|
||||
*/
|
||||
virtual const char* GetName() { return "SET_TESTS_PROPERTIES";}
|
||||
|
||||
/**
|
||||
* Succinct documentation.
|
||||
*/
|
||||
virtual const char* GetTerseDocumentation()
|
||||
{
|
||||
return "Set a property of the tests.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Longer documentation.
|
||||
*/
|
||||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" SET_TESTS_PROPERTIES(test1 [test2...] PROPERTIES prop1 value1 prop2 value2)\n"
|
||||
"Set a property for the tests. If the "
|
||||
"property is not found, CMake will report an error.";
|
||||
}
|
||||
|
||||
cmTypeMacro(cmSetTestsPropertiesCommand, cmCommand);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -49,3 +49,38 @@ void cmTest::SetArguments(const std::vector<cmStdString>& args)
|
||||
m_Args = args;
|
||||
}
|
||||
|
||||
const char *cmTest::GetProperty(const char* prop) const
|
||||
{
|
||||
std::map<cmStdString,cmStdString>::const_iterator i =
|
||||
m_Properties.find(prop);
|
||||
if (i != m_Properties.end())
|
||||
{
|
||||
return i->second.c_str();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool cmTest::GetPropertyAsBool(const char* prop) const
|
||||
{
|
||||
std::map<cmStdString,cmStdString>::const_iterator i =
|
||||
m_Properties.find(prop);
|
||||
if (i != m_Properties.end())
|
||||
{
|
||||
return cmSystemTools::IsOn(i->second.c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cmTest::SetProperty(const char* prop, const char* value)
|
||||
{
|
||||
if (!prop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!value)
|
||||
{
|
||||
value = "NOTFOUND";
|
||||
}
|
||||
m_Properties[prop] = value;
|
||||
}
|
||||
|
||||
|
@ -34,11 +34,11 @@ public:
|
||||
|
||||
///! Set the test name
|
||||
void SetName(const char* name);
|
||||
const char* GetName() { return m_Name.c_str(); }
|
||||
const char* GetName() const { return m_Name.c_str(); }
|
||||
void SetCommand(const char* command);
|
||||
const char* GetCommand() { return m_Command.c_str(); }
|
||||
const char* GetCommand() const { return m_Command.c_str(); }
|
||||
void SetArguments(const std::vector<cmStdString>& args);
|
||||
std::vector<cmStdString>& GetArguments()
|
||||
const std::vector<cmStdString>& GetArguments() const
|
||||
{
|
||||
return m_Args;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user