[Cmake-commits] [cmake-commits] king committed cmBootstrapCommands.cxx 1.28 1.29 cmCacheManager.cxx 1.100 1.101 cmMakefile.cxx 1.480 1.481 cmMakefile.h 1.234 1.235 cmSetCommand.h 1.20 1.21 cmUnsetCommand.cxx NONE 1.1 cmUnsetCommand.h NONE 1.1

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Aug 25 10:31:31 EDT 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv10261/Source

Modified Files:
	cmBootstrapCommands.cxx cmCacheManager.cxx cmMakefile.cxx 
	cmMakefile.h cmSetCommand.h 
Added Files:
	cmUnsetCommand.cxx cmUnsetCommand.h 
Log Message:
ENH: Add unset() command.

This introduces the unset() command to make it easy to unset CMake
variables, environment variables, and CMake cache variables.  Previously
it was not even possible to unset ENV or CACHE variables (as in
completely remove them).  Changes based on patch from Philip Lowman.
See issue #7507.


Index: cmCacheManager.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCacheManager.cxx,v
retrieving revision 1.100
retrieving revision 1.101
diff -C 2 -d -r1.100 -r1.101
*** cmCacheManager.cxx	29 Jan 2008 22:30:48 -0000	1.100
--- cmCacheManager.cxx	25 Aug 2008 14:31:28 -0000	1.101
***************
*** 715,722 ****
      this->Cache.erase(i);
      }
-   else
-     {
-     std::cerr << "Failed to remove entry:" << key << std::endl;
-     }
  }
  
--- 715,718 ----

--- NEW FILE: cmUnsetCommand.cxx ---
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmUnsetCommand.cxx,v $
  Language:  C++
  Date:      $Date: 2008-08-25 14:31:28 $
  Version:   $Revision: 1.1 $

  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;
    }
}


Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.234
retrieving revision 1.235
diff -C 2 -d -r1.234 -r1.235
*** cmMakefile.h	18 Aug 2008 20:29:00 -0000	1.234
--- cmMakefile.h	25 Aug 2008 14:31:28 -0000	1.235
***************
*** 279,282 ****
--- 279,284 ----
     */
    void RemoveDefinition(const char* name);
+   ///! Remove a definition from the cache.
+   void RemoveCacheDefinition(const char* name);
    
    /**

Index: cmSetCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSetCommand.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -C 2 -d -r1.20 -r1.21
*** cmSetCommand.h	23 Jan 2008 15:27:59 -0000	1.20
--- cmSetCommand.h	25 Aug 2008 14:31:28 -0000	1.21
***************
*** 88,93 ****
        "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"
        "  set(<variable> <value1> ... <valueN>)\n"
        "In this case <variable> is set to a semicolon separated list of "
--- 88,94 ----
        "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).\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 "

Index: cmBootstrapCommands.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmBootstrapCommands.cxx,v
retrieving revision 1.28
retrieving revision 1.29
diff -C 2 -d -r1.28 -r1.29
*** cmBootstrapCommands.cxx	7 Jul 2008 19:07:54 -0000	1.28
--- cmBootstrapCommands.cxx	25 Aug 2008 14:31:28 -0000	1.29
***************
*** 94,97 ****
--- 94,98 ----
  #include "cmTryCompileCommand.cxx"
  #include "cmTryRunCommand.cxx"
+ #include "cmUnsetCommand.cxx"
  
  void GetBootstrapCommands(std::list<cmCommand*>& commands)
***************
*** 164,166 ****
--- 165,168 ----
    commands.push_back(new cmTryCompileCommand);
    commands.push_back(new cmTryRunCommand);
+   commands.push_back(new cmUnsetCommand);
  }

--- NEW FILE: cmUnsetCommand.h ---
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmUnsetCommand.h,v $
  Language:  C++
  Date:      $Date: 2008-08-25 14:31:28 $
  Version:   $Revision: 1.1 $

  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

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.480
retrieving revision 1.481
diff -C 2 -d -r1.480 -r1.481
*** cmMakefile.cxx	19 Aug 2008 14:28:22 -0000	1.480
--- cmMakefile.cxx	25 Aug 2008 14:31:28 -0000	1.481
***************
*** 1649,1652 ****
--- 1649,1657 ----
  }
  
+ void cmMakefile::RemoveCacheDefinition(const char* name)
+ {
+   this->GetCacheManager()->RemoveCacheEntry(name);
+ }
+ 
  void cmMakefile::SetProjectName(const char* p)
  {



More information about the Cmake-commits mailing list