mirror of
https://github.com/reactos/CMake.git
synced 2024-11-30 15:00:41 +00:00
ENH: Add GET/SET_DIRECTORY_PROPERTY/PROPERTIES commands so that we can change include directories and get all sorts of things. Closes Bug #25 - Get_CMAKE_PROPERTIES
This commit is contained in:
parent
0b7d154ebd
commit
aff8c7bcd6
@ -81,6 +81,7 @@
|
||||
#include "cmExportLibraryDependencies.cxx"
|
||||
#include "cmFLTKWrapUICommand.cxx"
|
||||
#include "cmGetCMakePropertyCommand.cxx"
|
||||
#include "cmGetDirectoryPropertyCommand.cxx"
|
||||
#include "cmGetSourceFilePropertyCommand.cxx"
|
||||
#include "cmGetTargetPropertyCommand.cxx"
|
||||
#include "cmITKWrapTclCommand.cxx"
|
||||
@ -89,6 +90,7 @@
|
||||
#include "cmLoadCacheCommand.cxx"
|
||||
#include "cmOutputRequiredFilesCommand.cxx"
|
||||
#include "cmRemoveCommand.cxx"
|
||||
#include "cmSetDirectoryPropertiesCommand.cxx"
|
||||
#include "cmSetTargetPropertiesCommand.cxx"
|
||||
#include "cmSourceFilesCommand.cxx"
|
||||
#include "cmSourceFilesRemoveCommand.cxx"
|
||||
@ -171,6 +173,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
|
||||
commands.push_back(new cmExportLibraryDependenciesCommand);
|
||||
commands.push_back(new cmFLTKWrapUICommand);
|
||||
commands.push_back(new cmGetCMakePropertyCommand);
|
||||
commands.push_back(new cmGetDirectoryPropertyCommand);
|
||||
commands.push_back(new cmGetSourceFilePropertyCommand);
|
||||
commands.push_back(new cmGetTargetPropertyCommand);
|
||||
commands.push_back(new cmITKWrapTclCommand);
|
||||
@ -180,6 +183,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
|
||||
commands.push_back(new cmLoadCommandCommand);
|
||||
commands.push_back(new cmOutputRequiredFilesCommand);
|
||||
commands.push_back(new cmRemoveCommand);
|
||||
commands.push_back(new cmSetDirectoryPropertiesCommand);
|
||||
commands.push_back(new cmSetTargetPropertiesCommand);
|
||||
commands.push_back(new cmSourceFilesCommand);
|
||||
commands.push_back(new cmSourceFilesRemoveCommand);
|
||||
|
106
Source/cmGetDirectoryPropertyCommand.cxx
Normal file
106
Source/cmGetDirectoryPropertyCommand.cxx
Normal file
@ -0,0 +1,106 @@
|
||||
/*=========================================================================
|
||||
|
||||
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 "cmGetDirectoryPropertyCommand.h"
|
||||
|
||||
#include "cmake.h"
|
||||
|
||||
// cmGetDirectoryPropertyCommand
|
||||
bool cmGetDirectoryPropertyCommand::InitialPass(
|
||||
std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 2 )
|
||||
{
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string>::size_type cc;
|
||||
std::string variable = args[0];
|
||||
std::string output = "";
|
||||
|
||||
if ( args[1] == "VARIABLES" || args[1] == "CACHE_VARIABLES" )
|
||||
{
|
||||
int cacheonly = 0;
|
||||
if ( args[1] == "CACHE_VARIABLES" )
|
||||
{
|
||||
cacheonly = 1;
|
||||
}
|
||||
std::vector<std::string> vars = m_Makefile->GetDefinitions(cacheonly);
|
||||
for ( cc = 0; cc < vars.size(); cc ++ )
|
||||
{
|
||||
if ( cc > 0 )
|
||||
{
|
||||
output += ";";
|
||||
}
|
||||
output += vars[cc];
|
||||
}
|
||||
}
|
||||
else if ( args[1] == "MACROS" )
|
||||
{
|
||||
m_Makefile->GetListOfMacros(output);
|
||||
}
|
||||
else if ( args[1] == "INCLUDE_DIRECTORIES" )
|
||||
{
|
||||
std::vector<std::string>::iterator it;
|
||||
int first = 1;
|
||||
cmOStringStream str;
|
||||
for ( it = m_Makefile->GetIncludeDirectories().begin();
|
||||
it != m_Makefile->GetIncludeDirectories().end();
|
||||
++ it )
|
||||
{
|
||||
if ( !first )
|
||||
{
|
||||
str << ";";
|
||||
}
|
||||
str << it->c_str();
|
||||
first = 0;
|
||||
}
|
||||
output = str.str();
|
||||
}
|
||||
else if ( args[1] == "INCLUDE_REGULAR_EXPRESSION" )
|
||||
{
|
||||
output = m_Makefile->GetIncludeRegularExpression();
|
||||
}
|
||||
else if ( args[1] == "LINK_DIRECTORIES" )
|
||||
{
|
||||
std::vector<std::string>::iterator it;
|
||||
int first = 1;
|
||||
cmOStringStream str;
|
||||
for ( it = m_Makefile->GetLinkDirectories().begin();
|
||||
it != m_Makefile->GetLinkDirectories().end();
|
||||
++ it )
|
||||
{
|
||||
if ( !first )
|
||||
{
|
||||
str << ";";
|
||||
}
|
||||
str << it->c_str();
|
||||
first = 0;
|
||||
}
|
||||
output = str.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string emsg = "Unknown directory property: " + args[1];
|
||||
this->SetError(emsg.c_str());
|
||||
return false;
|
||||
}
|
||||
m_Makefile->AddDefinition(variable.c_str(), output.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
68
Source/cmGetDirectoryPropertyCommand.h
Normal file
68
Source/cmGetDirectoryPropertyCommand.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*=========================================================================
|
||||
|
||||
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 cmGetDirectoryPropertyCommand_h
|
||||
#define cmGetDirectoryPropertyCommand_h
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmGetDirectoryPropertyCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
virtual cmCommand* Clone()
|
||||
{
|
||||
return new cmGetDirectoryPropertyCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_DIRECTORY_PROPERTY";}
|
||||
|
||||
/**
|
||||
* Succinct documentation.
|
||||
*/
|
||||
virtual const char* GetTerseDocumentation()
|
||||
{
|
||||
return "Get a property of the directory.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Longer documentation.
|
||||
*/
|
||||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" GET_DIRECTORY_PROPERTY(VAR property)\n"
|
||||
"Get a property from the Directory. The value of the property is"
|
||||
"stored in the variable VAR. If the property is not found,"
|
||||
"CMake will report an error. The properties include: VARIABLES, "
|
||||
"CACHE_VARIABLES, COMMANDS, MACROS, INCLUDE_DIRECTORIES, "
|
||||
"LINK_DIRECTORIES, and INCLUDE_REGULAR_EXPRESSION.";
|
||||
}
|
||||
|
||||
cmTypeMacro(cmGetDirectoryPropertyCommand, cmCommand);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -213,6 +213,22 @@ public:
|
||||
*/
|
||||
void AddLinkDirectory(const char*);
|
||||
|
||||
/**
|
||||
* Get the list of link directories
|
||||
*/
|
||||
std::vector<std::string>& GetLinkDirectories()
|
||||
{
|
||||
return m_LinkDirectories;
|
||||
}
|
||||
const std::vector<std::string>& GetLinkDirectories() const
|
||||
{
|
||||
return m_LinkDirectories;
|
||||
}
|
||||
void SetLinkDirectories(const std::vector<std::string>& vec)
|
||||
{
|
||||
m_LinkDirectories = vec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a subdirectory to the build.
|
||||
*/
|
||||
@ -393,6 +409,10 @@ public:
|
||||
{
|
||||
m_IncludeFileRegularExpression = regex;
|
||||
}
|
||||
const char* GetIncludeRegularExpression()
|
||||
{
|
||||
return m_IncludeFileRegularExpression.c_str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a regular expression that include files that are not found
|
||||
@ -428,6 +448,10 @@ public:
|
||||
{
|
||||
return m_IncludeDirectories;
|
||||
}
|
||||
void SetIncludeDirectories(const std::vector<std::string>& vec)
|
||||
{
|
||||
m_IncludeDirectories = vec;
|
||||
}
|
||||
|
||||
/** Expand out any arguements in the vector that have ; separated
|
||||
* strings into multiple arguements. A new vector is created
|
||||
|
79
Source/cmSetDirectoryPropertiesCommand.cxx
Normal file
79
Source/cmSetDirectoryPropertiesCommand.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*=========================================================================
|
||||
|
||||
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 "cmSetDirectoryPropertiesCommand.h"
|
||||
|
||||
#include "cmake.h"
|
||||
|
||||
// cmSetDirectoryPropertiesCommand
|
||||
bool cmSetDirectoryPropertiesCommand::InitialPass(
|
||||
std::vector<std::string> const& args)
|
||||
{
|
||||
if(args.size() < 1 )
|
||||
{
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string>::const_iterator ait;
|
||||
for ( ait = args.begin()+1;
|
||||
ait != args.end();
|
||||
ait += 2 )
|
||||
{
|
||||
if ( ait +1 == args.end() )
|
||||
{
|
||||
this->SetError("Wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
const std::string& prop = *ait;
|
||||
const std::string& value = *(ait+1);
|
||||
if ( prop == "VARIABLES" )
|
||||
{
|
||||
this->SetError("Variables and cache variables should be set using SET command");
|
||||
return false;
|
||||
}
|
||||
else if ( prop == "MACROS" )
|
||||
{
|
||||
this->SetError("Commands and macros cannot be set using SET_CMAKE_PROPERTIES");
|
||||
return false;
|
||||
}
|
||||
else if ( prop == "INCLUDE_DIRECTORIES" )
|
||||
{
|
||||
std::vector<std::string> varArgsExpanded;
|
||||
cmSystemTools::ExpandListArgument(value, varArgsExpanded);
|
||||
m_Makefile->SetIncludeDirectories(varArgsExpanded);
|
||||
}
|
||||
else if ( prop == "LINK_DIRECTORIES" )
|
||||
{
|
||||
std::vector<std::string> varArgsExpanded;
|
||||
cmSystemTools::ExpandListArgument(value, varArgsExpanded);
|
||||
m_Makefile->SetLinkDirectories(varArgsExpanded);
|
||||
}
|
||||
else if ( prop == "INCLUDE_REGULAR_EXPRESSION" )
|
||||
{
|
||||
m_Makefile->SetIncludeRegularExpression(value.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string emsg = "Unknown directory property: " + args[1];
|
||||
this->SetError(emsg.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
67
Source/cmSetDirectoryPropertiesCommand.h
Normal file
67
Source/cmSetDirectoryPropertiesCommand.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*=========================================================================
|
||||
|
||||
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 cmSetDirectoryPropertiesCommand_h
|
||||
#define cmSetDirectoryPropertiesCommand_h
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmSetDirectoryPropertiesCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
virtual cmCommand* Clone()
|
||||
{
|
||||
return new cmSetDirectoryPropertiesCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_DIRECTORY_PROPERTIES";}
|
||||
|
||||
/**
|
||||
* Succinct documentation.
|
||||
*/
|
||||
virtual const char* GetTerseDocumentation()
|
||||
{
|
||||
return "Set a property of the directory.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Longer documentation.
|
||||
*/
|
||||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" SET_DIRECTORY_PROPERTIES(PROPERTIES prop1 value1 prop2 value2)\n"
|
||||
"Set a property for the current directory and subdirectories. If the "
|
||||
"property is not found, CMake will report an error. The properties "
|
||||
"include: INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and "
|
||||
"INCLUDE_REGULAR_EXPRESSION.";
|
||||
}
|
||||
|
||||
cmTypeMacro(cmSetDirectoryPropertiesCommand, cmCommand);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user