Fix some compilation errors for Visual C++ 2012
Unfortunately Visual C++ 2012 can't compile gmio because it does not support mixing declarations and instructions. Visual C++ 2013 at least is a prerequisite.
This commit is contained in:
parent
31d26ebd32
commit
7f794f532a
160
CMakeLists.txt
160
CMakeLists.txt
@ -131,9 +131,6 @@ if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
||||
add_definitions(-D_POSIX_SOURCE)
|
||||
endif()
|
||||
|
||||
message(STATUS "CMAKE_SHARED_LIBRARY_C_FLAGS = ${CMAKE_SHARED_LIBRARY_C_FLAGS}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
# cmake < v2.8.9 does not support CMAKE_POSITION_INDEPENDENT_CODE
|
||||
# For this project, gcc needs -fPIC option on x86_64 UNIX platform
|
||||
if(NOT (WIN32 OR CYGWIN)
|
||||
@ -148,6 +145,75 @@ if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
# Adapt C compiler flags GCC-like compilers
|
||||
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-aliasing")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align -Wfloat-equal")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Winline")
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
# Undefined behavior sanitizer(ubsan), requires GCC >= v4.9
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op-parentheses")
|
||||
endif()
|
||||
|
||||
# Disable warnings -Wno-missing-braces -Wno-missing-field-initializers
|
||||
# in case GCC wrongly warns about universal zero initializer {0}
|
||||
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} -Werror=missing-braces")
|
||||
check_c_source_compiles(
|
||||
"struct data { char array[128]; };
|
||||
int main() {
|
||||
struct data d = {0};
|
||||
return d.array[0];
|
||||
}"
|
||||
GMIO_GCC_DOESNT_WARN_UNIVERSAL_0_INITIALIZER)
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}") # Restore CMAKE_REQUIRED_FLAGS
|
||||
if (NOT GMIO_GCC_DOESNT_WARN_UNIVERSAL_0_INITIALIZER)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces -Wno-missing-field-initializers")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Adapt C compiler flags Clang
|
||||
if(CMAKE_COMPILER_IS_CLANG)
|
||||
# Clang on apple-darwin13.4.0 wrongly reports many unused functions
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
|
||||
endif()
|
||||
|
||||
# Adapt C compiler flags for Visual C++
|
||||
if(MSVC)
|
||||
# Set warning level to /W4
|
||||
string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
# Set warning level to /Wall
|
||||
#string(REGEX REPLACE "/W[0-9]" "/Wall" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4255 /wd4710 /wd4711 /wd4820")
|
||||
|
||||
# Enable static analysis
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /analyze")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi /Qvec-report:2")
|
||||
|
||||
# Treat some warnings as errors
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4013")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4024")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4057")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4090")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4133")
|
||||
|
||||
# Enable /Zc:strictStrings when msvc_ver > 2012 and build_type != Debug
|
||||
if((MSVC_VERSION GREATER 1700) AND NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zc:strictStrings")
|
||||
endif()
|
||||
|
||||
# Disable deprecation warnings about "non-secure" CRT functions
|
||||
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
# Enable "Generate Intrinsic Functions"
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}")
|
||||
|
||||
# Some compilers (like GCC v4.9) don't disable <stdint.h> when needed
|
||||
@ -189,11 +255,21 @@ endif()
|
||||
check_function_exists(powf GMIO_HAVE_POWF_FUNC)
|
||||
check_function_exists(sqrtf GMIO_HAVE_SQRTF_FUNC)
|
||||
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
|
||||
check_symbol_exists(isfinite math.h GMIO_HAVE_ISFINITE_MACRO)
|
||||
check_symbol_exists(isnan math.h GMIO_HAVE_ISNAN_MACRO)
|
||||
check_symbol_exists(isfinite math.h GMIO_HAVE_ISFINITE_SYM)
|
||||
check_symbol_exists(isnan math.h GMIO_HAVE_ISNAN_SYM)
|
||||
if(WIN32 AND NOT GMIO_HAVE_ISNAN_SYM)
|
||||
check_symbol_exists(_finite float.h GMIO_HAVE_WIN__FINITE_SYM)
|
||||
endif()
|
||||
if(WIN32 AND NOT GMIO_HAVE_ISNAN_SYM)
|
||||
check_symbol_exists(_isnan float.h GMIO_HAVE_WIN__ISNAN_SYM)
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES) # Pop changes
|
||||
|
||||
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
|
||||
check_c_source_compiles(
|
||||
"#include <stdbool.h>
|
||||
int main() { const bool c = 0; return 0; }"
|
||||
GMIO_HAVE_C99_BOOL)
|
||||
|
||||
check_function_exists(snprintf GMIO_HAVE_SNPRINTF_FUNC)
|
||||
if(WIN32 AND NOT GMIO_HAVE_SNPRINTF_FUNC)
|
||||
@ -278,78 +354,6 @@ elseif(MSVC)
|
||||
GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
||||
endif()
|
||||
|
||||
# Specific flags for GCC-like compilers
|
||||
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-aliasing")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align -Wfloat-equal")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Winline")
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
# Undefined behavior sanitizer(ubsan), requires GCC >= v4.9
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op-parentheses")
|
||||
endif()
|
||||
|
||||
# Disable warnings -Wno-missing-braces -Wno-missing-field-initializers
|
||||
# in case GCC wrongly warns about universal zero initializer {0}
|
||||
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} -Werror=missing-braces")
|
||||
check_c_source_compiles(
|
||||
"struct data { char array[128]; };
|
||||
int main() {
|
||||
struct data d = {0};
|
||||
return d.array[0];
|
||||
}"
|
||||
GMIO_GCC_DOESNT_WARN_UNIVERSAL_0_INITIALIZER)
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}") # Restore CMAKE_REQUIRED_FLAGS
|
||||
if (NOT GMIO_GCC_DOESNT_WARN_UNIVERSAL_0_INITIALIZER)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces -Wno-missing-field-initializers")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Specific flags for Clang
|
||||
if(CMAKE_COMPILER_IS_CLANG)
|
||||
# Clang on apple-darwin13.4.0 wrongly reports many unused functions
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
|
||||
endif()
|
||||
|
||||
# Specific flags for Visual C++
|
||||
if(MSVC)
|
||||
# Treat all files a C source files
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TC")
|
||||
|
||||
# Set warning level to /W4
|
||||
string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
# Set warning level to /Wall
|
||||
#string(REGEX REPLACE "/W[0-9]" "/Wall" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4255 /wd4710 /wd4711 /wd4820")
|
||||
|
||||
# Enable static analysis
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /analyze")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi /Qvec-report:2")
|
||||
|
||||
# Treat some warnings as errors
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4013")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4024")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4057")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4090")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4133")
|
||||
|
||||
# Enable /Zc:strictStrings when msvc_ver > 2012 and build_type != Debug
|
||||
if((MSVC_VERSION GREATER 1700) AND NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zc:strictStrings")
|
||||
endif()
|
||||
|
||||
# Disable deprecation warnings about "non-secure" CRT functions
|
||||
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
# Enable "Generate Intrinsic Functions"
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
|
||||
endif()
|
||||
|
||||
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
# zlib
|
||||
|
@ -50,8 +50,8 @@
|
||||
#cmakedefine GMIO_HAVE_STDINT_H
|
||||
#endif
|
||||
|
||||
#ifndef GMIO_HAVE_STDBOOL_H
|
||||
#cmakedefine GMIO_HAVE_STDBOOL_H
|
||||
#ifndef GMIO_HAVE_C99_BOOL
|
||||
#cmakedefine GMIO_HAVE_C99_BOOL
|
||||
#endif
|
||||
|
||||
#cmakedefine GMIO_HAVE_STRTOF_FUNC
|
||||
@ -61,8 +61,10 @@
|
||||
#cmakedefine GMIO_HAVE_VSNPRINTF_FUNC
|
||||
#cmakedefine GMIO_HAVE_WIN__VSNPRINTF_FUNC
|
||||
|
||||
#cmakedefine GMIO_HAVE_ISFINITE_MACRO
|
||||
#cmakedefine GMIO_HAVE_ISNAN_MACRO
|
||||
#cmakedefine GMIO_HAVE_ISFINITE_SYM
|
||||
#cmakedefine GMIO_HAVE_WIN__FINITE_SYM
|
||||
#cmakedefine GMIO_HAVE_ISNAN_SYM
|
||||
#cmakedefine GMIO_HAVE_WIN__ISNAN_SYM
|
||||
|
||||
/* POSIX */
|
||||
#cmakedefine GMIO_HAVE_SYS_TYPES_H
|
||||
|
@ -146,16 +146,20 @@ typedef uint32_t uintmax_t;
|
||||
|
||||
#endif
|
||||
|
||||
/* GMIO_HAVE_STDBOOL_H */
|
||||
#ifdef GMIO_HAVE_STDBOOL_H
|
||||
# include <stdbool.h>
|
||||
#elif !defined(DOXYGEN) && !defined(__cplusplus)
|
||||
/* GMIO_HAVE_C99_BOOL */
|
||||
#ifndef __cplusplus
|
||||
# if defined(GMIO_HAVE_C99_BOOL)
|
||||
# include <stdbool.h>
|
||||
# endif
|
||||
# if !defined(__bool_true_false_are_defined) && !defined(DOXYGEN)
|
||||
typedef int bool;
|
||||
enum gmio_bool_value
|
||||
{
|
||||
false = 0,
|
||||
true = 1
|
||||
};
|
||||
# define __bool_true_false_are_defined 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* GMIO_UNUSED */
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
#ifndef GMIO_INTERNAL_C99_MATH_COMPAT_H
|
||||
#define GMIO_INTERNAL_C99_MATH_COMPAT_H
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
#include <math.h>
|
||||
@ -50,17 +49,23 @@ GMIO_INLINE float gmio_sqrtf(float x)
|
||||
{ return (float)sqrt((double)x); }
|
||||
#endif
|
||||
|
||||
#ifdef GMIO_HAVE_ISFINITE_MACRO
|
||||
#if defined(GMIO_HAVE_ISFINITE_SYM)
|
||||
# define gmio_isfinite(x) isfinite(x)
|
||||
#elif defined(GMIO_HAVE_WIN__FINITE_SYM)
|
||||
# include <float.h>
|
||||
# define gmio_isfinite(x) _finite(x)
|
||||
#else
|
||||
/* No isfinite() macro*/
|
||||
/* No isfinite() symbol */
|
||||
# define gmio_isfinite(x) (((x) != NAN) && ((x) != INFINITY))
|
||||
#endif
|
||||
|
||||
#ifdef GMIO_HAVE_ISNAN_MACRO
|
||||
#if defined(GMIO_HAVE_ISNAN_SYM)
|
||||
# define gmio_isnan(x) isnan(x)
|
||||
#elif defined(GMIO_HAVE_WIN__ISNAN_SYM)
|
||||
# include <float.h>
|
||||
# define gmio_isnan(x) _isnan(x)
|
||||
#else
|
||||
/* No isnan() macro*/
|
||||
/* No isnan() symbol */
|
||||
# define gmio_isnan(x) ((x) == NAN)
|
||||
#endif
|
||||
|
||||
|
@ -122,7 +122,8 @@ size_t gmio_zip_write_local_file_header(
|
||||
uint8_t* buff = fixed_data;
|
||||
|
||||
const bool use_data_descriptor =
|
||||
info->general_purpose_flags & GMIO_ZIP_GENERAL_PURPOSE_FLAG_USE_DATA_DESCRIPTOR;
|
||||
info->general_purpose_flags
|
||||
& GMIO_ZIP_GENERAL_PURPOSE_FLAG_USE_DATA_DESCRIPTOR;
|
||||
|
||||
/* 4-bytes magic number 0x04034b50 */
|
||||
buff = gmio_adv_encode_uint32_le(0x04034b50, buff);
|
||||
|
@ -85,7 +85,7 @@ struct gmio_stream
|
||||
/*! Pointer on a function that checks end-of-stream indicator
|
||||
*
|
||||
* Checks whether the end-of-stream indicator associated with stream
|
||||
* pointed by \p cookie is set, returning true if is.
|
||||
* pointed by \p cookie is set, returning true if it is.
|
||||
*
|
||||
* The function should behaves like C standard [feof()]
|
||||
* (http://pubs.opengroup.org/onlinepubs/007904975/functions/feof.html)
|
||||
|
@ -374,8 +374,7 @@ bool stla_token_match_candidate(
|
||||
enum gmio_stla_token token, const enum gmio_stla_token* candidates)
|
||||
{
|
||||
bool found = false;
|
||||
size_t i;
|
||||
for (i = 0; !found && candidates[i] != null_token; ++i)
|
||||
for (size_t i = 0; !found && candidates[i] != null_token; ++i)
|
||||
found = token == candidates[i];
|
||||
return found;
|
||||
}
|
||||
@ -416,10 +415,9 @@ int gmio_stla_eat_next_token(
|
||||
enum gmio_stla_token expected_token)
|
||||
{
|
||||
struct gmio_string* token_str = &data->token_str;
|
||||
enum gmio_eat_word_error eat_error;
|
||||
|
||||
token_str->len = 0;
|
||||
eat_error = gmio_stringstream_eat_word(&data->strstream, token_str);
|
||||
const enum gmio_eat_word_error eat_error =
|
||||
gmio_stringstream_eat_word(&data->strstream, token_str);
|
||||
if (eat_error == GMIO_EAT_WORD_ERROR_OK) {
|
||||
const char* expected_token_str = stla_token_to_string(expected_token);
|
||||
if (gmio_ascii_stricmp(token_str->ptr, expected_token_str) == 0) {
|
||||
@ -443,12 +441,11 @@ int gmio_stla_eat_next_token_inplace(
|
||||
enum gmio_stla_token expected_token)
|
||||
{
|
||||
struct gmio_stringstream* sstream = &data->strstream;
|
||||
const char* stream_char = NULL;
|
||||
const char* expected_token_str = stla_token_to_string(expected_token);
|
||||
bool error = false;
|
||||
|
||||
data->token = unknown_token;
|
||||
stream_char = gmio_stringstream_skip_ascii_spaces(sstream);
|
||||
const char* stream_char = gmio_stringstream_skip_ascii_spaces(sstream);
|
||||
while (!error) {
|
||||
if (stream_char == NULL || gmio_ascii_isspace(*stream_char)) {
|
||||
if (*expected_token_str == 0) {
|
||||
@ -472,11 +469,9 @@ int gmio_stla_eat_next_token_inplace(
|
||||
{
|
||||
size_t i = 0;
|
||||
/* -- Copy the matching part of the expected token */
|
||||
{
|
||||
const char* it = stla_token_to_string(expected_token);
|
||||
while (it != expected_token_str)
|
||||
data->token_str.ptr[i++] = *(it++);
|
||||
}
|
||||
const char* it = stla_token_to_string(expected_token);
|
||||
while (it != expected_token_str)
|
||||
data->token_str.ptr[i++] = *(it++);
|
||||
/* -- Copy the non matching part */
|
||||
while (i < data->token_str.capacity
|
||||
&& stream_char != NULL
|
||||
@ -508,15 +503,13 @@ int gmio_stla_eat_until_token(
|
||||
|
||||
do {
|
||||
const size_t previous_buff_len = strbuff->len;
|
||||
enum gmio_eat_word_error eat_word_err = 0;
|
||||
const char* next_word = NULL; /* Pointer on next word string */
|
||||
size_t next_word_len = 0; /* Length of next word string */
|
||||
|
||||
gmio_stringstream_copy_ascii_spaces(sstream, strbuff);
|
||||
/* Next word */
|
||||
next_word = strbuff->ptr + strbuff->len;
|
||||
eat_word_err = gmio_stringstream_eat_word(sstream, strbuff);
|
||||
next_word_len = (strbuff->ptr + strbuff->len) - next_word;
|
||||
const char* next_word = strbuff->ptr + strbuff->len;
|
||||
const enum gmio_eat_word_error eat_word_err =
|
||||
gmio_stringstream_eat_word(sstream, strbuff);
|
||||
const size_t next_word_len =
|
||||
(strbuff->ptr + strbuff->len) - next_word;
|
||||
/* Qualify token */
|
||||
data->token =
|
||||
eat_word_err == GMIO_EAT_WORD_ERROR_OK ?
|
||||
|
Loading…
Reference in New Issue
Block a user