Added detection for clang compiler and fixed various warnings triggered by it (bug 4877, r=dvander).

This commit is contained in:
Scott Ehlert 2011-04-23 21:35:10 -05:00
parent 559f5c734b
commit 8c6aa2f62c
11 changed files with 23 additions and 18 deletions

View File

@ -70,15 +70,18 @@ class MMS:
#Set up defines #Set up defines
cxx = self.compiler.cxx cxx = self.compiler.cxx
if isinstance(cxx, Cpp.CompatGCC):
if isinstance(cxx, Cpp.GCC): if isinstance(cxx, Cpp.GCC):
self.vendor = 'gcc' self.vendor = 'gcc'
elif isinstance(cxx, Cpp.Clang):
self.vendor = 'clang'
self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp') self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp') self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf') self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf') self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
self.compiler.AddToListVar('CFLAGS', '-pipe') self.compiler.AddToListVar('CFLAGS', '-pipe')
self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing') self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
if cxx.majorVersion >= 4: if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden') self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden') self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
self.compiler.AddToListVar('CFLAGS', '-Wall') self.compiler.AddToListVar('CFLAGS', '-Wall')
@ -86,7 +89,6 @@ class MMS:
self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized') self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
self.compiler.AddToListVar('CFLAGS', '-Wno-unused') self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
self.compiler.AddToListVar('CFLAGS', '-Wno-switch') self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
self.compiler.AddToListVar('CFLAGS', '-msse') self.compiler.AddToListVar('CFLAGS', '-msse')
self.compiler.AddToListVar('CFLAGS', '-m32') self.compiler.AddToListVar('CFLAGS', '-m32')
self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
@ -94,7 +96,10 @@ class MMS:
self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti') self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H') self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
if self.vendor == 'gcc':
self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
elif isinstance(cxx, Cpp.MSVC): elif isinstance(cxx, Cpp.MSVC):
self.vendor = 'msvc' self.vendor = 'msvc'
if AMBuild.options.debug == '1': if AMBuild.options.debug == '1':
@ -130,7 +135,7 @@ class MMS:
#Optimization #Optimization
if AMBuild.options.opt == '1': if AMBuild.options.opt == '1':
self.compiler.AddToListVar('CDEFINES', 'NDEBUG') self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
if self.vendor == 'gcc': if self.vendor == 'gcc' or self.vendor == 'clang':
self.compiler.AddToListVar('CFLAGS', '-O3') self.compiler.AddToListVar('CFLAGS', '-O3')
elif self.vendor == 'msvc': elif self.vendor == 'msvc':
self.compiler.AddToListVar('CFLAGS', '/Ox') self.compiler.AddToListVar('CFLAGS', '/Ox')
@ -141,7 +146,7 @@ class MMS:
if AMBuild.options.debug == '1': if AMBuild.options.debug == '1':
self.compiler.AddToListVar('CDEFINES', 'DEBUG') self.compiler.AddToListVar('CDEFINES', 'DEBUG')
self.compiler.AddToListVar('CDEFINES', '_DEBUG') self.compiler.AddToListVar('CDEFINES', '_DEBUG')
if self.vendor == 'gcc': if self.vendor == 'gcc' or self.vendor == 'clang':
self.compiler.AddToListVar('CFLAGS', '-g3') self.compiler.AddToListVar('CFLAGS', '-g3')
elif self.vendor == 'msvc': elif self.vendor == 'msvc':
self.compiler.AddToListVar('CFLAGS', '/Od') self.compiler.AddToListVar('CFLAGS', '/Od')

View File

