From 154c582631c2fe81fe9ab49b10c2a2af1509af11 Mon Sep 17 00:00:00 2001 From: Dennis Ameling Date: Sun, 24 Oct 2021 16:44:40 +0200 Subject: [PATCH] CMakeLists.txt: enable building Git using LLVM/Clang on Windows While Clang is available on Windows, it uses the Visual Studio linker by default: "For Windows projects, Visual Studio by default invokes Clang in clang-cl mode. It links with the Microsoft implementation of the Standard Library." https://docs.microsoft.com/en-us/cpp/build/clang-support-msbuild?view=msvc-160 Since we want to build with the Clang/llvm-mingw toolchain, we have to get rid of some assumptions in the CMakeLists.txt file, as it's basically a GNU compiler and linker. Signed-off-by: Dennis Ameling --- contrib/buildsystems/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 77b7fad2935abe..29d2e5458c4d72 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -280,7 +280,8 @@ endif() #Platform Specific if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + # MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang) + if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (NOT CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang")) include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include) add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE) endif() @@ -719,7 +720,8 @@ endif() if(WIN32) target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res) add_dependencies(common-main git-rc) - if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + # MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang) + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR (CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang")) target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup) elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)