diff options
author | Nicolas Despres <nicolas.despres@gmail.com> | 2011-03-20 16:57:42 (GMT) |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2011-10-02 17:30:42 (GMT) |
commit | 3db2973bd2ceb65a0d88ed6a3428e17cc9f0e182 (patch) | |
tree | a01dd9538a35dad32d0e1948a97b3a29f28c1d1d /Source/cmTarget.cxx | |
parent | 89bdc3e213b82759c3f916ef746c0bc752ce32d2 (diff) | |
download | CMake-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/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 72 |
1 files changed, 31 insertions, 41 deletions
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 = |