From 9404962c322e38b7f5e6e0f7b8726121643e3abd Mon Sep 17 00:00:00 2001 From: huzhiqiang <912790387@qq.com> Date: Thu, 24 Sep 2020 10:10:45 +0800 Subject: [PATCH] [windows] Fix compiling error on windows (#4415) --- cmake/external/flatbuffers.cmake | 9 +------- lite/backends/x86/cpu_info.cc | 1 + lite/utils/charconv.h | 36 +++++++++++++++++--------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/cmake/external/flatbuffers.cmake b/cmake/external/flatbuffers.cmake index 4c2413c620..47b3042234 100644 --- a/cmake/external/flatbuffers.cmake +++ b/cmake/external/flatbuffers.cmake @@ -27,7 +27,7 @@ SET(FLATBUFFERS_SOURCES_DIR ${CMAKE_SOURCE_DIR}/third-party/flatbuffers) SET(FLATBUFFERS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/flatbuffers) SET(FLATBUFFERS_INCLUDE_DIR "${FLATBUFFERS_SOURCES_DIR}/include" CACHE PATH "flatbuffers include directory." FORCE) IF(WIN32) - set(FLATBUFFERS_LIBRARIES "${FLATBUFFERS_INSTALL_DIR}/${LIBDIR}/libflatbuffers.lib" CACHE FILEPATH "FLATBUFFERS_LIBRARIES" FORCE) + set(FLATBUFFERS_LIBRARIES "${FLATBUFFERS_INSTALL_DIR}/${LIBDIR}/flatbuffers.lib" CACHE FILEPATH "FLATBUFFERS_LIBRARIES" FORCE) ELSE(WIN32) set(FLATBUFFERS_LIBRARIES "${FLATBUFFERS_INSTALL_DIR}/${LIBDIR}/libflatbuffers.a" CACHE FILEPATH "FLATBUFFERS_LIBRARIES" FORCE) ENDIF(WIN32) @@ -64,13 +64,6 @@ ExternalProject_Add( -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} ) -IF(WIN32) - IF(NOT EXISTS "${FLATBUFFERS_INSTALL_DIR}/${LIBDIR}/libflatbuffers.lib") - add_custom_command(TARGET extern_flatbuffers POST_BUILD - COMMAND cmake -E copy ${FLATBUFFERS_INSTALL_DIR}/${LIBDIR}/flatbuffers_static.lib ${FLATBUFFERS_INSTALL_DIR}/${LIBDIR}/libflatbuffers.lib - ) - ENDIF() -ENDIF(WIN32) ADD_LIBRARY(flatbuffers STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET flatbuffers PROPERTY IMPORTED_LOCATION ${FLATBUFFERS_LIBRARIES}) ADD_DEPENDENCIES(flatbuffers extern_flatbuffers) diff --git a/lite/backends/x86/cpu_info.cc b/lite/backends/x86/cpu_info.cc index 276b62654f..3ba8dc5078 100644 --- a/lite/backends/x86/cpu_info.cc +++ b/lite/backends/x86/cpu_info.cc @@ -24,6 +24,7 @@ #include #elif defined(_WIN32) #define NOMINMAX // msvc max/min macro conflict with std::min/max +#define GLOG_NO_ABBREVIATED_SEVERITIES #include #else #include diff --git a/lite/utils/charconv.h b/lite/utils/charconv.h index ee458e549c..e04526d1e3 100644 --- a/lite/utils/charconv.h +++ b/lite/utils/charconv.h @@ -144,9 +144,9 @@ from_chars_result aton_unsigned(const char* str, // basic type. if (UNLIKELY(i > std::numeric_limits::digits10 + 1) && i == std::numeric_limits::digits10) { - uint64_t mx = static_cast(std::numeric_limits::max()); + uint64_t mx = static_cast((std::numeric_limits::max)()); if (val > mx / 10 || mx - (val * base) < cv) { - value = static_cast(std::numeric_limits::max()); + value = static_cast((std::numeric_limits::max)()); result.ec = std::errc::result_out_of_range; return result; } @@ -156,10 +156,11 @@ from_chars_result aton_unsigned(const char* str, } val += cv; } - if (UNLIKELY(i > std::numeric_limits::digits10 + 1 || - (i > std::numeric_limits::digits10 && - val > static_cast(std::numeric_limits::max())))) { - value = static_cast(std::numeric_limits::max()); + if (UNLIKELY( + i > std::numeric_limits::digits10 + 1 || + (i > std::numeric_limits::digits10 && + val > static_cast((std::numeric_limits::max)())))) { + value = static_cast((std::numeric_limits::max)()); result.ec = std::errc::result_out_of_range; return result; } @@ -209,10 +210,11 @@ from_chars_result aton_signed(const char* str, val += cv; } if (LIKELY(!negative)) { - if (UNLIKELY(i > std::numeric_limits::digits10 + 1 || - (i > std::numeric_limits::digits10 && - val > static_cast(std::numeric_limits::max())))) { - value = static_cast(std::numeric_limits::max()); + if (UNLIKELY( + i > std::numeric_limits::digits10 + 1 || + (i > std::numeric_limits::digits10 && + val > static_cast((std::numeric_limits::max)())))) { + value = static_cast((std::numeric_limits::max)()); result.ec = std::errc::result_out_of_range; return result; } @@ -224,8 +226,8 @@ from_chars_result aton_signed(const char* str, ret *= -1; } if (i > std::numeric_limits::digits10 + 1 || - ret < static_cast(std::numeric_limits::min())) { - value = static_cast(std::numeric_limits::min()); + ret < static_cast((std::numeric_limits::min)())) { + value = static_cast((std::numeric_limits::min)()); result.ec = std::errc::result_out_of_range; return result; } @@ -260,7 +262,7 @@ from_chars_result aton_float(const char* str, int len, T& value) { // NOLINT ++str; --len; } - ssize_t dot_pos = -1; + int16_t dot_pos = -1; int i = 0; for (; i < len; ++i) { char c = str[i]; @@ -297,8 +299,8 @@ from_chars_result aton_float(const char* str, int len, T& value) { // NOLINT val += static_cast(rval) / rdiv; } - if (!negative && val > static_cast(std::numeric_limits::max())) { - value = static_cast(std::numeric_limits::max()); + if (!negative && val > static_cast((std::numeric_limits::max)())) { + value = static_cast((std::numeric_limits::max)()); result.ec = std::errc::result_out_of_range; return result; } @@ -307,8 +309,8 @@ from_chars_result aton_float(const char* str, int len, T& value) { // NOLINT return result; } val *= -1; - if (val < static_cast(-std::numeric_limits::max())) { - value = static_cast(std::numeric_limits::min()); + if (val < static_cast(-(std::numeric_limits::max)())) { + value = static_cast((std::numeric_limits::min)()); result.ec = std::errc::result_out_of_range; return result; } -- GitLab