From 854ee420b97c1294ea6b5d284dcc1b4da56a7b80 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 23 Oct 2021 14:41:45 +0800 Subject: [PATCH] Fix MinGW build --- CMakeLists.txt | 6 +++++- src/hl.h | 6 ++++-- src/jit.c | 6 +++++- src/main.c | 6 ++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01c00142e..b5084d2a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,10 @@ if(MSVC) add_definitions(-DUNICODE -D_UNICODE) endif() +if (MINGW) + add_compile_options(-municode) +endif() + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/other/cmake ) @@ -117,7 +121,7 @@ set_target_properties(libhl PUBLIC_HEADER "${public_headers}" ) -if(WIN32) +if(WIN32 AND MSVC) set_target_properties(libhl PROPERTIES OUTPUT_NAME libhl diff --git a/src/hl.h b/src/hl.h index ee271ac23..939167723 100644 --- a/src/hl.h +++ b/src/hl.h @@ -163,6 +163,8 @@ # define IS_64 1 # ifdef HL_VCC # define _PTR_FMT L"%IX" +# elif defined(HL_MINGW) +# define _PTR_FMT L"%lX" # else # define _PTR_FMT u"%lX" # endif @@ -207,11 +209,11 @@ typedef unsigned long long uint64; // -------------- UNICODE ----------------------------------- -#if defined(HL_WIN) && !defined(HL_LLVM) +#if defined(HL_WIN) && !(defined(HL_LLVM)) #if defined(HL_WIN_DESKTOP) && !defined(HL_MINGW) # include #elif defined(HL_WIN_DESKTOP) && defined(HL_MINGW) -# include +# include #else # include #endif diff --git a/src/jit.c b/src/jit.c index 3f5179976..bee474654 100644 --- a/src/jit.c +++ b/src/jit.c @@ -3935,7 +3935,11 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) { size = begin_native_call(ctx, 1); set_native_arg(ctx,trap); - call_native(ctx,setjmp,size); +#ifdef HL_MINGW + call_native(ctx, _setjmp, size); +#else + call_native(ctx, setjmp, size); +#endif op64(ctx,TEST,PEAX,PEAX); XJump_small(JZero,jenter); op64(ctx,ADD,PESP,pconst(&p,trap_size)); diff --git a/src/main.c b/src/main.c index 0c5379f90..22c875562 100644 --- a/src/main.c +++ b/src/main.c @@ -134,7 +134,13 @@ static void setup_handler() { #endif #ifdef HL_WIN +#ifdef HL_WIN_DESKTOP +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) { + int argc = 0; + LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); +#else int wmain(int argc, pchar *argv[]) { +#endif #else int main(int argc, pchar *argv[]) { #endif