[PATCH] D97451: [PR48898][CMake] Support MinGW Toolchain tools in llvm_ExternalProject_Add
Markus Böck via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 25 00:36:42 PST 2021
zero9178 created this revision.
zero9178 added reviewers: mstorsjo, phosek, hubert.reinterpretcast.
Herald added a subscriber: mgorny.
zero9178 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Windows is in the unique position of having two drivers, clang-cl and normal GNU clang, depending on whether a GNU or MSVC target is used. The current implementation with the USE_TOOLCHAIN argument assumes that when CMAKE_SYSTEM_NAME is set to Windows that clang-cl should be used, which is the incorrect choice when targeting a GNU environment.
This patch solves the following:
- If the host is MinGW and USE_TOOLCHAIN is passed as an argument, the GNU style drivers should be selected instead of clang-cl
- If one of CMAKE_(C|ASM|CXX)_COMPILER_TARGET has been passed as cmake arguments it checks whether a windows-gnu or windows-msvc target has been requested and selects accordingly
I discovered these issues when trying to do builds of the runtimes using LLVM_ENABLE_RUNTIMES while having a MinGW target as one of the LLVM_RUNTIME_TARGETS.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97451
Files:
llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Index: llvm/cmake/modules/LLVMExternalProjectUtils.cmake
===================================================================
--- llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -46,9 +46,19 @@
${ARGN})
canonicalize_tool_name(${name} nameCanon)
+ if (MINGW)
+ set(use_mingw_toolchain_tools ON)
+ endif()
+
foreach(arg ${ARG_CMAKE_ARGS})
if(arg MATCHES "^-DCMAKE_SYSTEM_NAME=")
string(REGEX REPLACE "^-DCMAKE_SYSTEM_NAME=(.*)$" "\\1" _cmake_system_name "${arg}")
+ elseif (arg MATCHES "^-DCMAKE_(C|ASM|CXX)_COMPILER_TARGET=(.*)-windows-(gnu|msvc).*$")
+ if (${CMAKE_MATCH_3} STREQUAL "msvc")
+ set(use_mingw_toolchain_tools OFF)
+ else()
+ set(use_mingw_toolchain_tools ON)
+ endif ()
endif()
endforeach()
@@ -61,7 +71,7 @@
if(NOT ARG_TOOLCHAIN_TOOLS)
set(ARG_TOOLCHAIN_TOOLS clang)
# AIX 64-bit XCOFF and big AR format is not yet supported in some of these tools.
- if(NOT _cmake_system_name STREQUAL AIX)
+ if(NOT _cmake_system_name STREQUAL AIX OR use_mingw_toolchain_tools)
list(APPEND ARG_TOOLCHAIN_TOOLS lld llvm-ar llvm-ranlib llvm-nm llvm-objdump)
if(_cmake_system_name STREQUAL Darwin)
list(APPEND ARG_TOOLCHAIN_TOOLS llvm-libtool-darwin llvm-lipo)
@@ -138,7 +148,7 @@
if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING)
if(CLANG_IN_TOOLCHAIN)
- if(_cmake_system_name STREQUAL Windows)
+ if(_cmake_system_name STREQUAL Windows AND NOT use_mingw_toolchain_tools)
set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
@@ -149,14 +159,14 @@
endif()
endif()
if(lld IN_LIST TOOLCHAIN_TOOLS)
- if(_cmake_system_name STREQUAL Windows)
+ if(_cmake_system_name STREQUAL Windows AND NOT use_mingw_toolchain_tools)
list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX})
elseif(NOT _cmake_system_name STREQUAL Darwin)
list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld${CMAKE_EXECUTABLE_SUFFIX})
endif()
endif()
if(llvm-ar IN_LIST TOOLCHAIN_TOOLS)
- if(_cmake_system_name STREQUAL Windows)
+ if(_cmake_system_name STREQUAL Windows AND NOT use_mingw_toolchain_tools)
list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lib${CMAKE_EXECUTABLE_SUFFIX})
else()
list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar${CMAKE_EXECUTABLE_SUFFIX})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97451.326305.patch
Type: text/x-patch
Size: 2832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210225/875c06ae/attachment.bin>
More information about the llvm-commits
mailing list