@ -470,7 +470,7 @@ void CSmmAPI::LoadAsVSP()
/* Chop off the "engine" file part */ /* Chop off the "engine" file part */
len = strlen(engine_file); len = strlen(engine_file);
for (size_t i = len - 1; i >= 0 && i < len; i--) for (size_t i = len - 1; i < len; i--)
{ {
if (engine_file[i] == '/' if (engine_file[i] == '/'
|| engine_file[i] == '\\') || engine_file[i] == '\\')

View File

@ -230,7 +230,7 @@ public:
if (is_space(v[len-1])) if (is_space(v[len-1]))
{ {
for (i=len-1; i>=0; i--) for (i=len-1; i<len; i--)
{ {
if (!is_space(v[i]) if (!is_space(v[i])
|| (is_space(v[i]) && i==0)) || (is_space(v[i]) && i==0))

View File

@ -464,7 +464,7 @@ public:
if (!GrowIfNeeded(1)) if (!GrowIfNeeded(1))
{ {
return false; return iterator(0);
} }
++m_CurrentUsedSize; ++m_CurrentUsedSize;

View File

@ -71,7 +71,7 @@ void UTIL_TrimRight(char *buffer)
size_t len = strlen(buffer); size_t len = strlen(buffer);
/* Loop through buffer backwards while replacing whitespace chars with null chars */ /* Loop through buffer backwards while replacing whitespace chars with null chars */
for (size_t i = len - 1; i >= 0; i--) for (size_t i = len - 1; i < len; i--)
{ {
if (isspace((unsigned char) buffer[i])) if (isspace((unsigned char) buffer[i]))
{ {

View File

@ -326,7 +326,7 @@ void InitializeVSP()
/* Chop off the "engine" file part */ /* Chop off the "engine" file part */
len = strlen(engine_file); len = strlen(engine_file);
for (size_t i = len - 1; i >= 0 && i < len; i--) for (size_t i = len - 1; i < len; i--)
{ {
if (engine_file[i] == '/' || engine_file[i] == '\\') if (engine_file[i] == '/' || engine_file[i] == '\\')
{ {

View File

@ -445,7 +445,7 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source
char file_path[256]; char file_path[256];
size_t len = g_Metamod.PathFormat(file_path, sizeof(file_path), "%s", file); size_t len = g_Metamod.PathFormat(file_path, sizeof(file_path), "%s", file);
for (size_t i = len - 1; i >= 0 && i < len; i--) for (size_t i = len - 1; i < len; i--)
{ {
if (_IsPathSepChar(file_path[i])) if (_IsPathSepChar(file_path[i]))
{ {

View File

@ -87,7 +87,7 @@ void UTIL_TrimRight(char *buffer)
size_t len = strlen(buffer); size_t len = strlen(buffer);
/* Loop through buffer backwards while replacing whitespace chars with null chars */ /* Loop through buffer backwards while replacing whitespace chars with null chars */
for (size_t i = len - 1; i >= 0; i--) for (size_t i = len - 1; i < len; i--)
{ {
if (isspace((unsigned char) buffer[i])) if (isspace((unsigned char) buffer[i]))
{ {
@ -138,7 +138,7 @@ bool UTIL_PathCmp(const char *path1, const char *path2)
/* If we're at a different non-alphanumeric, the next character MUST match */ /* If we're at a different non-alphanumeric, the next character MUST match */
if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2]) if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2])
|| ||
!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]) (!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]))
) )
{ {
return false; return false;

View File

@ -230,7 +230,7 @@ public:
if (is_space(v[len-1])) if (is_space(v[len-1]))
{ {
for (i=len-1; i>=0; i--) for (i=len-1; i<len; i--)
{ {
if (!is_space(v[i]) if (!is_space(v[i])
|| (is_space(v[i]) && i==0)) || (is_space(v[i]) && i==0))

View File

@ -464,7 +464,7 @@ public:
if (!GrowIfNeeded(1)) if (!GrowIfNeeded(1))
{ {
return false; return iterator(0);
} }
++m_CurrentUsedSize; ++m_CurrentUsedSize;

View File

@ -125,7 +125,7 @@ mm_TrimRight(char *buffer)
size_t len = strlen(buffer); size_t len = strlen(buffer);
/* Loop through buffer backwards while replacing whitespace chars with null chars */ /* Loop through buffer backwards while replacing whitespace chars with null chars */
for (size_t i = len - 1; i >= 0; i--) for (size_t i = len - 1; i < len; i--)
{ {
if (isspace((unsigned char) buffer[i])) if (isspace((unsigned char) buffer[i]))
buffer[i] = '\0'; buffer[i] = '\0';
@ -245,7 +245,7 @@ mm_PathCmp(const char *path1, const char *path2)
/* If we're at a different non-alphanumeric, the next character MUST match */ /* If we're at a different non-alphanumeric, the next character MUST match */
if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2]) if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2])
|| ||
!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]) (!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]))
) )
{ {
return false; return false;