summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-08-23 20:14:18 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-08-23 20:14:18 (GMT)
commitbe2705deaa8e0a2e3fc71d36096a808947e85f17 (patch)
tree62766252da748221087078562227cc4feb99df9c /Source
parent2120ce4fcd935d74442ad7f63c06c52287665f35 (diff)
downloadCMake-be2705deaa8e0a2e3fc71d36096a808947e85f17.zip
CMake-be2705deaa8e0a2e3fc71d36096a808947e85f17.tar.gz
CMake-be2705deaa8e0a2e3fc71d36096a808947e85f17.tar.bz2
ENH: class for parsing the arguments for INSTALL()
Alex
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCommands.cxx1
-rw-r--r--Source/cmInstallCommandArguments.cxx189
-rw-r--r--Source/cmInstallCommandArguments.h65
3 files changed, 255 insertions, 0 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 8ad4f0e..59cd099 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -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"
diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx
new file mode 100644
index 0000000..91a00ce
--- /dev/null
+++ b/Source/cmInstallCommandArguments.cxx
@@ -0,0 +1,189 @@
+/*=========================================================================
+
+ 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 "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);
+}
+
diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h
new file mode 100644
index 0000000..936aa46
--- /dev/null
+++ b/Source/cmInstallCommandArguments.h
@@ -0,0 +1,65 @@
+/*=========================================================================
+
+ 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 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