Skip to content

Commit

Permalink
CMakeLists.txt: enable building Git using LLVM/Clang on Windows
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dennisameling committed Oct 25, 2021
1 parent 47c9c7a commit 154c582
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 154c582

Please sign in to comment.