[PATCH] D80425: Fix LLVM/Clang builds with mingw toolchain

Tobias Hieta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 02:25:42 PDT 2020


thieta created this revision.
Herald added subscribers: llvm-commits, cfe-commits, mstorsjo, dexonsmith, mgorny.
Herald added projects: clang, LLVM.

These are a collection of small fixes to make LLVM/Clang build with a clang+mingw toolchain to target Windows.

The three commits address the following problems:

- When using LTO we pass --lto-cache-directory to lld - but this option is not supported by the lld MingW driver so it fails with unknown argument.
- Don't symlink the tools - a MingW build version of clang should be assumed to be used on Windows - which doesn't support symlinks correctly - so instead use the copy path of the code for MingW as well.
- The logic for linking libclang with libdl was a bit flawed - use the similar logic as to other places in the CMake build system.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80425

Files:
  clang/tools/libclang/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: clang/tools/libclang/CMakeLists.txt
===================================================================
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -66,9 +66,8 @@
   endif ()
 endif ()
 
-find_library(DL_LIBRARY_PATH dl)
-if (DL_LIBRARY_PATH)
-  list(APPEND LIBS dl)
+if (HAVE_LIBDL)
+  list(APPEND LIBS ${CMAKE_DL_LIBS})
 endif()
 
 option(LIBCLANG_BUILD_STATIC
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -953,6 +953,8 @@
   # time a little since we re-link a lot of the same objects, and significantly
   # improves incremental build time.
   # FIXME: We should move all this logic into the clang driver.
+  #
+  # FIXME; mingw lld driver doesn't support any of the options below
   if(APPLE)
     append("-Wl,-cache_path_lto,${PROJECT_BINARY_DIR}/lto.cache"
            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
@@ -962,7 +964,7 @@
   elseif(LLVM_USE_LINKER STREQUAL "gold")
     append("-Wl,--plugin-opt,cache-dir=${PROJECT_BINARY_DIR}/lto.cache"
            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
-  elseif(LINKER_IS_LLD_LINK)
+  elseif(LINKER_IS_LLD_LINK AND NOT MINGW)
     append("/lldltocache:${PROJECT_BINARY_DIR}/lto.cache"
            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
   endif()
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1868,7 +1868,7 @@
   if(NOT ARG_OUTPUT_DIR)
     # If you're not overriding the OUTPUT_DIR, we can make the link relative in
     # the same directory.
-    if(CMAKE_HOST_UNIX)
+    if(CMAKE_HOST_UNIX AND NOT MINGW)
       set(dest_binary "$<TARGET_FILE_NAME:${target}>")
     endif()
     if(CMAKE_CONFIGURATION_TYPES)
@@ -1894,7 +1894,7 @@
     endif()
   endif()
 
-  if(CMAKE_HOST_UNIX)
+  if(CMAKE_HOST_UNIX AND NOT MINGW)
     set(LLVM_LINK_OR_COPY create_symlink)
   else()
     set(LLVM_LINK_OR_COPY copy)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80425.265681.patch
Type: text/x-patch
Size: 2145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200522/e108c31e/attachment-0001.bin>


More information about the cfe-commits mailing list