From ca360a2f2dc030f097601f96fbf762f0a75088bc Mon Sep 17 00:00:00 2001 From: Yuyi Wang Date: Thu, 14 Oct 2021 16:21:40 +0800 Subject: [PATCH] cmake: Use correct link option for gcc ld in MinGW. While MSVC needs to specify entry as `wWinMainCRTStartup`, MinGW needs `-municode`. MinGW used to not support `wWinMain`, but recently it finally adds support for that. The support for clang is more complicated. This code was tested on MinGW clang, provided by MSYS2 clang64, and it worked successfully. Further investigation may be needed. Signed-off-by: Yuyi Wang --- contrib/buildsystems/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 97885cd1f1..cc68687c90 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -726,7 +726,13 @@ if(WIN32) endif() add_executable(headless-git ${CMAKE_SOURCE_DIR}/compat/win32/headless.c) - target_link_options(headless-git PUBLIC /NOLOGO /ENTRY:wWinMainCRTStartup /SUBSYSTEM:WINDOWS) + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_link_options(headless-git PUBLIC -municode -Wl,-subsystem,windows) + elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") + target_link_options(headless-git PUBLIC /NOLOGO /ENTRY:wWinMainCRTStartup /SUBSYSTEM:WINDOWS) + else() + message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}") + endif() elseif(UNIX) target_link_libraries(common-main pthread rt) endif()