summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorNicolas Despres <nicolas.despres@gmail.com>2011-03-20 16:57:42 (GMT)
committerPeter Collingbourne <peter@pcc.me.uk>2011-10-02 17:30:42 (GMT)
commit3db2973bd2ceb65a0d88ed6a3428e17cc9f0e182 (patch)
treea01dd9538a35dad32d0e1948a97b3a29f28c1d1d /Source
parent89bdc3e213b82759c3f916ef746c0bc752ce32d2 (diff)
downloadCMake-3db2973bd2ceb65a0d88ed6a3428e17cc9f0e182.zip
CMake-3db2973bd2ceb65a0d88ed6a3428e17cc9f0e182.tar.gz
CMake-3db2973bd2ceb65a0d88ed6a3428e17cc9f0e182.tar.bz2
Refactor TargetTypeNames.
Make it a static method instead of an array. It is safer for the type checking and if we add a new target type we will be warned to add a case to the switch.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmComputeTargetDepends.cxx2
-rw-r--r--Source/cmLocalGenerator.cxx2
-rw-r--r--Source/cmMakefile.cxx2
-rw-r--r--Source/cmTarget.cxx72
-rw-r--r--Source/cmTarget.h2
5 files changed, 35 insertions, 45 deletions
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index 3a0ed06..8e701c4 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -404,7 +404,7 @@ cmComputeTargetDepends
// Describe the depender.
e << " \"" << depender->GetName() << "\" of type "
- << cmTarget::TargetTypeNames[depender->GetType()] << "\n";
+ << cmTarget::GetTargetTypeName(depender->GetType()) << "\n";
// List its dependencies that are inside the component.
EdgeList const& nl = this->InitialGraph[i];
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 1d1e8da..6af7fd5 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -996,7 +996,7 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
}
if(variable == "TARGET_TYPE")
{
- return cmTarget::TargetTypeNames[replaceValues.CMTarget->GetType()];
+ return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
}
}
if(replaceValues.Output)
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index e5b5443..573c430 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1379,7 +1379,7 @@ void cmMakefile::AddLinkLibraryForTarget(const char *target,
{
cmOStringStream e;
e << "Target \"" << lib << "\" of type "
- << cmTarget::TargetTypeNames[static_cast<int>(tgt->GetType())]
+ << cmTarget::GetTargetTypeName(tgt->GetType())
<< " may not be linked into another target. "
<< "One may link only to STATIC or SHARED libraries, or "
<< "to executables with the ENABLE_EXPORTS property set.";
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index fb92016..e74e70c 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -25,12 +25,35 @@
#include <queue>
#include <stdlib.h> // required for atof
#include <assert.h>
-const char* cmTarget::TargetTypeNames[] = {
- "EXECUTABLE", "STATIC_LIBRARY",
- "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
- "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
- "UNKNOWN_LIBRARY"
-};
+
+const char* cmTarget::GetTargetTypeName(TargetType targetType)
+{
+ switch( targetType )
+ {
+ case cmTarget::STATIC_LIBRARY:
+ return "STATIC_LIBRARY";
+ case cmTarget::MODULE_LIBRARY:
+ return "MODULE_LIBRARY";
+ case cmTarget::SHARED_LIBRARY:
+ return "SHARED_LIBRARY";
+ case cmTarget::EXECUTABLE:
+ return "EXECUTABLE";
+ case cmTarget::UTILITY:
+ return "UTILITY";
+ case cmTarget::GLOBAL_TARGET:
+ return "GLOBAL_TARGET";
+ case cmTarget::INSTALL_FILES:
+ return "INSTALL_FILES";
+ case cmTarget::INSTALL_PROGRAMS:
+ return "INSTALL_PROGRAMS";
+ case cmTarget::INSTALL_DIRECTORY:
+ return "INSTALL_DIRECTORY";
+ case cmTarget::UNKNOWN_LIBRARY:
+ return "UNKNOWN_LIBRARY";
+ }
+ assert(0 && "Unexpected target type");
+ return 0;
+}
//----------------------------------------------------------------------------
struct cmTarget::OutputInfo
@@ -2346,7 +2369,7 @@ cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
std::string msg = "cmTarget::GetOutputInfo called for ";
msg += this->GetName();
msg += " which has type ";
- msg += cmTarget::TargetTypeNames[this->GetType()];
+ msg += cmTarget::GetTargetTypeName(this->GetType());
this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
abort();
return 0;
@@ -2645,40 +2668,7 @@ const char *cmTarget::GetProperty(const char* prop,
// the type property returns what type the target is
if (!strcmp(prop,"TYPE"))
{
- switch( this->GetType() )
- {
- case cmTarget::STATIC_LIBRARY:
- return "STATIC_LIBRARY";
- // break; /* unreachable */
- case cmTarget::MODULE_LIBRARY:
- return "MODULE_LIBRARY";
- // break; /* unreachable */
- case cmTarget::SHARED_LIBRARY:
- return "SHARED_LIBRARY";
- // break; /* unreachable */
- case cmTarget::EXECUTABLE:
- return "EXECUTABLE";
- // break; /* unreachable */
- case cmTarget::UTILITY:
- return "UTILITY";
- // break; /* unreachable */
- case cmTarget::GLOBAL_TARGET:
- return "GLOBAL_TARGET";
- // break; /* unreachable */
- case cmTarget::INSTALL_FILES:
- return "INSTALL_FILES";
- // break; /* unreachable */
- case cmTarget::INSTALL_PROGRAMS:
- return "INSTALL_PROGRAMS";
- // break; /* unreachable */
- case cmTarget::INSTALL_DIRECTORY:
- return "INSTALL_DIRECTORY";
- // break; /* unreachable */
- case cmTarget::UNKNOWN_LIBRARY:
- return "UNKNOWN_LIBRARY";
- // break; /* unreachable */
- }
- return 0;
+ return cmTarget::GetTargetTypeName(this->GetType());
}
bool chain = false;
const char *retVal =
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 26fcef2..0abdddb 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -62,7 +62,7 @@ public:
SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, GLOBAL_TARGET,
INSTALL_FILES, INSTALL_PROGRAMS, INSTALL_DIRECTORY,
UNKNOWN_LIBRARY};
- static const char* TargetTypeNames[];
+ static const char* GetTargetTypeName(TargetType targetType);
enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
/**