[cmake-commits] alex committed cmCommands.cxx 1.117 1.118 cmInstallCommandArguments.h NONE 1.1 cmInstallCommandArguments.cxx NONE 1.1

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Aug 23 16:14:20 EDT 2007


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

Modified Files:
	cmCommands.cxx 
Added Files:
	cmInstallCommandArguments.h cmInstallCommandArguments.cxx 
Log Message:

ENH: class for parsing the arguments for INSTALL()

Alex


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

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmInstallCommandArguments.h,v $
  Language:  C++
  Date:      $Date: 2007/08/23 20:14:18 $
  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 cmInstallCommandArguments_h
#define cmInstallCommandArguments_h

#include "cmStandardIncludes.h"
#include "cmCommandArgumentsHelper.h"

class cmInstallCommandArguments : public cmCommandArgumentsHelper
{
  public:
    cmInstallCommandArguments();
    void SetGenericArguments(cmInstallCommandArguments* args) 
                                               {this->GenericArguments = args;}
    // Compute destination path.
    bool Finalize();
    cmCommandArgumentGroup ArgumentGroup;

    const std::string& GetDestination() const;
    const std::string& GetComponent() const;
    const std::string& GetRename() const;
    const std::string& GetPermissions() const;
    const std::vector<std::string>& GetConfigurations() const;
    bool GetOptional() const;

    // once HandleDirectoryMode() is also switched to using cmInstallCommandArguments
    // then these two functions can become non-static private member functions
    // without arguments
    static void ComputeDestination(const std::string& inDest, 
                                   std::string& absDest);
    static bool CheckPermissions(const std::string& onePerm, 
                                 std::string& perm);
  private:
    cmCAString Destination;
    cmCAString Component;
    cmCAString Rename;
    cmCAStringVector Permissions;
    cmCAStringVector Configurations;
    cmCAEnabler Optional;

    std::string AbsDestination;
    std::string PermissionsString;

    cmInstallCommandArguments* GenericArguments;
    static const char* PermissionsTable[];
    static const std::string EmptyString;
    bool CheckPermissions();
};

#endif

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

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmInstallCommandArguments.cxx,v $
  Language:  C++
  Date:      $Date: 2007/08/23 20:14:18 $
  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 "cmInstallCommandArguments.h"
#include "cmSystemTools.h"

// Table of valid permissions.
const char* cmInstallCommandArguments::PermissionsTable[] =
{
  "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
  "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
  "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
  "SETUID", "SETGID", 0
};

const std::string cmInstallCommandArguments::EmptyString;

cmInstallCommandArguments::cmInstallCommandArguments()
:cmCommandArgumentsHelper()
,ArgumentGroup()
,Destination   (this, "DESTINATION"   , &ArgumentGroup)
,Component     (this, "COMPONENT"     , &ArgumentGroup)
,Rename        (this, "RENAME"        , &ArgumentGroup)
,Permissions   (this, "PERMISSIONS"   , &ArgumentGroup)
,Configurations(this, "CONFIGURATIONS", &ArgumentGroup)
,Optional      (this, "OPTIONAL"      , &ArgumentGroup)
,GenericArguments(0)
{
  this->Component.SetDefaultString("Unspecified");
}

const std::string& cmInstallCommandArguments::GetDestination() const
{
  if (!this->AbsDestination.empty())
    {
    return this->AbsDestination;
    }
  if (this->GenericArguments!=0)
    {
    return this->GenericArguments->GetDestination();
    }
  return this->EmptyString;
}

const std::string& cmInstallCommandArguments::GetComponent() const
{
  if (!this->Component.GetString().empty())
    {
    return this->Component.GetString();
    }
  if (this->GenericArguments!=0)
    {
    return this->GenericArguments->GetComponent();
    }
  return this->EmptyString;
}

const std::string& cmInstallCommandArguments::GetRename() const
{
  if (!this->Rename.GetString().empty())
    {
    return this->Rename.GetString();
    }
  if (this->GenericArguments!=0)
    {
    return this->GenericArguments->GetRename();
    }
  return this->EmptyString;
}

const std::string& cmInstallCommandArguments::GetPermissions() const
{
  if (!this->PermissionsString.empty())
    {
    return this->PermissionsString;
    }
  if (this->GenericArguments!=0)
    {
    return this->GenericArguments->GetPermissions();
    }
  return this->EmptyString;
}

bool cmInstallCommandArguments::GetOptional() const
{
  if (this->Optional.IsEnabled())
    {
    return true;
    }
  if (this->GenericArguments!=0)
    {
    return this->GenericArguments->GetOptional();
    }
  return false;
}

const std::vector<std::string>& 
    cmInstallCommandArguments::GetConfigurations() const
{
  if (!this->Configurations.GetVector().empty())
    {
    return this->Configurations.GetVector();
    }
  if (this->GenericArguments!=0)
    {
    return this->GenericArguments->GetConfigurations();
    }
  return this->Configurations.GetVector();
}


bool cmInstallCommandArguments::Finalize()
{
  if (!this->CheckPermissions())
    {
    return false;
    }
  this->ComputeDestination(this->Destination.GetString(),this->AbsDestination);

  return true;
}

bool cmInstallCommandArguments::CheckPermissions()
{
  this->PermissionsString = "";
  for(std::vector<std::string>::const_iterator 
      permIt = this->Permissions.GetVector().begin(); 
      permIt != this->Permissions.GetVector().end(); 
      ++permIt)
    {
    if (!this->CheckPermissions(*permIt, this->PermissionsString))
      {
      return false;
      }
    }
  return true;
}

bool cmInstallCommandArguments::CheckPermissions(
                    const std::string& onePermission, std::string& permissions)
{
  // Check the permission against the table.
  for(const char** valid = cmInstallCommandArguments::PermissionsTable; 
      *valid; ++valid)
    {
    if(onePermission == *valid)
      {
      // This is a valid permission.
      permissions += " ";
      permissions += onePermission;
      return true;
      }
    }
  // This is not a valid permission.
  return false;
}

//----------------------------------------------------------------------------
void cmInstallCommandArguments::ComputeDestination(const std::string& inDest, 
                                                   std::string& absDest)
{
  if((inDest.size()>0) && !(cmSystemTools::FileIsFullPath(inDest.c_str())))
    {
    // Relative paths are treated with respect to the installation prefix.
    absDest = "${CMAKE_INSTALL_PREFIX}/";
    absDest += inDest;
    }
  else
    {
    // Full paths are absolute.
    absDest = inDest;
    }
  // Format the path nicely.  Note this also removes trailing slashes.
  cmSystemTools::ConvertToUnixSlashes(absDest);
}


Index: cmCommands.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCommands.cxx,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -d -r1.117 -r1.118
--- cmCommands.cxx	26 Jun 2007 21:08:29 -0000	1.117
+++ cmCommands.cxx	23 Aug 2007 20:14:18 -0000	1.118
@@ -32,6 +32,7 @@
 #include "cmGetTestPropertyCommand.cxx"
 #include "cmIncludeExternalMSProjectCommand.cxx"
 #include "cmInstallCommand.cxx"
+#include "cmInstallCommandArguments.cxx"
 #include "cmInstallProgramsCommand.cxx"
 #include "cmLinkLibrariesCommand.cxx"
 #include "cmListCommand.cxx"



More information about the Cmake-commits mailing list