fix compile bug under clang(backend MSVC)

This commit is contained in:
VisualGMQ 2024-01-29 20:48:21 +08:00
parent 6868fb9e25
commit 7be64d0df7
3 changed files with 18 additions and 8 deletions

View file

@ -21,6 +21,17 @@ endif()
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode") message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
message(STATUS "Building with ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} on ${CMAKE_SYSTEM}") message(STATUS "Building with ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} on ${CMAKE_SYSTEM}")
function(IsMSVC var)
if (MSVC OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_SIMULATE_ID STREQUAL "MSVC"))
set(${var} 1 PARENT_SCOPE)
else()
set(${var} 0 PARENT_SCOPE)
endif()
endfunction()
set(is_msvc 0)
IsMSVC(is_msvc)
macro(xcheck_add_c_compiler_flag FLAG) macro(xcheck_add_c_compiler_flag FLAG)
string(REPLACE "-" "" FLAG_NO_HYPHEN ${FLAG}) string(REPLACE "-" "" FLAG_NO_HYPHEN ${FLAG})
check_c_compiler_flag(${FLAG} COMPILER_SUPPORTS_${FLAG_NO_HYPHEN}) check_c_compiler_flag(${FLAG} COMPILER_SUPPORTS_${FLAG_NO_HYPHEN})
@ -30,7 +41,7 @@ macro(xcheck_add_c_compiler_flag FLAG)
endmacro() endmacro()
xcheck_add_c_compiler_flag(-Wall) xcheck_add_c_compiler_flag(-Wall)
if(NOT MSVC) if(NOT is_msvc)
xcheck_add_c_compiler_flag(-Werror) xcheck_add_c_compiler_flag(-Werror)
xcheck_add_c_compiler_flag(-Wextra) xcheck_add_c_compiler_flag(-Wextra)
endif() endif()
@ -45,7 +56,7 @@ xcheck_add_c_compiler_flag(-Wno-format-truncation)
xcheck_add_c_compiler_flag(-funsigned-char) xcheck_add_c_compiler_flag(-funsigned-char)
# ClangCL is command line compatible with MSVC, so 'MSVC' is set. # ClangCL is command line compatible with MSVC, so 'MSVC' is set.
if(MSVC) if(${is_msvc})
xcheck_add_c_compiler_flag(-Wno-unsafe-buffer-usage) xcheck_add_c_compiler_flag(-Wno-unsafe-buffer-usage)
xcheck_add_c_compiler_flag(-Wno-sign-conversion) xcheck_add_c_compiler_flag(-Wno-sign-conversion)
xcheck_add_c_compiler_flag(-Wno-nonportable-system-include-path) xcheck_add_c_compiler_flag(-Wno-nonportable-system-include-path)
@ -54,7 +65,7 @@ if(MSVC)
xcheck_add_c_compiler_flag(-Wno-reserved-macro-identifier) xcheck_add_c_compiler_flag(-Wno-reserved-macro-identifier)
xcheck_add_c_compiler_flag(-Wno-reserved-identifier) xcheck_add_c_compiler_flag(-Wno-reserved-identifier)
xcheck_add_c_compiler_flag(-Wdeprecated-declarations) xcheck_add_c_compiler_flag(-Wdeprecated-declarations)
add_compile_definitions(WIN32_LEAN_AND_MEAN) add_compile_definitions(WIN32_LEAN_AND_MEAN _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
endif() endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug") if(CMAKE_BUILD_TYPE MATCHES "Debug")
@ -146,7 +157,7 @@ if(BUILD_QJS_LIBC)
endif() endif()
list(APPEND qjs_defines _GNU_SOURCE) list(APPEND qjs_defines _GNU_SOURCE)
list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS}) list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS})
if(NOT MSVC) if(NOT is_msvc)
list(APPEND qjs_libs m pthread) list(APPEND qjs_libs m pthread)
endif() endif()

View file

@ -612,6 +612,7 @@ void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
} }
#if defined(_MSC_VER) #if defined(_MSC_VER)
struct timezone;
// From: https://stackoverflow.com/a/26085827 // From: https://stackoverflow.com/a/26085827
static int gettimeofday_msvc(struct timeval *tp, struct timezone *tzp) static int gettimeofday_msvc(struct timeval *tp, struct timezone *tzp)
{ {

View file

@ -211,8 +211,6 @@ typedef enum {
JS_GC_PHASE_REMOVE_CYCLES, JS_GC_PHASE_REMOVE_CYCLES,
} JSGCPhaseEnum; } JSGCPhaseEnum;
typedef enum OPCodeEnum OPCodeEnum;
struct JSRuntime { struct JSRuntime {
JSMallocFunctions mf; JSMallocFunctions mf;
JSMallocState malloc_state; JSMallocState malloc_state;
@ -977,7 +975,7 @@ typedef enum OPCodeFormat {
#undef FMT #undef FMT
} OPCodeFormat; } OPCodeFormat;
enum OPCodeEnum { typedef enum OPCodeEnum {
#define FMT(f) #define FMT(f)
#define DEF(id, size, n_pop, n_push, f) OP_ ## id, #define DEF(id, size, n_pop, n_push, f) OP_ ## id,
#define def(id, size, n_pop, n_push, f) #define def(id, size, n_pop, n_push, f)
@ -997,7 +995,7 @@ enum OPCodeEnum {
#undef DEF #undef DEF
#undef FMT #undef FMT
OP_TEMP_END, OP_TEMP_END,
}; } OPCodeEnum;
static int JS_InitAtoms(JSRuntime *rt); static int JS_InitAtoms(JSRuntime *rt);
static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len, static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,