summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2004-04-23 20:20:36 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2004-04-23 20:20:36 (GMT)
commitaff8c7bcd6fe751974c2e82147d1a29928236209 (patch)
tree9be11469b702704fb44204b91ca5e50e6d1a9a41
parent0b7d154ebd1e2ab713a8f5018e26c4b0d8b823c4 (diff)
downloadCMake-aff8c7bcd6fe751974c2e82147d1a29928236209.zip
CMake-aff8c7bcd6fe751974c2e82147d1a29928236209.tar.gz
CMake-aff8c7bcd6fe751974c2e82147d1a29928236209.tar.bz2
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
-rw-r--r--Source/cmCommands.cxx4
-rw-r--r--Source/cmGetDirectoryPropertyCommand.cxx106
-rw-r--r--Source/cmGetDirectoryPropertyCommand.h68
-rw-r--r--Source/cmMakefile.h24
-rw-r--r--Source/cmSetDirectoryPropertiesCommand.cxx79
-rw-r--r--Source/cmSetDirectoryPropertiesCommand.h67
6 files changed, 348 insertions, 0 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 4a7417a..96c5a6e 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -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);
diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx
new file mode 100644
index 0000000..23b0008
--- /dev/null
+++ b/Source/cmGetDirectoryPropertyCommand.cxx
@@ -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;
+}
+
diff --git a/Source/cmGetDirectoryPropertyCommand.h b/Source/cmGetDirectoryPropertyCommand.h
new file mode 100644
index 0000000..44297e3
--- /dev/null
+++ b/Source/cmGetDirectoryPropertyCommand.h
@@ -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
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 39c937a..c35cf43 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -214,6 +214,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.
*/
void AddSubDirectory(const char*, bool includeTopLevel=true, bool preorder = false);
@@ -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
diff --git a/Source/cmSetDirectoryPropertiesCommand.cxx b/Source/cmSetDirectoryPropertiesCommand.cxx
new file mode 100644
index 0000000..4256e62
--- /dev/null
+++ b/Source/cmSetDirectoryPropertiesCommand.cxx
@@ -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;
+}
+
diff --git a/Source/cmSetDirectoryPropertiesCommand.h b/Source/cmSetDirectoryPropertiesCommand.h
new file mode 100644
index 0000000..d5e5acf
--- /dev/null
+++ b/Source/cmSetDirectoryPropertiesCommand.h
@@ -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