summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmBootstrapCommands.cxx2
-rw-r--r--Source/cmCacheManager.cxx4
-rw-r--r--Source/cmMakefile.cxx5
-rw-r--r--Source/cmMakefile.h2
-rw-r--r--Source/cmSetCommand.h5
-rw-r--r--Source/cmUnsetCommand.cxx64
-rw-r--r--Source/cmUnsetCommand.h84
7 files changed, 160 insertions, 6 deletions
diff --git a/Source/cmBootstrapCommands.cxx b/Source/cmBootstrapCommands.cxx
index b8031fc..f14b024 100644
--- a/Source/cmBootstrapCommands.cxx
+++ b/Source/cmBootstrapCommands.cxx
@@ -93,6 +93,7 @@
#include "cmTargetLinkLibrariesCommand.cxx"
#include "cmTryCompileCommand.cxx"
#include "cmTryRunCommand.cxx"
+#include "cmUnsetCommand.cxx"
void GetBootstrapCommands(std::list<cmCommand*>& commands)
{
@@ -163,4 +164,5 @@ void GetBootstrapCommands(std::list<cmCommand*>& commands)
commands.push_back(new cmTargetLinkLibrariesCommand);
commands.push_back(new cmTryCompileCommand);
commands.push_back(new cmTryRunCommand);
+ commands.push_back(new cmUnsetCommand);
}
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index bd95354..52cb448 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -714,10 +714,6 @@ void cmCacheManager::RemoveCacheEntry(const char* key)
{
this->Cache.erase(i);
}
- else
- {
- std::cerr << "Failed to remove entry:" << key << std::endl;
- }
}
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 102ca44..a251462 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1648,6 +1648,11 @@ void cmMakefile::RemoveDefinition(const char* name)
#endif
}
+void cmMakefile::RemoveCacheDefinition(const char* name)
+{
+ this->GetCacheManager()->RemoveCacheEntry(name);
+}
+
void cmMakefile::SetProjectName(const char* p)
{
this->ProjectName = p;
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index f9d10b6..f78a1dd 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -278,6 +278,8 @@ public:
* for cache entries, and will only affect the current makefile.
*/
void RemoveDefinition(const char* name);
+ ///! Remove a definition from the cache.
+ void RemoveCacheDefinition(const char* name);
/**
* Specify the name of the project for this build.
diff --git a/Source/cmSetCommand.h b/Source/cmSetCommand.h
index e818d6a..39d0bc3 100644
--- a/Source/cmSetCommand.h
+++ b/Source/cmSetCommand.h
@@ -87,8 +87,9 @@ public:
"above the current scope. Each new directory or function creates a new "
"scope. This command will set the value of a variable into the parent "
"directory or calling function (whichever is applicable to the case at "
- "hand) If VALUE is not specified then the variable is removed from the "
- "parent scope.\n"
+ "hand).\n"
+ "If <value> is not specified then the variable is removed "
+ "instead of set. See also: the unset() command.\n"
" set(<variable> <value1> ... <valueN>)\n"
"In this case <variable> is set to a semicolon separated list of "
"values.\n"
diff --git a/Source/cmUnsetCommand.cxx b/Source/cmUnsetCommand.cxx
new file mode 100644
index 0000000..d45b50b
--- /dev/null
+++ b/Source/cmUnsetCommand.cxx
@@ -0,0 +1,64 @@
+/*=========================================================================
+
+ 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 "cmUnsetCommand.h"
+
+// cmUnsetCommand
+bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &)
+{
+ if(args.size() < 1 || args.size() > 2)
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ const char* variable = args[0].c_str();
+
+ // unset(ENV{VAR})
+ if (!strncmp(variable,"ENV{",4) && strlen(variable) > 5)
+ {
+ // what is the variable name
+ char *envVarName = new char [strlen(variable)];
+ strncpy(envVarName,variable+4,strlen(variable)-5);
+ envVarName[strlen(variable)-5] = '\0';
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmSystemTools::UnsetEnv(envVarName);
+#endif
+ delete[] envVarName;
+ return true;
+ }
+ // unset(VAR)
+ else if (args.size() == 1)
+ {
+ this->Makefile->RemoveDefinition(variable);
+ return true;
+ }
+ // unset(VAR CACHE)
+ else if ((args.size() == 2) && (args[1] == "CACHE"))
+ {
+ this->Makefile->RemoveCacheDefinition(variable);
+ return true;
+ }
+ // ERROR: second argument isn't CACHE
+ else
+ {
+ this->SetError("called with an invalid second argument");
+ return false;
+ }
+}
+
diff --git a/Source/cmUnsetCommand.h b/Source/cmUnsetCommand.h
new file mode 100644
index 0000000..d125a18
--- /dev/null
+++ b/Source/cmUnsetCommand.h
@@ -0,0 +1,84 @@
+/*=========================================================================
+
+ 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 cmUnsetCommand_h
+#define cmUnsetCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmUnsetCommand
+ * \brief Unset a CMAKE variable
+ *
+ * cmUnsetCommand unsets or removes a variable.
+ */
+class cmUnsetCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmUnsetCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() { return true; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual const char* GetName() {return "unset";}
+
+ /**
+ * Succinct documentation.
+ */
+ virtual const char* GetTerseDocumentation()
+ {
+ return "Unset a variable, cache variable, or environment variable.";
+ }
+
+ /**
+ * More documentation.
+ */
+ virtual const char* GetFullDocumentation()
+ {
+ return
+ " unset(<variable> [CACHE])\n"
+ "Removes the specified variable causing it to become undefined. "
+ "If CACHE is present then the variable is removed from the cache "
+ "instead of the current scope.\n"
+ "<variable> can be an environment variable such as:\n"
+ " unset(ENV{LD_LIBRARY_PATH})\n"
+ "in which case the variable will be removed from the current "
+ "environment.";
+ }
+
+ cmTypeMacro(cmUnsetCommand, cmCommand);
+};
+
+
+
+#endif