Skip to content

Commit ea85e40

Browse files
committed
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 <dennis@dennisameling.com>
1 parent 1cfb52e commit ea85e40

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ endif()
280280

281281
#Platform Specific
282282
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
283-
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
283+
# MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang)
284+
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (NOT CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
284285
include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include)
285286
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
286287
endif()
@@ -719,7 +720,8 @@ endif()
719720
if(WIN32)
720721
target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
721722
add_dependencies(common-main git-rc)
722-
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
723+
# MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang)
724+
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR (CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
723725
target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup)
724726
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
725727
target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)

0 commit comments

Comments
 (0)